Event Tracking Google Tag Manager

Asked

Viewed 127 times

2

I created the event in Google tag manager, and I need to bring the value that is in the ID clicked. But in Analytics it shows as 'Undefined', someone has some hint?

$('a#HomeB02').on('click', function() {

  var Id_ = $(this).attr('id');

  dataLayer.push({
      'event': 'HomeB',
      'gaEventCategory': 'Home',
      'gaEventAction': 'Banner',
      'gaEventLabel': Id_

  });
});
  • 1

    Have you tried putting console.log(Id_) to see if there appears undefined also? Also, you can write simply this.id in place of $(this).attr('id'). What console.log(this) prints? I would guess that the context of your Handler is not what you expect it to be.

  • Tested and does not work either, I believe it works only by setting directly on gaEventLabel. Thanks for the help.

  • Thanks for the help @ctgPi managed to resolve.

1 answer

1

The default tag manager does not recognize Jquery selector, a practical solution is to put the default snippet code as custom HTML and put the code below as custom and do not forget to have Jquery code on the page.

$('a#HomeB02').on('click', function() {

      var Id_ = $(this).attr('id');

      ga.push('send','event','Home','Banner', ''+Id_+'');

    });

A second solution is to use Javascript’s Event Listener or the tag manager itself.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.