History change trigger

Tag Manager

Video tutorial: watch on YouTube

A history change trigger fires a tag when the hash in the page URL changes or when the history object in the browser changes. It’s mostly used for tracking single-page applications (SPAs) where a regular tracking code fails to capture page reloads.

By default, the trigger fires a tag with every history change. However, you can change its conditions so that the tag fires for a specific page or specific conditions.

History change trigger in Piwik PRO

Note: In this trigger we use the option: Wait 1 second before firing the tag. It helps to match page URLs with page titles in single-page applications.

  • When turned on: The tag will fire if the visitor stays on the page for at least one second. This option also affects how events are reported. Events that occur before the one-second delay will be attributed to the previous page. If multiple history changes occur during the delay, only the last one will be recorded as a page view, and the previous changes will be ignored.
  • When turned off: The tag will fire each time a hash or history object changes. All events will fire the tag.

We recommend that you turn it on because then your data will be more accurate.

Here’s a list of conditions available in this trigger.

Event conditions

Condition type Description Example
Page URL Fires the tag when a history object or hash changes for the selected page URL. For example, a visitor is on the page https://clearbank.com/product-tour and a history object or hash changes. Page Url equals https://clearbank.com/product-tour/
Page path Fires the tag when a history object or hash changes for the page with the selected page path. For example, a visitor is on the page that contains the path /product-tour and a history object or hash changes. Page Path contains /product-tour
Page hostname Fires the tag when a history object or hash changes for the page hosted on the selected domain. For example, a visitor is on the page that is hosted on clearbank.com and a history object or hash changes. Page Hostname equals clearbank.com
History source

Fires the tag when a visitor is on a page where a specific history event (pushState, replaceState, popState or hashchange) occurs.

For more on the history object, see this article.

History source equals pushState
History fragment Fires the tag when a visitor is on a page where the hash in the page URL matches the selected condition.

History fragment equals pricing

Example URL: https://example.com/#pricing

Old history fragment

Fires the tag when a visitor is on a page where the previous hash in the page URL matches the selected condition.

For more on the hashchange event, see this article.

Old history fragment equals about-us

Example previous URL: https://example.com/#about-us

History state

Fires the tag when a visitor is on a page where the history state in the page URL matches the selected condition.

For more on the history.state property, see this article.

History state is set

or

History state equals my-state

Old history state

Fires the tag when a visitor is on a page where the previous history state in the page URL matches the selected condition.

For more on the history.state property, see this article.

Old history state is set

or

Old history state equals my-state

Referrer Fires the tag when a history object or hash changes for the page a visitor was directed to by the selected referrer. This referrer is internal, meaning that it belongs to the same domain as your site. For example, a visitor comes from https://clearbank.com/blog and a history object or hash changes. Referrer equals https://clearbank.com/blog
External referrer Fires the tag when a history object or hash changes for the page a visitor was directed to by the selected external referrer. This referrer is external, meaning that it has a different domain than your site. For example, a visitor comes from https://google.com and a history object or hash changes. External referrer equals https://google.com
Campaign Fires the tag when a history object or hash changes for the page a visitor was directed to by the selected campaign (based on the utm_campaign parameter). Campaign equals winter-promo
Traffic source

Fires the tag when a history object or hash changes for the page a visitor was directed to by the selected traffic source.

Possible values: campaign, organic search, social, referral, direct.

Traffic source equals direct
Returning visitor Fires the tag when a visitor is a returning visitor and a history object or hash changes. The returning visitor is recognized by Tag Manager, which uses the stg_returning_visitor cookie. Returning visitor is true
Variable-based conditions Any variable you add will appear in the list of conditions and you can use it to define trigger conditions. ––

Tip: Learn more about trigger conditions.

Was this article helpful?

Technical support

If you still have any questions, visit our community.
There’s always someone happy to help!

Back to help center