Search code examples
javascriptgoogle-analyticsprivacy

Tracking only the page, not the querystring


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


Solution

  • 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.