What is the best way to attach a GA event to a button click?

tester1234
Silver Contributor
Silver Contributor tester1234

I'd like to attach a event listener to a button that fires a Google Analytics event when it is clicked. I set it up, but I can't get it to send to GA. Any suggestions?

 

I created a tag with a load rule to target my specific page.

 

I then created a javascript extension that is scoped to that tag. In the extension I have

 

$(".social-widgets a" ).click(function() {
  console.log( "Handler for .click() called." );
  ga('send', 'event', 'details_share', 'details_share', 'details_share_email');
});

When it is clicked the console logs it, but it doesn't send it to GA. Do I need to put more info into the function to connect it to GA? I've verified that GA is on the page and working properly.

 

1 REPLY 1

What is the best way to attach a GA event to a button click?

Tealium Employee

Hi @tester1234,

 

You can accomplish this using a jQuery onHandler Extension in TiQ, then mapping the event category, action, label to the Google Analytics tag. Please see the screen shots and visit jQuery onHandler Extension for more info. Let me know if you have any more questions.

 

1.

jQuery onHandler Extension

 

2.

GUA tag mappings