Auto-Event Variable(like in GTM)

Hi,

Is there any way how I can set up an Auto-event Variable like in GTM that works the same way?

Thanks in advance!

Hi,

There is no possibility to set Auto-event Variable that way. In some cases workaround is possible, but it depends on particular use case.

We can try to find a solution if you describe your use case.

Maciej

Hi @Maciej_Kowcun ,

We have an Auto-Event Variable in GTM that we want to migrate into Piwiks Tag Manager. Basically, the Auto-Event Variable is grabbing one of our Element Attributes called “data-gtm”.

Auto-Event Variable GTM

The returned value in the Auto-Event Variable is then used and modified in two Custom Javascript Variables. These two Custom Javascript Variables are then used in Triggers and Tags.

If you have any workaround for this, I would be really thankful!

Hi,

Unfortunately there is now workaround right now. We are working on variables inside variables, which should make it possible. It will be ready in the next couple of weeks.

1 Like

Hi @Dataguy,

As a workaround you can create a Custom JS variable which returns the value of the data-gtm attribute.

function() {
return dataLayer.slice().reverse().find(x => x.event === "stg.click")?.element?.dataset?.gtm;
}

Please note that optional chaining (?.) used in the example above might not work on older browsers so if you have users that use these browsers I would recommend to compile that code with Babeljs.

Hi @kamilb ,

Thanks for reply! I will try it out :slight_smile:

Hello - what is the workaround for this :slight_smile:

Thanks so much!

Hi @Michael_Attea,

A few things have changed since the last answer.
Since we currently support variables inside of variables you can solve this by simply adding this code in a Custom JS variable -

function() {
  if({{ Click Element }}){
    return {{ Click Element }}.getAttribute('data-gtm');
  }  
}

This will return the value of the data-gtm attribute from a clicked element.

3 Likes

Great thanks! Excited

Warm Regards,

Michael James Attea

Michael James Attea

(716)863-2240

mjattea@hotmail.com

Follow me on LinkedIn!

www.linkedin.com/in/michaeljamesattea

Michael Attea | Digital Analytics Specialist
New Era Technology | Virtual, United States
Michael.Attea@NewEraTech.com | neweratech.com