javascript - How should I handle tracking fragment page views in Google Analytics? - Stack Overflow

I've been searching through the Google Analytics documentation, but I still don't understand

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/#!/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"]);?

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./#!/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"]);?

Share Improve this question edited Jun 14, 2013 at 4:13 Yahel 37.3k23 gold badges106 silver badges154 bronze badges asked Nov 2, 2011 at 14:58 kojirokojiro 77.3k19 gold badges150 silver badges212 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745187687a4615714.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信