APIs & Integrations

RJB
Member

Google Analytics event tracking on anchor CTA

Hi, I'm trying to add Google Analytics event tracking to a CTA, but every time I do, the code is partially removed after I have saved it...

 

Example in the screenshots below.

 
The code I have been adding:

 

screenshot 2.png
 
 
 
 
 
 
What it looks like after I have saved it and re-entered the “edit source code” editor:

 

screenshot 3.png
 
Does anyone have an idea what might be going wrong, and how I might be able to track clicks for this anchor link CTA?

Thanks!
0 Upvotes
1 Reply 1
WendyGoh
HubSpot Employee
HubSpot Employee

Google Analytics event tracking on anchor CTA

Hey @RJB,

 

I believe the reason why the onclick function was removed after you saved and re-entered the source code is because the source only support html and css. However, the onclick function is a javascript code as such it's not supported. 

 

To add javascript on your pages, these are some of the options: 

Add a JavaScript file to HubSpot

or

A couple of options outlined here by my colleague AJ - HubSpot Community - Adding a Javascript widget to my website

 

As for how you can modify the javascript, I'd love to share with you this community thread - Solved: HubSpot Community - CTA and Google analytics event tracking in which user lince shared a HubSpot CTA that triggers the GA track event. 

0 Upvotes