GA Event Tracking on Hubspot Form


Hi - would appreciate any guidance on this. We'd like to be able to add an event tracking script to the form button on this page: but there doesn't seem to be any way to customize the ahref for the destination link and I can't seem to identify the ID for the button.

We want to track clicks on the 'get a copy' button and are looking at something like this in the page footer:

$(document).ready(function() {
$('#id_of_cta').click(function() {
ga(‘send’, ‘event’, ‘PDF’, ‘Download’, ‘Digital Workplace WP’);

where id of cta is our missing value.Is this the best way to go about doing this and if so how can I define the 'get a copy' button?



Hi @jshs,

Could you instead add a GA tracking function to the onFormSubmit callback?


Thanks for the response - I'm not a developer by any stretch but I don't think that would work since the user is redirected to the resource as soon as they submit the form (URL changes). There wouldn't be any time for that to execute which is why I need to track the actual button click. Would appreciate any guidance you can offer.



Hi @jshs,

There should be enough time for the GA event to be sent, at least based on my testing. Since the form is submitted immediately after clicking the submit button, triggering the GA event on the click won't provide any extra time. If you're worried about the GA event having enough time to submit, I'd recommend triggering the event by some other criteria on the resulting page (either on page load, or perhaps some custom query parameter).


Thanks Derek, your response makes sense. Unfortunately the destination page is a PDF but I suppose the parameter could work - that wasn't something I considered. Thanks!


Derek I don't know why this didn't occur to me before but it's a .pdf so there's no GA script and URL parameter won't work on the page. I installed GTM in the hopes that I'd be able to track the link click but the form submit button isn't a hard-coded URL so I can't fire a link click trigger. Any insights on how to track hubspot form submits in GTM?


Hi @jshs,

I'm not 100% familiar with the workings of GTM, but if there is any script that needs to be fired to track a click, you can fire it from the onFormSubmit callback mentioned above. That callback fires right when the form is submitted, no matter what type of content is at the redirect URL.