Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I handle tracking fragment page views in Google Analytics?

I've been searching through the Google Analytics documentation, but I still don't understand how I should track page views for a single "page" site that uses ajax to reveal different views. I use shebang URLs and _escaped_fragment_ to help search engines understand the site layout, but our analytics guy told me to strip out the #! part of the URL when tracking, so when you visit mysite.com/#!/fish/bonker we would run:

_gaq.push(["_trackPageview", "/fish/bonker"]);

but that seems wrong to me. Wouldn't we want our tracked URLs to align with what Google actually spiders? Is there anything wrong with tracking _gaq.push(["_trackPageview", "#!/fish/bonker"]);?

like image 289
kojiro Avatar asked Nov 02 '11 14:11

kojiro


People also ask

How do I analyze page views in Google Analytics?

You can find the Pageviews report in Google Analytics by navigating to Audience > Overview report. If you want to find out which specific pages on your website have had the highest amount of traffic over a given period of time, then you'll want to use Top Content as opposed to All Pages or All Referrals.

Does Google Analytics track page views?

Users, sessions and pageviews are among the key metrics Google Analytics provides, and they're very easy to find in your Google Analytics dashboard. Simply go to the Audience - Overview report. At the top is a line graph tracking users over time. You can toggle to see sessions and pageviews, among other metrics.

Does Google Tag Manager track page views?

However, in SPA, all the subsequent “pageviews” happen dynamically without loading/reloading the page document. That's why by default, Tag Manager does not track “dynamic” pageviews. Because of this, you need to do some additional configuration (and maybe even with the help of a developer).


1 Answers

It's important to recognize that there is a wall between Google Analytics and Google Search. There's no reason you would be penalized by having your URLs in one not correspond to what the other sees.

escaped_fragment is purely a semi-standard for crawlers seeking to crawl AJAX content.

By default, Google Analytics does the equivalent when you don't pass a custom pageview value:

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

If you want to have it also track the anchor value, you can simply pass it on your own:

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

The benefit here is that the URLs will correspond with "real" URLs.

Long story short: You're perfectly fine doing your proposed method; I would prefer the latter (explicitly passing the actual location.hash, not a hacked version of it), but both work.

like image 144
Yahel Avatar answered Sep 24 '22 14:09

Yahel