Merge pull request #724 from google/add-analytics-components
Track clicks to the components page as pageviews.
This commit is contained in:
commit
d615fc3f6a
@ -130,10 +130,15 @@ MaterialComponentsNav.prototype.clickHandler = function(link) {
|
|||||||
|
|
||||||
// Add an history entry and display the hash fragment in the URL.
|
// Add an history entry and display the hash fragment in the URL.
|
||||||
var section = window.location.hash.split('/')[0];
|
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);
|
history.pushState(null, 'Material Design Lite', link);
|
||||||
// Scroll to top of page
|
// Scroll to top of page
|
||||||
document.getElementById('content').scrollTop = 0;
|
document.getElementById('content').scrollTop = 0;
|
||||||
|
// Track the specific component page view in Google analytics
|
||||||
|
if (ga) {
|
||||||
|
ga('send', 'pageview', '/components/' + linkWithoutHash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
10
docs/_templates/layout.html
vendored
10
docs/_templates/layout.html
vendored
@ -53,7 +53,15 @@
|
|||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
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');
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||||
ga('create', 'UA-25993200-9', 'auto');
|
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.
|
// Setup error tracking before anything else runs.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user