Trigger tag only once in lifetime

Hi.
I’m doing AB-testing and wish to have a tag fire only once in lifetime, instead of every time the user visits a page where the AB-test is active. Coming from Matomo tag manager there’s an option for this. But I can’t find it in PiwikPro.

/edit: Or as an alternative have it trigger max once per day/week

Thanks!

Hi. To achieve that you would have to use custom async tag and create a cookie or entry in the local storage when the tag is fired. Keep in mind that some of the browsers limit the max lifetime for those, so being able to fire it once in lifetime seems hard to achieve.

After the cookie is set, you could read it using the Cookie variable and then use as trigger condition.

Do you know of a instruction or manual on how to create a cookie in a custom tag?

Hi,

you can use JavaScipt inside a script tag in a custom HTML tag. Setting a cookie can be done using the document.cookie API, documented here: Document: cookie property - Web APIs | MDN

To create a cookie “foo” with a value of “bar” with 400 days of lifetime (which most browsers will restrict anyway), use code like the following and add a domain or change attributes if needed:

<script>
      var date = new Date(Date.now() + 400);
      document.cookie = "foo=bar; path=/; samesite=lax; expires=" + date.toUTCString();
</script>

best,
Markus