Merge pull request #724 from google/add-analytics-components
Track clicks to the components page as pageviews.master
commit
d615fc3f6a
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue