Facebook Event track when form is submitted

I’ve successfully set up the main Facebook Pixel for my site but now I’d also like to track when users submit a form on my website. I’ve got the standard FB event/lead tracking code (see below) and added is as an embedded element to the form when it’s in the Successful state. Unfortunately it seems that this gets triggered when the page gets loaded, not when the form is submitted. I know I can redirect to a new page and add the embedded code there, but I don’t want to redirect the user. How do I track form submissions using the code below without sending the user to a new page?

<script>
  fbq('track', 'Lead');
</script>

From what I can make out according to their documentation, you will need to attach this to the form submission event yourself.

So within the Webflow designer give your form an ID and then add some custom code like this:

document.getElementById('form').addEventListener('submit', function(){
    // Enter pixel function here to trigger it
})

Make sure to update the ID in the function. See if that helps.

Jason

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.