From 358deb9ea4210d659aee549e6cf1a39d61ad1064 Mon Sep 17 00:00:00 2001 From: Pavel Makhov Date: Sat, 20 Oct 2018 13:25:49 -0400 Subject: [PATCH] First attempt to make GA track URL fragments --- _includes/google-analytics.html | 26 +++++++++++++++++++------- assets/js/init.js | 7 ++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/_includes/google-analytics.html b/_includes/google-analytics.html index 517d572..de94a9c 100644 --- a/_includes/google-analytics.html +++ b/_includes/google-analytics.html @@ -1,9 +1,21 @@ - - ---> + + + + \ No newline at end of file diff --git a/assets/js/init.js b/assets/js/init.js index 189900a..43f99af 100644 --- a/assets/js/init.js +++ b/assets/js/init.js @@ -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); }); } +