Reputation: 887
I'm having an odd problem with datalayer events. I push an event object
{
'event': 'item',
'item_name' : 'generic user',
'item_value' : 'commenced'
}
into the datalayer and I can see it is correctly sent through to google. The parameters show up in the analytics.js get call in the network tab something like:
https://www.google-analytics.com/collect?...&ec=generic%20user%20%20shop&ea=checkout&el=commenced...
I'm assuming the insertion of the 'checkout' and the addition of 'shop' is defined in tag manager somehow and isn't relevant? I then push a different type of event object
{
'event': 'item',
'item_name' : 'generic user',
'item_description' : 'bermuda shorts',
'item_size' : 'medium'
}
and again it is sent correctly.
https://www.google-analytics.com/collect?...&ec=generic%20user%20%20shop&ea=medium&el=bermuda%20shorts...
When I then try to push another object of the original type
{
'event': 'item',
'item_name' : 'generic user',
'item_value' : 'next'
}
instead of sending the new object to google the previous object is resent.
https://www.google-analytics.com/collect?...&ec=generic%20user%20%20shop&ea=medium&el=bermuda%20shorts...
If I don't send the new type of object in between I can send through as many of the original object type as I want and they are sent correctly.
Using DataSlayer the correct events are shown being added. If I inspect the dataLayer object I can see the correct events in the array. Looking in GA at the real time events the events sent by the analytics.js show up as expected but the ones in the dataLayer that are not sent do not show up.
Does anyone have any idea what could be happening?
Upvotes: 3
Views: 6504
Reputation: 111
The problem is that you are not cleaning the dataLayer, and when you push the last dataLayer, it will overwrite the variables you are pushing, but the ones pushed before that arent pushed again, they are still available in the dataLayer.
You can check the state of the dataLayer at every dataLayer.push by using the preview of GTM troug the tab of DataLayer.
Example:
First push
{
'event': 'item',
'item_name' : 'generic user',
'item_value' : 'commenced'
}
DataLayer state:
{
'event': 'item',
'item_name' : 'generic user',
'item_value' : 'commenced'
}
Second push
{
'event': 'item',
'item_name' : 'generic user',
'item_description' : 'bermuda shorts',
'item_size' : 'medium'
}
DataLayer state:
{
'event': 'item', // overwrited
'item_name' : 'generic user', // overwrited
'item_description' : 'bermuda shorts', // added
'item_size' : 'medium', // added
'item_value' : 'commenced' //still available from first push
}
Third dataLayer push
{
'event': 'item',
'item_name' : 'generic user',
'item_value' : 'next'
}
DataLayer state:
{
'event': 'item', // overwrited
'item_name' : 'generic user', // overwrited
'item_description' : 'bermuda shorts', // available from previous push
'item_size' : 'medium', // available from previous push
'item_value' : 'next' //overwrited
}
In order to solve that, you should clean the dataLayer by pushing the variables that you don't want as undefined.
Example for the third push
{
'event': 'item',
'item_name' : 'generic user',
'item_description' : undefined,
'item_size' : undefined,
'item_value' : 'next'
}
Upvotes: 3