Hello,
It would be great if we could set a dataLayer trigger to fire only once per page.
Or maybe add this option on tag level, the same way GTM does for all types of tags:
Thank you!
Hello,
It would be great if we could set a dataLayer trigger to fire only once per page.
Or maybe add this option on tag level, the same way GTM does for all types of tags:
Thank you!
Hi Thomas,
I’ve created a feature request for that functionality.
Thank you for your input!
Best,
Oliwer
This was bugging me as well as we have a number of implementations that would require this function. What I did was a workaround with a custom HTML tag and a bit of JS. This is an example for a custom event tag, that needs to be limited to triggering once per page.
OPTIONAL:
if you have a complex tag (say lots of custom dimensions etc.) and don’t want to worry about the syntax, you can first create this tag with the standard Piwik PRO custom event.
You can then open the debugger, click the tag you created and copy the code
APPROACH:
After you have your event code ready you can create a custom html tag. First we create a variable which will contain the current page path. To achieve this we will use thie Page Path built-in variable.
var pageUrl = {{ Page Path }};
To make sure this tag only fires once, we need to implement a check. My approach was to set an extra variable eventTriggered, that checks whether the variable exists or if it exists, that it doesn’t match the current page path. The later is necessary to enable this tag to trigger in an SPA environment.
To make it compatible with multiple instances of this in different tags, I add the TAGID to it (you can copy it from the URL of the tag, just remove the dashes).
if (typeof eventTriggered_TAGID === "undefined" || eventTriggered_TAGID !== pageUrl )
After the check just enter your code “do something” and add the closing bracket.
The final touch is that you need to set the eventTriggered_TAGID variable and give it value of
the current page path so it will not trigger again on this page path url for this tag.
eventTriggered_TAGID = pageUrl;
Full example:
<script>
var pageUrl = {{ Page Path }};
if (typeof eventTriggered_TAGID === "undefined" || eventTriggered_TAGID !== pageUrl ) {
var _paq = _paq || [];
_paq.push(["setCustomDimensionValue", 7, {{ DLV - bonus_value }}]);
_paq.push(["setCustomDimensionValue", 6, {{ DLV - bonus_game }}]);
_paq.push(['trackEvent', 'bouns', {{ DLV - bonus_type }}, {{ DLV - bonus_reason }}, {{ DLV - bonus_value }}]);
}
eventTriggered_TAGID = pageUrl;
</script>
p.s. Don’t forget to wrap it in script tags