I am writing a Javascript function that will be a tag in Google Tag Manager.
It is loaded on a SPA which I have minimal control over.
Whenever a user clicks, I use the GTM functionality to push some data to the datalayer, e.g.:
var someEventIsTriggered = function(e) {
var target = $('input#watched');
// Trigger a generic "gtm.click" event on every click
dataLayer.push({
"event": "gtm.customEvent",
"gtm.customWatchedVariable": target.val()
});
};
Every time this is triggered, it will push a new event to the datalayer, and updated the value of gtm.customWatchedVariable. What I now want to check is if the current gtm.customWatchedVariable is different from the last gtm.customWatchedVariable, and then fire a Trigger in GTM when it changes.
How can I do this?