History change trigger on a portion of the URL?
Is it possible to have a history change trigger but only on one specific URL query change? I have multiple queries in the URL and I would like to only detect/trigger the change of one query as the URL updates.
Posted Aug 26, 2022, 1:13 PM UTC
18
I've never used the history change trigger, so I don't know if this is the best practise, but it looks like it certainly is possible. I can see Google Tag Manager pushes "gtm.newUrl" to the dataLayer on historyChange.
Sooo:
I saw it too, but let’s say the query appears in the URL after an interaction, and then I do another interaction that makes another query appear in my URL, my history will change again. My URL is still going to contain the first query, so that will trigger the tag even though I haven’t interacted with the first element that made the first query appear.
The reason why I use history change instead of clicks is because the URL contains the information I want, and it’s pushed only AFTER the click has been done on the page. So if I use on click, the information is not yet available in the URL.
Can you give us a more detailed example of how you would like it to work? It would be helpful to include some dummy parameters, to make it easier to understand
I click on something on the page, which adds parameter 1 to the URL. When I click something else, parameter 2 is added to the URL (alongside parameter 1). I could go on, and click anywhere else on the page, and add any number of parameters to the URL.
I want to track all changes of parameter 1 only, regardless of how the URL is evolving as I interact with the page. I could have X number of parameters, I only want to grab the value of parameter 1 when it’s updated.
There is an auto-event variable that you can use to extract a given query (parameter) of the URL.
Yes, but there is no trigger. I am already grabbing the value of the URL query on history change. What I’m looking for is a trigger that will fire a tag every time this value updates. It can’t be history change, because I have other queries that trigger a history change, therefore, my tag would fire again with the same value.
I’m sorry if it’s for unclear, that situation is a little complex to explain. 😅