Track clicks to the components page as pageviews.

Also track correctly a direct page load to a component.
This commit is contained in:
Nicolas Garnier 2015-07-06 15:19:09 +02:00
parent 11ced2560b
commit cf87a03942
2 changed files with 15 additions and 2 deletions

View File

@ -130,10 +130,15 @@ MaterialComponentsNav.prototype.clickHandler = function(link) {
// Add an history entry and display the hash fragment in the URL.
var section = window.location.hash.split('/')[0];
if (section !== '#' + link.href.split('#')[1]) {
var linkWithoutHash = link.href.split('#')[1];
if (section !== '#' + linkWithoutHash) {
history.pushState(null, 'Material Design Lite', link);
// Scroll to top of page
document.getElementById('content').scrollTop = 0;
// Track the specific component page view in Google analytics
if (ga) {
ga('send', 'pageview', '/components/' + linkWithoutHash);
}
}
return true;
}.bind(this);

View File

@ -53,7 +53,15 @@
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-25993200-9', 'auto');
ga('send', 'pageview');
// If a specific component page is loaded directly we'll attribute the
// page view to the specific component's page
if (window.location.pathname.indexOf('/components/') !== -1 &&
window.location.hash.indexOf('-section') !== -1) {
ga('send', 'pageview', '/components/' +
window.location.hash.split('#')[1].split('/')[0]);
} else {
ga('send', 'pageview');
}
// }
// Setup error tracking before anything else runs.