Reputation: 488
I'm looking to track only the page the user visits, not the querystring (for privacy reasons).
Is this valid?
_gaq.push(['_trackPageview', document.location.pathname]);
So a page that's:
x.com/section/page/?test=123
will be logged as
/section/page
Cheers
Upvotes: 0
Views: 216
Reputation: 703
You can do it this way and NEVER pass the value to Google Analytics, or you can apply a filter in GA to exclude the part after the query string with a regular expression (I believe you even have the option in your Profile configuration now).
This might be more useful if you plan on using some query string parameters for other purposes - internal searches, user language, etc.
Upvotes: 1
Reputation: 37305
Yes, that will work perfectly fine. Passing that second argument will log a pageview using that value rather than the default value Google Analytics would be passing (location.pathname+location.search
), and the pageviews will appear without the query string.
Upvotes: 3