Skip to content

Commit

Permalink
Move analytics to separate include and use env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhorsford committed Nov 24, 2016
1 parent ef9bed0 commit 447122b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
9 changes: 9 additions & 0 deletions docs/views/includes/analytics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', '{{ analyticsId }}', 'auto');
ga('send', 'pageview');
</script>
15 changes: 2 additions & 13 deletions docs/views/includes/head.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
<link href="/public/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/public/stylesheets/docs.css" media="screen" rel="stylesheet" type="text/css" />

{% if promoMode == 'true' %}

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-26179049-11', 'auto');
ga('send', 'pageview');

</script>

{% if promoMode == 'true' and analyticsId %}
{% include "includes/analytics.html" %}
{% endif %}
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var password = process.env.PASSWORD
var env = process.env.NODE_ENV || 'development'
var useAuth = process.env.USE_AUTH || config.useAuth
var useHttps = process.env.USE_HTTPS || config.useHttps
var analyticsId = process.env.ANALYTICS_TRACKING_ID

env = env.toLowerCase()
useAuth = useAuth.toLowerCase()
Expand Down Expand Up @@ -103,6 +104,7 @@ app.use(function (req, res, next) {

// Add variables that are available in all views
app.use(function (req, res, next) {
res.locals.analyticsId = analyticsId
res.locals.serviceName = config.serviceName
res.locals.cookieText = config.cookieText
res.locals.releaseVersion = 'v' + releaseVersion
Expand Down

0 comments on commit 447122b

Please sign in to comment.