How do I add a GA goal (event) to the subscribe button on my blog?

Highlighted
Occasional Contributor

I would like to add tracking to the subscribe button on our blog so I can see a conversion count in our GA property. We have the global site tag already placed in the header HTML of the blog in settings. I have the goal set up in GA as an event with the parameters: 

 

  • Category: Subscribe
  • Action: submit
  • Label: Subscribe
  • Value: 300

Now how do I add that to the subscribe button for the blog? Do I need to use javascript or jQuery? I need to know what the code looks like and where it would go in the blog template builder (inline or wrapping html of the button element?).

 

Thanks!

Andy

Reply
0 Upvotes
4 Replies 4
Regular Contributor | Gold Partner

Hi @LocalJobNetwork ,

 

It's implemented via JavaScript. The simplest way is to add an onclick attribute to the links, like the default code below. Set the category, action, label and value to what you want to record in GA, like you named in your post. 

<a href="http://www.example.com" onClick="ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, value);">Link Text</a>


Best regards,

Kim

 

Did this post help solve your problem, help the community and mark it as solution.

Occasional Contributor

Thanks for the reply. 

 

I understand the code you provided will work, but I am unsure of where to put it in the blog template. 

 

Does that go in the "inline styling" or the "wrapping HTML" section, or somewhere else?

 

blog.jpg

 

Thanks!

Andy

Reply
0 Upvotes
Regular Contributor | Gold Partner

Hi @LocalJobNetwork , 

 

Sorry I misunderstood your question before, you want to track the email subscription button, right? If so, you should put the code (just like below) in the module code. 

ga('send', {
  hitType
: 'event',
  eventCategory
: 'category',
  eventAction
: 'action',
  eventLabel
: 'label'
});


You can follow these steps for further information on how to add custom JavaScript to the module. 

 

Best regards, 

Kim 

 

Did this post help solve your problem? Help the community and mark it as solution.

 

Occasional Contributor

Thanks, 

 

I followed those steps (using only/exactly the code you sent me with my category/action/label text) and saw that the Linked Javascript in the editor section was for the blog template itself, not the individual subscribe button element. Is that correct and will it only trigger when the subscribe button is clicked?

 

The subscribe button the right side of this page is what I need tracked: https://blog.localjobnetwork.com/

 

Thanks,

Andy

Reply
0 Upvotes