Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

added in anonmyized ip google analytics #111

Merged
merged 1 commit into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 11 additions & 3 deletions server/portal_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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) => {
Expand All @@ -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(() => {
Expand Down
3 changes: 3 additions & 0 deletions views/download.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<script src="/bundle.js"></script>
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css">
<link rel="stylesheet" type="text/css" href="/main.css" />
{{#if shouldRenderAnalytics}}
{{> analytics trackerId=trackerId}}
{{/if}}
</head>
<body>

Expand Down
3 changes: 3 additions & 0 deletions views/index.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<script src="/bundle.js"></script>
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css">
<link rel="stylesheet" type="text/css" href="/main.css" />
{{#if shouldRenderAnalytics}}
{{> analytics trackerId=trackerId}}
{{/if}}
</head>
<body>

Expand Down
10 changes: 10 additions & 0 deletions views/partials/analytics.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<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', '{{{trackerId}}}', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>