Tracking Google Analytics on a 1-Page Website Using Hashtags

I have a long one page website using hashtags in the url when you navigate to a specific section from a scroll or click. What technique can I use to track these hashtags as โ€œpagesโ€ in Google Analytics?

+4
source share
3 answers

(processing from previous answer ...)

In general, your code might look like this:

_gaq.push(['_trackPageview',location.pathname + location.search + location.hash]); 

You can associate this code with every hash change in your application or use the common hashchange plugin , which uses HTML5 onhashchange and some backward compatible hacks for older browsers and binds this code to this event, so it fires every time the hash changes.

Using this plugin, your code might look like this:

 $(window).hashchange( function(){ _gaq.push(['_trackPageview',location.pathname + location.search + location.hash]); }) 
+8
source

Yes, virtual pageviews is your solution, here is a tutorial: http://services.google.com/analytics/breeze/en/et_vps/index.html

+3
source

I believe you can use google analytics something like this

  onclick="javascript:_gaq.push(['_trackPageview','/PDF/EXAMPLE PDF NAME']);" 

your Google analytics will record a click in the folder structure that you specify

0
source

Source: https://habr.com/ru/post/1382726/


All Articles