0

I have this code triggering on clicking a tab.

window.ga('send', {
  hitType: 'event',
  eventCategory: 'PDP',
  eventAction: 'ChangeTab',
  eventLabel: 'lorem ipsum',
});

I have checked Analytics Real time and it shows up but the Event Label is always "(not set)"..

enter image description here Is it Google Tag Manager's Click Event that is messing up my event?

enter image description here If so how do I work around that? No Tag is fired on the Click.

EDIT: Is this the problem that this datalayer variable is defined in GTM? enter image description here

OZZIE
  • 6,609
  • 7
  • 55
  • 59
  • Although you should not have a trailing comma like `eventLabel: 'lorem ipsum',}`, your code worked fine for me and the event label came through. How is this code actually configured in GTM? As a Custom HTML tag? Is your code really `lorem ipsum`, or are you using your GTM variable like `eventLabel: '{{eventLabel}}',`? – Joshua T May 27 '19 at 16:46
  • @JoshuaT This code is for Google Analytics tracking directly not for GTM. I've added it to the sites source code. But I think something in our GTM is messing with it removing my data. the trailing comma is a part of eslint. Doesn't work in IE7 but we don't need to support that :D – OZZIE May 28 '19 at 06:12
  • @JoshuaT but great thank you for telling me that it works on a clean GTM! :-) This is what I suspected! – OZZIE May 28 '19 at 06:56
  • I have removed this label from GTM now but didn't help :( – OZZIE May 28 '19 at 08:15

1 Answers1

0

This was the solution: https://stackoverflow.com/a/51705995/846348

We're including Analytics via GTM and using "Custom Dimension"/"Trackers" whatever that means.

class AnalyticsHelper {
  static DEBUG = false; // requires https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna

  static analyticsSend(data = {}) {
    if (AnalyticsHelper.DEBUG) {
      window.ga_debug = { trace: true };
    }
    window.ga(() => {
      const trackers = window.ga.getAll();
      const firstTracker = trackers[0];
      const trackerName = firstTracker.a.data.values[':name'];
      window.ga(`${trackerName}.send`, data);
    });
  }
}
OZZIE
  • 6,609
  • 7
  • 55
  • 59