Dan
Dan

Reputation: 3358

Tracking Google Analytics on a 1 page website using hashtags

I have a long single page website using hashtags in the URL when you get to a certain section from scrolling or clicking. What technique can I use to track these hashtags as "pages" in google analytics?

Upvotes: 4

Views: 5576

Answers (3)

Nikolay
Nikolay

Reputation: 2214

Yeah, virtual pageviews is your solution, here's the tutorial: http://services.google.com/analytics/breeze/en/et_vps/index.html

Upvotes: 3

Yahel
Yahel

Reputation: 37305

(Recycling from a prior answer...)

Generically, your code could look like this:

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

You could either bind that code to every time you have a hash change within your application, or you could use a generic hashchange plugin, that uses the HTML5 onhashchange, and some backwards compatible hacks for older browsers, and bind this code to that event, so that it fires every time your hash changes.

Using that plugin, your code could look like:

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

})

Upvotes: 8

Ben
Ben

Reputation: 171

I believe you can use google analytics something like this

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

in your google analytics it will then record a click in the folder structure you specify

Upvotes: 0

Related Questions