Read more

Google Analytics: Change the tracked URL path

Henning Koch
April 30, 2012Software engineer at makandra GmbH

By default, Google Analytics tracks the current URL for every request. Sometimes you will want to track another URL instead, for example:

  • When an application URL contains a secret (e.g. an access token)
  • When you want to track multiple URLs under the same bucket
  • When you want to track interactions that don't have a corresponding URL + request (e.g. a Javascript button or a PDF download)
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Luckily the Analytics code snippet allows you to freely choose what path is being tracked. Simple change this:

ga('send', 'pageview');

... to this:

ga('send', 'pageview', { 'page': '/YOUR-CUSTOM-PATH' });

With Unpoly

With Unpoly you want to trigger an Analytics pageview whenever a major content fragment is replaced. See Unpoly instructions here.

Legacy snippet

Change this:

_gaq.push(['_trackPageview']);

... to this:

_gaq.push(['_trackPageview', '/YOUR-CUSTOM-PATH']);
Posted by Henning Koch to makandra dev (2012-04-30 10:15)