Tracking Facebook Leads with WordPress Contact Form 7

By December 16, 2015Facebook

The Contact Form 7 plugin for WordPress is a very popular WordPress plugin – I reckon I see it on 70% of websites. It’s an excellent free plugin for creating contact forms, however, I have one gripe with it:¬†by default, it does not redirect to a different thanks you page when a visitor submits a form.

By default, when a visitor to your website submits a contact form, they see a little message appear just below the contact form like this:

Contact form 7 success message

Sure, this might be a nice user experience – not loading another “thank you” page, but for us analytics and tracking guys, it’s a pain in the bum. Why? Because it makes it tricky to track leads – it’s much easier to setup conversion tracking when you send someone to a different URL after they’ve submitted a form.

Being the fanatical Facebook Ads person that you are, I’m pretty sure you want to be able to track conversions form lead generation forms like Contact Form 7. Then you can glance at your Facebook ads reports and see what it’s costing you per lead.

Here are two options for setting up lead tracking on websites using the Contact Form 7 plugin for WordPress.

Option 1: Redirect to a thank you page

Add the following piece of code to the Additional Setting field settings of your form:

on_sent_ok: "location.replace('http://www.YOURSITE.com/thank-you');"

It should then look like this:

Contact Form 7 Additional settings for redirect.

You will then need to setup a /thank-you page where the visitor will be redirected after submitting the form.

Then from within Facebook Ads Manager, you can go to your Pixels settings and Create Conversion and add the Thank You page URL into the form as follows:

Facebook Conversion Pixel - create conversion.

Using this method also means you can easily setup retargeting, not to mention Google Analytics Goal tracking, conversion tracking for Twitter and other ad platform tracking. This is your ideal setup as it makes it easy to track conversion in multiple platforms.

Lazy marketers, you might prefer option 2.

Option 2: Trigger a Facebook conversion on the form page

If you don’t want to go to the hassle of adding a new “Thanks You” landing page, then there is another option. And that is to trigger a specific Facebook conversion type, such as a lead.

Using the following code in the Additional Settings field, you can trigger a Lead Facebook conversion event.

on_sent_ok: “fbq(‘track’, ‘Lead’);”

So it should look like this in your form settings:

Triggering a Facebook Lead events in Contact Form 7

You could use this method to trigger any of the Facebook standard conversion events.

 

  • Mark – Shotkit

    great tip thanks Luke – is this still relevant with the latest Facebook pixel?

    • RunTheNightLtd

      yeah, i’d really like to know this aswell

  • It’s still relevant to have a unique landing page URL, but with the new Facebook Pixel you can use the same code across all your pages, you just need to setup the conversion URL in Facebook Ad Manager.

  • Agnieszka Rokita

    Can you customise that snippet in option 2?
    If I use different adverts to send people to the same page and the conversion I’m tracking is a registration could I have multiple codes to track who came from which advert?

    I use on_click method to tract events in GAnalytics so my feeling is that it’s possible. But I’m not great with JS so I actually don’t know.

  • Ylenia Vernucci

    Thank you very much Luke. Very useful. Just a question. If I use the second solution but on my website I have different contact form, how can I recognize which form has been filled from users coming from the same fb ads link? Thank you so much!

  • Art Veal

    THANKS!

  • Using method 2, doesn’t seem to be sending the tracking info to facebook. It sends the message, but blocks the “Message Sent” message from showing, which is really confusing for customers

  • Sergio Occhipinti

    The CF7 documentation says the “on_sent_ok” hook is not safe and it will be removed in the 2017.

  • Bunty

    Looks like this is outdated and obsolete. DO NOT usE