First attempt to make GA track URL fragments

This commit is contained in:
Pavel Makhov 2018-10-20 13:25:49 -04:00
parent d284b3d3b4
commit 358deb9ea4
2 changed files with 25 additions and 8 deletions

View File

@ -1,9 +1,21 @@
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-57641651-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
<!--&lt;!&ndash; Global site tag (gtag.js) - Google Analytics &ndash;&gt;-->
<!--<script async src="https://www.googletagmanager.com/gtag/js?id=UA-57641651-4"></script>-->
<!--<script>-->
<!--window.dataLayer = window.dataLayer || [];-->
<!--function gtag(){dataLayer.push(arguments);}-->
<!--gtag('js', new Date());-->
gtag('config', 'UA-57641651-4');
<!--gtag('config', 'UA-57641651-4');-->
<!--</script>-->
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-57641651-4', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

View File

@ -31,9 +31,13 @@ $(document).ready(function(){
$('.sidenav').sidenav();
$('.sidenav > li > a').click(function(event){
event.preventDefault();//stop browser to take action for clicked anchor
let replace = $(this).text().trim().replace(/\s+/g, '-');
console.log(replace);
ga('set', 'page', replace);
ga('send', 'pageview');
location.hash = event.target.hash;
//get displaying tab content jQuery selector
@ -73,3 +77,4 @@ if ('serviceWorker' in navigator) {
console.log("Error registering service worker" + e);
});
}