Triggering a Google Analytics event



We’re looking to trigger a google analytics event when someone submits a form, which is a HubSpot form embedded on our website.

The form is set up to display a thank you message, so we can’t trigger the event upon load of the thank you page, because there is no thank you page.

Wondering if anyone has any experience with this?



@Champion You could add the onFormSubmit function to the embed code which could then call your google analytics event.

Trigger Google Analytics Event with Form Submission

Thanks @pmanca .

I’m not a developer so struggling to get this to work… I have the code that needs to be linked, but not sure how to link it using the onFormSubmit string within the form embed.

Here is the embed form code:

hbspt.forms.create({ sfdcCampaignId: 'XXXXXXXXX', portalId: 'XXXXXXXXX', formId: 'XXXXXXXXX' }); Then the code that has been sent across to be added looks like: dataLayer.push({'event' : 'formSubmitted', 'formName' : 'consultation'}); function onFormSuccess(event) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event' : 'formSubmitted', 'formName' : 'consultation' }); } { form.onSubmit(function(){ dataLayer.push({ 'event': 'formSubmitted' 'formName': 'consultation' }); }); });


@Champion Read through the documentation I posted above. You need to have the link in your hbspt.forms.create function. so underneath formId you would add it.


@Champion did you manage to make this work? I’m very interested in your final code