Multiple data layer pushes not working

Hey all,
I’m working on an Angular page in which I’m trying to set variables via the data layer. I have already managed to do this for the UserId and a category in which our users are classified.

Now I would create another variable (berufswelt.jobtitle), but it is not set. However, my previous variables UserId (berufswelt.userid) and UserCategory (berufswelt.userCategory) are still filled correctly. Only I don’t understand why the new variable is not set unlike the others.

I use a TrackingService that initializes the data layer.

    window['_mtm'] = window['_mtm'] ?? [];
    return window['_mtm'];

Then it just pushes into the array the variables.

The previous variables (UserId and UserCategory) are set in the root component. The new variable should only be set on a subpage (i.e. not directly at the beginning).

I can see in the developer tools of the browser that the variable is pushed into the array, however it is not shown to me as set in the debug tool of Matomo…

image

I have checked the correct naming of the variables in Matomo and in the code several times, it is the same.

Can someone tell me why the new variable is not set ?

Hi jgabele

Sorry, it may be a bit late to post an answer on your question ;

May I rephrase it a little to be sure I understand the matter ?
According to what you wrote, I understand that ;

You mean :

  • you have a property berufswelt.jobtitle in a Datalayer - that is OK
  • In MTM Debug mode, you don’t see the value of this Datalayer property in the related MTM Variable - that is KO

right ?

Do you see your variable as ‘Empty’ ?
Or is your variable not here at all ?

Hey Laurent,
thanks a lot for your answer! In the debug mode I can see the variable. However, the code is set only once, each subsequent attempt does not overwrite the old value. The first value remains.

However, in the code of the web page I can see via debug output in the developer tools of the browser that the call is made to Matomo. After I can set the value once, I assume that the way I set the variable is correct.

What do I want to do? I am trying to populate the variable with page specific data, that is, set data from the current page and use it in Matomo.

Thanks a lot for your help!

Hi,

Sorry, I’m not sure to understand ;

When you check your Datalayer property berufswelt.jobtitle in the browser DevTools for the second page (as it’s ok for the first page),
do you see the expected value ? or does it remain the same as the first page ?

best rgds

Hi,
so the value is set correctly on the first page, the value is displayed correctly in the data layer debug window of Matomo. If I navigate to another page the variable should be set again. But this does not work. The value of the variable remains at the value of the first page. The variable is set only once, any further change does not work.
Best regards

Sorry, but when you say “If I navigate to another page the variable should be set again. But this does not work. The value of the variable remains at the value of the first page.” it’s not clear to me wether you’re talking about the Datalayer property value, or about the MTM Variable.

If the Datalayer property value doesn’t change, the issue is in the code that calls/builds the Datalayer.
(front coding issue). Then it wouldn’t be a MTM issue…

best rgds

1 Like