CMS Development

asingh
Member

How to add a GTM tag on click of the download button of the Hubspot Form

Hi. 

So, What I want to do is. 

I have a HTML page. Link-

https://www.centilytics.com/resources/ebooks/azure-vs-aws.html

Now, this page has a hubspot form. 

 

What I want is, to apply a tag via GTM which triggers only when somebody clicks on this Download E-Book button. I have read the articles (https://support.google.com/tagmanager/answer/7679219?hl=en&ref_topic=7679108)

that was provided by your support team, but I haven't found a solution to that. 

Because whenever I try this, and click on the Hubspot Button to check for its click classes, It just doesn't get a click action.  Over the iframe, if I am clicking on that iframe (where the hubspot form is) the whole iframe doesn't show any click. And if I click anywhere else on the page, it registers a click, I mean it shows in the DOM window. 

 

Please tell me how can I do this?

How do I add a tag on this page (via GTM) which gets triggered only when somebody clicks on the Download button of the Hubspot form I'm using. 

Thanks

1 Reply 1
derekcavaliero
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

How to add a GTM tag on click of the download button of the Hubspot Form

@asingh 

 

For numerous security reasons, the browser will not let you setup a click event listener on a button that is inside a <iframe>. 

 

Furthermore, it's really bad practice to attach "conversion tracking" to a "click" action because clicks do not always mean the form was submitted successfully - for example when a user clicks the button and the form doesn't submit due to validation errors with the form fields. 

 

A better option is to fire conversion code when the form is "submitted". That can be achieved using the onFormSubmit HubSpot global event listener found here: https://developers.hubspot.com/global-form-events

 

If your form is set to redirect the user to a thank you page, you might run into issues where the tag doesn't have enough time to fire before the page unloads - to be safe I would use inline form messages.

 

Admittedly - I haven't tried using these global event listeners with HubSpot forms that are rendered in <iframes> - I always use the raw unstyled forms for better control and to avoid any <iframe> nonsense that makes everything more difficult.

Derek Cavaliero
Director of Engineering

WebMechanix
www.webmechanix.com
0 Upvotes