views:

909

answers:

3

How can you modify the URL for the current page that gets passed to Google Analytics?

(I need to strip the extensions from certain pages because for different cases a page can be requested with or without it and GA sees this as two different pages.)

For example, if the page URL is http://mysite/cake/ilikecake.html, how can I pass to google analytics http://mysite/cake/ilikecake instead?

I can strip the extension fine, I just can't figure out how to pass the URL I want to Google Analytics. I've tried this, but the stats in the Google Analytics console don't show any page views:

pageTracker._trackPageview('cake/ilikecake');

Thanks, Mike

+4  A: 

Two possibilities come to mind:

  1. it can take a while, up to about 24 hours, for visits to be reflected in the Analytics statistics. How long ago did you make your change?

  2. try beginning the pathname with a "/", so

    pageTracker._trackPageview('/cake/ilikecake');
    

    and then wait a bit, as per the first item.

Athena
+4  A: 

You could edit the GA profile and add custom filters ...

Create a 'Search and Replace' custom filter, setting the filter field to 'Request URI' and using something like:

Search String: (.*ilikecake\.)html$

Replace String: $1
(was \1)

pelms
Or use (.*)\.html$ to strip the extension from all .html urls.
Liam
i would go with pageTracker._trackPageview ... it would keep things more organized then having filters. plus you have to add the to all your profiles.
solomongaby
+1  A: 

Usually you have the ga script code at the end of your file, while special _trackPageviews() calls are often used somewhere else.

Have you made sure you have your call to pageTracker._trackPageview() after you have defined the pagetracker?

Like this:

var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._trackPageview();

otherwise you just get a JavaScript error I suppose.

Nicolai