Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handle urls with hash # with google analytics

I'm developing a js single-page web application using a javascript client side mvc (angular.js in this case)

I added google analytic to the site, but from what I could see so far (at least in realtime) google doesn't take into account the part of the uri after the hash

that is I have a url like mydomain.com.ar/#/ideas/1 but for google analytics it looks just like mydomain.com.ar/

any idea?

like image 700
opensas Avatar asked Dec 04 '25 18:12

opensas


1 Answers

You need to parse the parameters after # and send the data by using _trackPageview in order to see them on your pages report.

and here is how to do it,

 var params = {},
     queryString = location.hash.substring(1), 
     regex = /([^&=]+)=([^&]*)/g, 
     m; 
 while (m = regex.exec(queryString)) { 
     params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
 }
 _gaq.push(['_trackPageview', queryString]);
like image 181
Ibrahim Ozturkcan Avatar answered Dec 07 '25 16:12

Ibrahim Ozturkcan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!