How add dataLayers when form has submited?



I need to add a dataLayers of Google Tag Manager to my website, but when I try to add a function with jQuery this not working only in hubspot form. When I try another form not hubspot is working.

Basically, what I need is: When form submitted is succes run the next dataLayer.

‘event’ : ‘evLeadId’, //Static data
’clienId’ : ‘123456.123456’, //Dynamic data
’leadId’ : ‘2017121513561223’, //Dynamic data
’formType’ : ‘Formulario principal’, //Dynamic data
’city’ : ‘Veracruz’, //Dynamic data
’career’ : ‘Ingeniero en Mecatronica’, //Dynamic data
’modal’ : ‘Ejecutiva’, //Dynamic data
’hourForm’ : ‘8|18|Entre Semana’, //Dynamic data
’userType’ : ‘Recurrente’ //Dynamic data

How can I this action?

Thank´s in advance for your help!


Hi @Carlos_Franco,

I’m not completely clear on your existing setup, but you can use the HubSpot form embed’s onFormSubmit callback to trigger scripts when a HubSpot form is submitted:


Hi @Derek_Gervais,

This working for me, thank you for the reference!