Question

My app consists of 2 pieces, 1 private management and 1 payment gateway, which are deployed to different urls:

https://manage-my-app.com
https://pay-my-app.com

They need to be able to live on 1 server, however, with the domains are managed in the same vhost file.

I want to configure Google Analytics to run separately on each of these urls, but to store as much of the configuration in Environment Variables as possible (conforming with 12Factor).

I want to avoid using App Environments (dev, staging, production) to determine when to load GA, and I want to try to use as few variables as possible.

I'm thinking of using:

# manage-my-app.com vhost config
SetEnv GA_CODE something

# pay-my-app.com vhost config
SetEnv GA_CODE somethingelse

Then in my code, using:

<?php if ($ga = getenv('GA_CODE')) : ?>
// do google analytics here
<?php endif; ?>

I think this covers all my bases:

  • The config is in the ENV
  • Each deployment has its own analytics code
  • Each deployment only has to maintain its own string
  • Deploys with no analytics (dev, staging, etc) don't include the javascript

BUT I am worried it's not extensible enough.

For example:
How should I modify my approach if I need special analytics code or config for the payment gateway to conform to our privacy policy?

I want to avoid 2 paths, but I cannot rely on the url if 2 paths is the only way:

<?php if ($ga = getenv('GA_CODE')) : ?>
    <?php if ($url == 'pay-my-app.com') : ?>
        <!-- do it one way -->
    <?php else : ?>
        <!-- do it some other way -->
    <?php endif; ?>
<?php endif; ?>

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top