Hedra
Hedra

Reputation: 89

Google Analytics and hash/anchor doesn't work

I hope you can help me.

I have a gallery in Javascript. Each picture has a specific hash.

www.example.com/gallery.html#title_1

My stats are on Google Analytics but hash doesn't exist even when I tried this in the respective code :

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

or this :

_gaq.push(['_setAllowAnchor', true]);

Any idea to solve this problem ?

Thanks for your answers.

Upvotes: 2

Views: 461

Answers (1)

Eduardo
Eduardo

Reputation: 22834

_setAllowAnchor is for a completely different use case.

The right way to do it is as you said:

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

But you need to execute this after the hash has changed. I think you are executing this when the page loads. When the hash changes the page doesn't reload so you need to run this function call explicitly again.

Upvotes: 1

Related Questions