Custom Event variable like in GTM

Hi all,

for my SPA setting I used the custom event variable in GTM.
Is there a possibility to have the same variable?

image

My code looks like this:

function(){
var vpu = “Fallbackrechner”;
if ( {{Custom Event}}.indexOf(“rlv”) == 0 ){
vpu = “Angebotsrechner Risikoleben”;
} else if ( {{Custom Event}}.indexOf(“pkw”) == 0 ){
vpu = “Angebotsrechner PKW”; etc.

I am reading the events name that is pushed and extract the technical name like
indexOf(“step1.load”)

For now the console says: Cannot read properties of undefined (reading ‘indexOf’)
My guess is that is because the Variable is not set

Regards Martin

Hi @Martin,

Please try using {{ Event }} instead of {{Custom Event}}.
{{ Event }} is a built in variable which returns the value of the event key in the dataLayer.

Have a great day! :slight_smile:

Hi @kamilb

that worked. But I still get a console error Cannot read properties of undefined (reading ‘indexOf’).
any ideas?
it seems on the initial load that the variable is undefined. The error accures just once and the rest is as it should be

Okay … Im getting an empty event where everything is undefined. Thats interessting

Hi @Martin,

Just to make sure, this code is in a tag or a variable? -
function(){
var vpu = “Fallbackrechner”;
if ( {{Custom Event}}.indexOf(“rlv”) == 0 ){
vpu = “Angebotsrechner Risikoleben”;
} else if ( {{Custom Event}}.indexOf(“pkw”) == 0 ){
vpu = “Angebotsrechner PKW”;

If it is inside of a tag, what is the trigger?

Can you show me what you see in the dataLayer?

Seems like i fixed it.

The code is in a variable . I changed Custom Event to Event.

I think the initial DataLayer pushes empty variables. Now that I know this case I set {{Event}} to be “default” if its not defined.

The initial empty push is just “[ ]” . Maybe some old stuff from the current Google setting.

Everything runs fine now, thanks for the help.