Merge pull request #724 from google/add-analytics-components

Track clicks to the components page as pageviews.
master
Nicolas Garnier 2015-07-06 16:22:17 +02:00
commit d615fc3f6a
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.