App Deployment - deploy different index files

Reading time ~1 minute

Description

We want to deploy an Ember app that uses google analytics tracking script.

  • Enable it for production deployments
  • Disable it during development

End Goal

Step by step

  • Create a production deployment folder
mkdir -p .deployment/production 
  • Add the custom index file that contains Google analytics script
<!-- .deployment/production/index.html -->
<script type="text/javascript">
  window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
  ga('create', 'UA-XXXXX-Y', 'auto');
  ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
  • Make sure Google analytics tracks all pages
// .deployment/production/router.js
Router.reopen({
  notifyGoogleAnalytics: function() {
    return ga('send', 'pageview', {
        'page': this.get('url'),
        'title': this.get('url')
      });
  }.on('didTransition')
});
  • Add deployment commands in travis configuration file
    • copy index file
    • add google analytics code to the Router
before_deploy:
  - cp -rf .deployment/production/index.html app/
  # append content of ".deployment/production/router.js" to "app/router.js"
  - cat app/router.js > app/router.tmp.js
  - cat app/router.tmp.js .deployment/production/router.js > app/router.js

Now if you deploy your app using travis, it will have google analytics enabled, but when you run it locally, you won’t have to worry about messing up your analytics data!

GitHub resources:

App Deployment - Serve Emberjs app on s3

Deploy Emberjs app on s3 and allow access to all routes using the hash Continue reading

Travis-ci - Send notification with custom message

Published on September 29, 2016

Travis-ci - deployment triggers

Published on September 27, 2016