GA (or other javascript apps) configured and called in a 12Factor-y way

萝らか妹 提交于 2019-12-11 10:05:10

问题


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; ?>

来源:https://stackoverflow.com/questions/21247024/ga-or-other-javascript-apps-configured-and-called-in-a-12factor-y-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!