Search code examples
javascriptgoogle-analyticsgoogle-tag-manageruniversal-analytics

Google Analytics event labels undefined when using GTM and custom events


I'm migrating from UA to UA inside of GTM, and working on re-creating the custom events that I need using the dataLayer.

I've got GTM installed, UA linked, and a trigger linked to a UA Event tag.

I can see the tag working when I visit Google Analytics -> Real Time -> Events, however the event category, action and label, are all coming through as either undefined, or not set.

Racking my brain here, so any assistance would be gratefully received.

My current code is below:

window.dataLayer.push({
    'event'         : 'Search',
    'eventLabel'    : 'Foo',
    'eventValue'    : 'Bar'
});

Solution

  • This was resolved by not realising that the objects you pass into the array have to be added to GTM as a dataLayer variable.

    i.e from my code above, eventLabel, eventValue, would be made as GTM data layer variables.

    Then, you have to map these created variables to the event tag that you have made.

    Combine that with a trigger and you're good to go!