Only send Google Analytics data if analytics was loaded successfully

Prevent errors in local environment and if people are using blockers.
This commit is contained in:
Adam Wathan 2017-11-17 08:22:06 -05:00
parent 60e1a9d8b3
commit 3bc4631924

View file

@ -52,8 +52,10 @@ $.when($.ready).then(function() {
}, '', href)
// Track on Google Analytics
ga('set', 'page', href)
ga('send', 'pageview')
if (typeof(ga) === 'function') {
ga('set', 'page', href)
ga('send', 'pageview')
}
})
})
@ -66,8 +68,10 @@ $.when($.ready).then(function() {
$('#content').html(e.state.content)
// Track on Google Analytics
ga('set', 'page', e.state.href)
ga('send', 'pageview')
if (typeof(ga) === 'function') {
ga('set', 'page', e.state.href)
ga('send', 'pageview')
}
}
}