Posted over 8 years ago. Visible to the public. Repeats.

Google Analytics: Change the tracked URL path

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)

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:


... to this:

_gaq.push(['_trackPageview', '/YOUR-CUSTOM-PATH']);

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Henning Koch
Last edit:
11 months ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more