views:

63

answers:

1

I am having some trouble with Google Analytics picking up deep linking as separate pages.

The site uses JQuery to handle tabs and deep linking. Take a look at this page as an example: http://www.albanyservices.com/compliance/#/ic_compliance/

The part of the URL after the '#' refers to the specific tab within the page. This is updated when a new tab is selected.

At the moment, google analytics doesn't treat each tab as a separate page within the site. As they all contain individual content and are linked to directly throughout the site, I need to find a way to have google analytics treat each '#' change as a separate page.

Any help would be hugely appreciated. Thanks in advance.

+1  A: 

First off, your idea of "deep linking" is not Google's. In all actuality, /compliance/ is a single page with the content of all of those tabs already loaded in, and the # is just an inline anchor, which displays some corresponding content and hides the rest. It's not a new pageview, but an event happening on the page. In most cases, tracking each jQuery tab as a new page would be incorrect, but I could see here why you would want to.

What you'll want to do is call the _trackPageview() function every time a tab is switched. You can do this by putting it in the tab's "change" callback (after where you're working on $.address.title right now, line 143 of that page's source).

The only problem here is that change gets called when the page loads too. So when the page loaded, you'd have your inital trackPageview (which we've deemed is not doing what you want), and then a second one for the tab.

So what I'd propose is, on pages where "tabs" are the more sensical page structure than physical pages, you remove this line:

_gaq.push(['_trackPageview']);

And instead, inside of the .change callback on the tab, calling this:

var _gaq = _gaq || [];
 _gaq.push(['_trackPageview', document.location.pathname + document.location.hash]);

Now one more problem with this. It will track a pageview to something like /compliance/#/additional_risk_management/

Again, Google doesn't really think # means a new page, so if for some reason that code doesn't work, you'll have to resolve to removing the # from any pages you track, like so:

var _gaq = _gaq || [];
gaq.push(['_trackPageview', document.location.pathname +     document.location.hash.replace("#/","")])
dmrnj