diff --git a/server/config.js b/server/config.js index 7e793f78..fd04dc57 100644 --- a/server/config.js +++ b/server/config.js @@ -22,6 +22,11 @@ const conf = convict({ arg: 'port', env: 'PORT' }, + analytics_id: { + format: String, + default: 'UA-101393094-1', + env: 'GOOGLE_ANALYTICS_ID' + }, env: { format: ['production', 'development', 'test'], default: 'development', diff --git a/server/portal_server.js b/server/portal_server.js index c6f74c68..5b129401 100644 --- a/server/portal_server.js +++ b/server/portal_server.js @@ -16,7 +16,10 @@ const log = mozlog('portal.server'); const app = express(); -app.engine('handlebars', exphbs({ defaultLayout: 'main' })); +app.engine('handlebars', exphbs({ + defaultLayout: 'main', + partialsDir: 'views/partials/' +})); app.set('view engine', 'handlebars'); app.use(helmet()); @@ -25,7 +28,10 @@ app.use(bodyParser.json()); app.use(express.static(path.join(__dirname, '../public'))); app.get('/', (req, res) => { - res.render('index'); + res.render('index', { + shouldRenderAnalytics: notLocalHost, + trackerId: conf.analytics_id + }); }); app.get('/exists/:id', (req, res) => { @@ -43,7 +49,9 @@ app.get('/download/:id', (req, res) => { .then(contentLength => { res.render('download', { filename: filename, - filesize: bytes(contentLength) + filesize: bytes(contentLength), + shouldRenderAnalytics: notLocalHost, + trackerId: conf.analytics_id }); }) .catch(() => { diff --git a/views/download.handlebars b/views/download.handlebars index da97535f..229184f6 100644 --- a/views/download.handlebars +++ b/views/download.handlebars @@ -6,6 +6,9 @@ + {{#if shouldRenderAnalytics}} + {{> analytics trackerId=trackerId}} + {{/if}}
diff --git a/views/index.handlebars b/views/index.handlebars index 9dd4a70f..d66cda60 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -6,6 +6,9 @@ + {{#if shouldRenderAnalytics}} + {{> analytics trackerId=trackerId}} + {{/if}} diff --git a/views/partials/analytics.handlebars b/views/partials/analytics.handlebars new file mode 100644 index 00000000..4f6aaff9 --- /dev/null +++ b/views/partials/analytics.handlebars @@ -0,0 +1,10 @@ + \ No newline at end of file