How do I use the History Change Trigger if my website has multiple History Change types?
When you’re using the History Change trigger for your Single Page Application Pageview tracking, you may notice that you have multiple Pageview tracking requests for each page that is viewed. This can happen when your Single Page Application uses multiple different History Change trigger types for different uses. To fix this we can add a condition to the History Change trigger to only fire for specific History Change types.
How do I get the trigger to only fire for specific History Change types?
- Click « Edit » for your existing History Change trigger.
- In the option « Only trigger when (optional) » use the condition « History Source equals » and enter the necessary History Source for your website:
Which History Source should I use for my Single Page Application?
The History Change Trigger in Matomo Tag Manager supports hashchange
, replaceState
and popState
. You can use any one of these as a filter.
When to use hashchange?
When your URL changes but the page does not reload (recommended for most of the case). For example when someone clicks the « Contact Us » link from the menu on the « Products » page and your SPA only changes the # of the URL:
Eg: Current URL: https://example.com#view-products
New URL: https://example.com#contact-us
When to use replaceState?
When you use history.replaceState
to change the current URL for SPA pages.
When to use popState?
This is used when you want to track the user’s navigation history, forward or backward. This event is fired when the active history entry changes while the user navigates the session history. It changes the current history entry to that of the last page the user visited.