Google Analytics for Tracking Hash URLs

It’s surprisingly simple to use Google Analytics for Tracking Hash URLs really. I needed to track each “page” as it was viewed, but being a hash url driven website of course google analytics (by default) only recognises the “index”, seeing as its essentially a “one page website”. No good to anyone…

So a simple one liner ( i have added this inside my function that loads the content, but it goes wherever you need to track)

[code]
_gaq.push([‘_trackPageview’, "/" + window.location.hash]);
[/code]

Looking at the Google Analytics screen we can now see each hash url logged as a visited page. Exactly what the client wants to see.

2 thoughts on “Google Analytics for Tracking Hash URLs”

  1. I am trying to accomplish this in the yoast wordpress plugin. I tried this but I do not think it is working correctly, any ideas?

    line:244 class-frontend.php

    else {
    $push[] = "'_trackPageview', + window.location.hash";
    }

Leave a Reply

Your email address will not be published. Required fields are marked *