Pushing multiple custom events confuses events's data

Hello!
In our website we have an upload documents page where the user can upload documents one by one or multiple documents at the same time.
What I would like to do is to send two custom events. The first event should be “First Document Uploaded” and the second event should be “All required documents uploaded”.
The problem starts by the time user decides to upload all the documents together, because I should send two events at the same time. Matomo confuses the event details.
Here is my code:

function mtm_event(args){
   var _mtm = window._mtm = window._mtm || [];
    _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});

   var _mtmData = {'event': 'UniSIS.'+args.action, 'mtm.category':args.category, 'mtm.action': args.action, 'mtm.name':args.name};
    _mtm.push(_mtmData);
    console.log(_mtm);
}

On the Data Layer tab of the Matomo debugger, on the “Content after this event” section, both events on Category, Name and Action have the data of the second event that is pushed. That means that the first event gets the event details of the second one.
As you can see in the code above, I have used a console.log to print the _mtm . On the console it looks perfect! I get the event details correct.

If I add a setTimeOut before pushing the second event, the problem does not occur.

Is this a bug of Matomo? Could you please advice me how to fix this?
Thank you in advance!

Hi @Maria_Kyprianou,

Which version of Matomo and MTM do you use?
Can you verbose MTM and share the whole console log?

Hello @heurteph-ei,

The Matomo version is 4.3.1 . Could you please guide me on how to find the MTM version?

This is my code:

function mtm_event(args){
   var _mtm = window._mtm = window._mtm || [];
    _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});

   var _mtmData = {'event': 'UniSIS.'+args.action, 'mtm.category':args.category, 'mtm.action': args.action, 'mtm.name':args.name};
    _mtm.push(_mtmData);
    console.log(_mtm);
}

    mtm_event({'category': 'Documents','action':'FDU', 'name':'First document uploaded'});
    mtm_event({'category': 'Documents','action':'ARDU', 'name':'All required documents uploaded'});

Below you can see the console.log of the second mtm_event call:

Array(5)

 0: {uid: "the id that I send"}
 1: {mtm.category: "Documents", mtm.action: "FDU", mtm.name: "First document uploaded", event: "UniSIS.FDU"}
 2: {mtm.category: "Documents", mtm.action: "ARDU", mtm.name: "All required documents uploaded", event: "consequentlyEvent.ARDU"}
 3: {mtm.startTime: 1622721971147, event: "mtm.Start"}
 4: {siteId: "14"}
 push: ƒ ()
 length: 5
 __proto__: Array(0)

As you can see, I get the two events details correctly.

  1: {mtm.category: "Documents", mtm.action: "FDU", mtm.name: "First document uploaded", event: "UniSIS.FDU"}
  2: {mtm.category: "Documents", mtm.action: "ARDU", mtm.name: "All required documents uploaded", event: "consequentlyEvent.ARDU"}

The two events retain their own details.

On the matomo debugger I get the following:

For the First document uploaded event:
Pushed data by this event

{ "event": "mtm.CustomEvent", "mtm.customEventMatch": "UniSIS.FDU" }

Content after this event

{ "mtm.containerId": "my container Id", "uid": "the id that I send", "mtm.category": "Documents", "mtm.action": "ARDU", "mtm.name": "All required documents uploaded", "event": "mtm.CustomEvent", "mtm.startTime": 1622721971147, "siteId": "14", "mtm.mtmScriptLoadedTime": 1622721971759, "unicaf_uuid": "the id that I send", "gtm.start": 1622721971146, "gtm.uniqueEventId": 11, "userInteraction": { "category": "sisStudentSideEvent", "label": "campaignAdID", "non-interaction-hit": false }, "importantMarketingVariables": { "utm_source": "SC_nA", "utm_medium": "MC_nA", "utm_term": "TC_nA", "utm_content": "CoC_nA", "utm_campaign": "CC_nA", "gcl_id": "GC_nA", "devicemodel": null, "adID": null, "placement": null, "loc_physical_ms": null, "target": null }, "gtm.scrollThreshold": 0, "gtm.scrollUnits": "percent", "gtm.scrollDirection": "vertical", "gtm.triggers": "13528378_54", "mtm.customEventMatch": "UniSIS.FDU" }

For the All required documents uploaded event:
Pushed data by this event

{ "event": "mtm.CustomEvent", "mtm.customEventMatch": "consequentlyEvent.ARDU" }

Content after this event

{ "mtm.containerId": "my container Id", "uid": "the id that I send", "mtm.category": "Documents", "mtm.action": "ARDU", "mtm.name": "All required documents uploaded", "event": "mtm.CustomEvent", "mtm.startTime": 1622721971147, "siteId": "14", "mtm.mtmScriptLoadedTime": 1622721971759, "unicaf_uuid": "the id that I send", "gtm.start": 1622721971146, "gtm.uniqueEventId": 11, "userInteraction": { "category": "sisStudentSideEvent", "label": "campaignAdID", "non-interaction-hit": false }, "importantMarketingVariables": { "utm_source": "SC_nA", "utm_medium": "MC_nA", "utm_term": "TC_nA", "utm_content": "CoC_nA", "utm_campaign": "CC_nA", "gcl_id": "GC_nA", "devicemodel": null, "adID": null, "placement": null, "loc_physical_ms": null, "target": null }, "gtm.scrollThreshold": 0, "gtm.scrollUnits": "percent", "gtm.scrollDirection": "vertical", "gtm.triggers": "13528378_54", "mtm.customEventMatch": "consequentlyEvent.ARDU" }

As you can see, on the First document uploaded event the “mtm.action” and “mtm.name” values are replaced by the “All required documents uploaded” event details.
Also, for some reason the object contais gtm values that I don’t push on the data layer.

Since Matomo Tag Manager is a core plugin of Matomo it is always updated together with Matomo and shares the same version.

1 Like

Hi,

I see severalt little things…

  1. When you want to track an event, you shouldn’t call mtm.startTime. This function should be called only at MTM init.
  2. I am not sure it is a good idea to use mtm.category, mtm.action and mtm.name as they belong to Matomo namespace.

The way I suggest to follow is:

  _mtm.push({'event': 'UniSIS.FDU'});
  _mtm.push({'event': 'UniSIS.ARDU'});

Then define 2 Custom Events in MTM triggers: UniSIS.FDU and UniSIS.ARDU
Then on your MTM configure 2 tags as below:
Tracking Type: Event
Event Category: Documents
Event Action: FDU
Event Name: First document uploaded
Execute this tag when: UniSIS.FDU is fired


Tracking Type: Event
Event Category: Documents
Event Action: ARDU
Event Name: All required documents uploaded
Execute this tag when: UniSIS.ARDU is fired

Indeed, the _mtm array is fully read each time an event is sent, so the last value set for a datalayer variable will be used as datalayer variable value…

Hi,
Thank you for your reply!
Regarding point 1: Yes, you are right, I accidentally added it. I have already removed it but the problem remains.
Regarding point 2: I have removed the “mtm” as you suggested but nothing changed.

I understand what you have suggested about the events and I have two questions:
1. What if I have a lot of events? In my case I have almost 10 custom events, the documents upload it was an example. I believe I should have something that it will be more dynamic.

2. What if I would like to send some dynamic values to the event? Let’s say that in the First document upload I would like to send a value which it will be dynamic. How can I achieve it by following the solution that you have proposed?

Thank you! :slight_smile:

Hi,

Just following this suggestion would not solve the problem. The solution was to use 2 events.

If the 10 events are note fired at the same time, you can do as you did in your first version (except for the little remarks I wrote 4 days ago :wink: ). But if they are fired at the same time, I don’t see an easy solution…

Something like:

  _mtm.push({'event': 'UniSIS.FDU', 'UniSIS.FDU.category': 'dynamid value 1', 'UniSIS.FDU.name': 'dynamid value 2'});

[+]
Tracking Type: Event
Event Category: {{UniSIS.FDU.category}}
Event Action: FDU
Event Name: {{UniSIS.FDU.name}}
Execute this tag when: UniSIS.FDU is fired

I hope it will solve your issue?

Hello @heurteph-ei,
Thank you for your message! Yes, this can solve my issue. I have already tried it and it works.
I was hoping that there was a way to do it without adding separate tags/variables for a specific event :slight_smile: