Formit Hook for Google Tracking

Hi,

Looking to trigger a Google javascript tag like this:

On a successful submission of a Formit form. Any suggestions on the best way of accomplishing this?

Thanks in advance.

Are you referring to a Google Analytics event trigger? :thinking: Do you have a Google Tag Manager account?

1 Like

Yes, exactly. I do have an account.

It depends on how you set up your form.

If you redirect to a “Thank you” page, then you could track this page.
If you display a success message, then you can give it a unique id/class and track that or maybe add a <script> tag that calls dataLayer.push({ ... });

[[!+fi.success:is=`1`:then=`<script> ... </script>`]]

Thanks, I am trying to trigger the script as a hook in the Formit snippet instead of placing it Thank You page since in therory that could lead to false positives if the Thank You page is reloaded or viewed directly.

I’m not sure if there is a way to trigger an event from PHP, so I don’t think you can use a FormIt hook.

Maybe you can use the FormItRetriever snippet on the “Thank You” page with the properties redirectToOnNotFound (and possibly eraseOnLoad) to make sure the page can’t be viewed directly.

//use &store=`1` for the form
[[!FormIt?
    &store=`1`
]]
//and FormItRetriever on the "Thank You" page
[[!FormItRetriever? &redirectToOnNotFound=`444` &eraseOnLoad=`1`]]

Interesting! Thanks halftrainedharry. I will give it a try.