Tracking Goals in CF7

Goal Tracking with Contact Form 7 in Universal/Classic Analytics

One of my favourite plugins for WordPress is Contact Form 7, a free and powerful plugin that allows developers to manage multiple contact forms on their WordPress site. However as the forms are processed within an AJAX application it’s not immediately obvious if and how you can track form submissions as goals in Google Analytics.

You can find the updated version of this article on Medium ‘Goal Tracking for Contact Form 7 in Google Analytics‘.

The great news is that you can and it’s very easy to setup. In this quick tutorial i’ll walk you through setting up a new goal and the code you’ll need for both ‘Classic’ and the shiny new ‘Universal’ Google Analytics.

Setting up the Goal in Google Analytics

So let’s start by setting up the goal in our Google Analytics account. Login to GA and head over to the Admin panel of your select domain profile. Select Goals from within the View (Profile) menu:


Next click on ‘Create a Goal’ to begin setting up the new goal that you’d like to track for Contact Form 7. In Step 1 click on ‘custom’ rather than ‘template’ from the initial set-up option. Now within Step 2 simply choose a name for your goal like ‘Contact Page’ and choose ‘Destination’ from the ‘Type’ options:


Finally in step 3 choose ‘Equals to’ for the destination and set a ‘fake’ URL that we can use to track the goal. I’ll explain later on why this Goal Destination is ‘fake’ but for now, simply pick a URL that doesn’t exist (and would therefore 404) that you can assign to the goal.


Complete the goal as necessary to finish the set-up of your new goal. Remember your ‘fake’ Destination URL as we’re going to ‘ping’ this imaginary path in the Contact Form 7 plugin next.

Pinging the GA Goal from Contact Form 7

As I mentioned earlier, CF7 forms work as AJAX applications – which means the data is submitted and processed within an AJAX event. When users successfully complete a CF7 form, they’re not taken to a new ‘thank you page’ URL by default, which can make tracking the event tricky.

However, both the Classic and the new Universal Google Analytics provide functions that allow you to trigger or ‘ping’ page-views whether you’re actually on that specific page or not. To take advantage of these functions, Contact Form 7 includes a really useful JavaScript Action Hook called ‘on_sent_ok’ that can trigger custom JavaScript events when the form has sent successfully. Depending on whether you’re using Classic (ga.js) or the new Universal (analytics.js) Google Analytics code, you’ll need either one of the following lines of code:

Universal Analytics Code

on_sent_ok: "ga('send', 'pageview', '/your/url');"

Classic Analytics Code

on_sent_ok: "_gaq.push(['_trackPageview', '/your/url']);"

Remember that Goal URL that we created earlier in Google Analytics? Swap /your/url in the code above for the path that you set up. If you now navigate to your individual Contact Form 7 form settings, scroll down to the bottom to to the ‘Additional Settings’ field:


Paste in the line of code like in the example above. Now, once our form is successfully completed, the on_sent_ok Action Hook will trigger our ga() or _gaq.push() functions that will ping our goal within Google Analytics.

That’s it!

  • caledonianmercury

    Hi James, I am using Google Tag Manager and have successfully set up a Goal (event rather than destination) for tracking Contact 7 form submissions, but having done so realised that I cannot set up funnels for events in Google Analytics.

    I was pleased to find your post as I am now looking to find how I could track Contact 7 form submission in the way you describe above i.e. using a destination page. Clearly using a destination page allows setting up of the funnel path and this is useful when you are looking to optimise pages for conversion. Unfortunately the approach you described above didn’t trigger/ping page view.

    • Sorry to hear that it didn’t work. For your Tag Type are you using the ‘Google Analytics’ or ‘Universal Analytics (beta)’ Tag type? In order for CF7’s Action Hook to ping GA, you need to make sure you’ve added the corresponding code from the two options above.

      • Stefan Jacobsen

        Hi James. I am using Universal analytics and Tag manager, but I cant figure out how to track my leads from Contact7 form. Could you please explain how to do this? What codeline should I paste at contact7 form and what tag-type and firing-rules should I add at GTM? Thank you!

        • Hi Stefen, are you just using the GTM at the moment to bring out your Analytics code? Could you DM me a link to your site that it’s installed on?

          • Stefan Jacobsen

            Hi. what is your email address?

          • Stefan Jacobsen

            Yes I am using GTM. Please see link attached.

          • Hi Stefan, I’ve tried inspecting your GTM code, but the URL of the iFrame seems to 404 which may suggest that it’s not installed correctly? Therefore I don’t think any tracking data is being captured? Are you receiving any data in analytics?

          • stefan

            Hi James. Yes I am receiving other data in Analytics. I debugged GTM and all rules were fired correctly at different pages.

    • Xavier

      traditional GA code doesn’t work if you use Google Tag Manager. You’d need to find out the tracker object firs.

      • Stefan Jacobsen

        Can you please explain this: “You’d need to find out the tracker object firs.”?

        • Hi Stefan, is this an error message you’re receiving whilst using the Tag Manager like Xavier?

  • Pepe

    Hi James! Does the results appear in Analytics in real time? I’m trying to do the goal tracking through a plugin extension for CF7, dinamically changing the fake URL depending on a variable. It doesn’t seem to work, but maybe I have to wait some hours, perhaps days to see it in Google Analytics admin page?

    Thank you very much!

    • Hi Pepe, if you set the reporting range to include the current day – you can start to see results coming through after a few hours. Best thing to do is to leave it 24 hours and review the day’s testing the following day.

  • Tessa

    Hi James,
    I’ve added the UA code above as per your instructions and the contact form 7 form has stopped displaying the ‘Your message was sent successfully’ message and doesn’t clear the contact form after hitting Send. I’ve removed the code and the successful completion message etc works fine. Any thoughts as to what in the UA code would be stopping these two things from working and how I could get both to work at the same time?

    • Hi Tessa, is the form posting and sending the message and pinging the goal? If you’re using Chrome or Firebug, are you able to open the console and try submitting the form to see if there are any JavaScript errors shown? Thank you Tessa.

      • Siobhan

        Hi James,

        I’m getting this same issue with the ‘Your message was sent successfully’ message no longer appearing after the set up of the tracking code (I also have no events showing up in Analytics yet but it’s been less than an hour since the test so may be too soon to tell).

        Using Chrome I’m getting the following error message in my console when a form is submitted. The error message appearing is “Uncaught ReferenceError: ga is not defined”. Do you know what might be causing this?


        • Hi Siobhan, it sounds like you might be using the wrong code snippet from above. Your error message suggests that you’re using Classic Analytics, rather than the new Universal Analytics tracking code. Try using the Classic code snipped from above (_gaq.push), and replace the one you have in place (_ga). That should hopefully remove the console error, bring back the ‘Your message was sent successfully’ message and also ping the goal in GA. Let me know if that works.

  • Added it… waiting to see if google records it now!

    • Catherine

      Hey Nick,

      Did this end up working for you and if so how long did it take to show that it recorded?

      • It did work and it took at least a day and a half to show up! I was on Classic GA! Very useful.

        • Mark McKay

          So to confirm, it takes a couple of days for the info to show up? I am using universal analytics. Also, can you tell me, why do we do use the phantom URL method instead of tracking this as an event? Thanks.

          • It can take about 12 hours yes before it shows up. As per my reply to your other comment, please make sure you use the ga() code snippet rather than _gaq.push() if you’re using the Universal tracking code.

  • James J

    Hi James. This works. Thanks a lot. It’s now tracking form submissions that come through organic searches which is great. Do i need to add anything else in order to track form submissions that come through and Adwords campaign? I would like to to be able to see which form submissions come from organic searches and which come from PPC. At the moment I just have the on_sent_ok: “_gaq.push([‘_trackPageview’, ‘my/url’]);” in the Additional Settings section of the CF7 panel. Would i need to add anything else here or would Analytics automatically detect which users had come through Adwords?


    • Hi James, unless you’re tracking any specific custom goals, then Google Analytics can automatically break this data up for you. Simply navigate to the Goal Overview then apply the Paid Search Segment.

      • James J

        Hi James. Thanks for your reply. We’re tracking ok but what we need to do is to display all our Analytics data on the submitted form that gets sent through so that the sales team can load the leads into their CRM. We are using a plugin by Found for this. Unfortunately we can’t seem to display the correct information when the lead comes from Adwords. So, we would like to see the Campaign name and campaign term which are correctly recorded in Analytics. It comes through saying the enquiry was from PPC but the rest of the info is missing. It seems that when you connect Adwords to Analytics the cookies get changed and a new parameter called ‘utmgclid’ appears – Google stores the AdWords campaign data (encrypted) here and it is only read by Analytics. There seem to have been numerous attempts to decode ‘utmgclid’, but nobody has succeeded?

        At the moment, there doesn’t seem to be a solution that would allow us to get the data sent on the form form and link it to Analytics as well. You can of course unlink AdWords form Analytics, but then there will be no advert statistics in the Analytics panel. Any ideas would be much appreciated. Is driving us mad. Thanks

  • Nombre


  • Hello James,
    I created a new destination goal as you described on GA Universal and I added on_sent_ok: “ga(‘send’, ‘pageview’, ‘/goals/subscription-page’);” on Contact7 additional settings.
    It’s 24h after this and no data are loaded on GA for Goal Completion ๐Ÿ™
    Any ideas?

    • @konstantinoschristodoulakis:disqus, please could you tweet me your URL offline and I can take a quick look to see if I can see anything @jamesbavington

      • Stephen Lessey

        Hi James, I am having the same problem. I followed these instructions and for some reason, i’m not getting any data. Can you help?

        • Hi Stephen, if you can tweet me your URL I can happily take a look for you and try and help.

  • Farhan Mahmood

    Hi James,
    Thank you for this great tutorial, it works.
    I have a question, I have two different CF7 forms on my homepage and I’m using their shortcodes in homepage template, although goal tracking works (I can see green successful submission alert) but all submissions are not registered, e.g,. I submitted forms 4 times (two times both forms), checked after 24 hours and goal conversion was 3, then I submitted 4 times again, after 24 hours conversion was 2.
    May be two different form (side by side) in same template is causing the problem? Your suggestion?


    • Farhan Mahmood

      Sorry for my bad english. The second time I submitted forms goal conversion was increased by 2, not that it was reduced to 2 from 3! ๐Ÿ˜›
      So when I submitted forms first time, goal conversion was 3, after second time, goal conversion is 5.


  • Does this line of code also need to be added to the Google Analytics code in the footer of the page? on_sent_ok: “_gaq.push([‘_trackPageview’, ‘/your/url’]);”

    • Hey Mark, no it only needs to be added into the additional settings in the plugin configuration. Just make sure though that if you’re using the new Universal analytics tracking code you use the ga() not _gaq.push() version of the code, otherwise it won’t track the conversions. Hope that helps.

      • Thanks James. My form is for people to RSVP to an event. Once the form is completed it sends an email to a generic email account. When I look at the analytics, it shows me that there were 60 goals completed, but I only received 8 emails confirming the RSVP. Any idea on why the discrepancy between completion and the actual number of emails received? Thanks.

        • Hi Mark – if you could email me or Tweet me your site’s URL etc, I can happily take a look for you to see if I can work out why.

  • Alek

    Hi James, great article, works as advertised. Is there a hook to track if the submit button was clicked but the email was not sent? Basically a way for me to track if there were any issues with the submit form.

    • Morning Alek, I don’t believe there’s a hook within CF7, however you could simply track clicks of the submit button itself as a custom event. My other tutorial here shows how to set-up specific event tracking on things like links and buttons, you just need to ensure the submit button has an ID or class you can identify:

  • Dave

    when I add this code the “thank you” messages disappears

    • Same problem here… Thank you message disappears…

    • This is usually indicative of a JavaScript error. First thing i’d check is that you’re using the right tracking code above (i.e Universal vs Classic) with the right supporting code. Happy to take a look if you’re able to post or DM me your URL.

      • sc456a

        Thanks, James. That was my issue. I had to switch my Analytics plugin to Universal.

        • Cool, thanks for letting me know, glad that’s working now.

  • Hi, the issue you’re experiencing is a result of a JavaScript error. At the moment, you’re page is set up with the Classic Analytics tracking code, but you’re using the Universal Analytics code snippet (_ga). Do you get the same problem when you do change the code to the _gaq.push() method from the post? If you could switch this over to me, I can take a look – or you could leave the code in as-is now, and change your GA plugin from Yoast to something like WP Headmaster (which allows the Universal Tracking Code) or by manually adding it to your header.php file.

    • Thanks for taking a look at this for me James, it’s much appreciated.

      I tried both the ga() and the _gaq.push() on the form and they both don’t show the ‘thank you’ pop up after the form has been submitted.

      Weirdly, my GA account has given me the UA code, but the Yoast plugin doesn’t support UA just yet. Is there any way I can override this (even temporarily)? If I was to remove the plug in and just manually slip the code into my theme’s header.php, would that work?

      I’ve changed the for back to gaq.push() now if you wouldn’t mind taking a look?

      • Hi Kane, I’ve just done a test message, and the form seemed to work OK for me? No JavaScript errors and I got the success message and the form fields cleared. Let me know if you received my test message, and hopefully that will look as a goal in a few hours?

        If you’re looking to add the UA code from Google (which is Universal Tracking Code), yes I’d recommend disabling Yoast’s plugin and manually adding the code into your header.php file, just before the closing tag.

        • Hi James,

          Thanks again. Yep, that’s what I did, I manually added the tracking code, just waiting to see whether it tracks the goals in GA now.

          Thanks so much for your help and support (and the post!), it’s hugely appreciated.

  • Hi, I’m not seeing Google Analytics installed on the page, is the above the right link?

  • Hi, James. Thanks for the great post!

    I’m not able to get Contact Form 7 3.8.1 to work with GTM & UA for event tracking. I’ve added the following to the additional settings this form:

    on_sent_ok: “ga(‘send’, ‘event’, ‘Form Tracking CF’, ‘Contact Us’);”

    on this page:

    No events are generated after successful form submission. This goes for two other forms, too. BTW, can I troubleshoot this using real-time event tracking in Analytics to your knowledge? I was thinking I should be able to.

    Any thoughts would be greatly appreciated!

    I am able to submit events using GTM tags. However the AJAX processing works, I’m not able to use GTM form validation so I have to count every click on submit buttons. Since this will over count actual successful submissions, I’d love to get event tracking CF7 working.


    • Hi Darren, I don’t use the GTM myself, so I’ve not experienced the potential incompatibility I’m afraid. Have you tried adding the UA tracking code inline temporarily to ensure the events track normally, to point point the issue?

  • JJ

    Hi James, excellent post, I have done similar but using events instead of virtual pageviews. The issue I’m having is that I can’t get the on_sent_ok hook to do two things at once. i.e. I want it to track an event/pageview, then redirect to a thank you page after form submission. Any ideas?

    • Hi JJ, what code are you adding into CF7? If you could paste into here, I can take a look to see if I can help.

  • Joanne G

    Hi there,

    I’m having trouble with this and feel like I’ve tried everything.

    As soon as I updated to universal analytics (added demographics code too), tracking in contact form 7 stopped working.

    I updated the code in additional settings – UA to on_sent_ok: “ga(‘send’, ‘pageview’, ‘/your/url’);”

    and even tried it as an event – on_sent_ok: “ga(‘send’, ‘event’, ‘contact’, ‘enquiry’, ‘ContactForm’);” …but no joy.

    Even tried to use the code that directs people to an actual thank you page but that won’t work either.

    If anyone has any ideas it would be much appreciated!


    • Hi Joanne, if you could tweet, email or direct message me your URL I can take a look for you to see if I can help.

      • Joanne G

        Thanks James! Just followed on Twitter, or if you could let me know your email ๐Ÿ™‚

  • Hi James,
    I’m also having trouble to make it work and I think this issue is still open ?

    • Hi Patrice, sorry to hear that. I’ve managed to work with most of the people who’ve commented, offline and resolved the issues they’d been having. What problems are you having with your integration?

      • I’m still having the same issue, Contact Form 7 don’t fire the event on my website. ๐Ÿ™
        I added the but form get sent properly, but no event pushed. URL sent via Hangout

  • Daniel

    Same issue as Patrice. The Universal Analytics Code is populated correctly (I think). The CF7 Additional Settings fied has been populated with the respective code as well (on_sent_ok: “ga(‘send’, ‘event’, ‘Enquiry’, ‘Submit’);”). But no joy. No events. Nothing in real time. Nothing in non-real time. Been trying all day, and nothing.

  • soma

    I’m so happy that this has been worked for me. I just used classic code in universal analytics.. thanks

  • Elliott Davidson

    I’m have a little difficulty with this as well and have been working on it all morning. I seem to be having the same issue as a lot of the people on here.

    I have everything pasted in the correct locations but google is still telling me that I haven’t received any conversions in the last 7 days when I know that I have.

    Any Idea on what my next step should be?


    • Hi Elliot, thanks for posting your feedback. I’ve helped a lot of the people on the comments get their’s working. It tends to be a few different things ranging from the wrong code to CF7 not displaying correctly. If you’re happy to tweet me your URL (@jamesbavington) or send it through our contact form – I can take a look at your integration.

  • Dinesh Rohila

    I am using a cf-7 on all pages of website. How can i track it?

  • Dinesh Rohila

    as well as I need for event not for destination url

  • Nigel Stratton

    Great stuff, thanks for this! I added it and saw a real time conversion immediately. Now I’m waiting for it to show up in the normal Analytics’ stats.

    One thought is you can turn on the goal’s funnel and make the Contact Page a required page. That would show how many opened the contact page but never completed it.

  • C Alexander

    When I used your code as-is, the form stopped displaying a successfully sent message. I added ‘submit’ to the end of the code {{ on_sent_ok: “ga(‘send’, ‘pageview’, ‘/fakesuccess’, ‘submit’);” }} and now the form displays the sent message. Still waiting to see if the analytics still works….any one else have this problem and tried a similar workaround?

    • Hi C Alexander, have you double checked that you’re using the right code, i.e. whether your tracking code is Classic or Universal?

      • C Alexander

        I am using Universal ๐Ÿ™‚

        • I can happily take a look for you, if you wanted to contact me offline?

  • Hello everyone, Thank you for all the assistance that you provide for people, I think its great that you do this.

    I have the same issue as C Alexander, I input the Universal code:

    on_sent_ok: “ga(‘send’, ‘pageview’, ‘/goals/contact-us’);”

    and it made the green confirmation message disappear.

    I then added the ‘Submit’ function that he mentioned worked for him:

    on_sent_ok: “ga(‘send’, ‘pageview’, ‘/goals/contact-us’,’submit’);”

    and still am not registering a goal conversion in my GA, nor am i getting a contact confirmation that was appearing before I pasted the code snippet.
    Does my script look incorrect? is there something else I can try?

    I am using universal Analytics BTWรขโ‚ฌโ€any tips would be greatly appreciated.


    • Hey Brian, if you could contact me offline, I can happily take a look at your integration for you.

  • Is it possible to call more than one “on_sent_ok” in one contact form using CF7?

    on_sent_ok: “_gaq.push([‘_trackPageview’, ‘/example_url’]);”
    on_sent_ok: ” track_load(‘/example_two’, ‘Second Track Code’);”

    I have multiple analytics’s software running for different purposes and want to trigger both.

    Thanks in advance.

  • Cannot get this working either on a couple of my sites ๐Ÿ™ – I don’t see why a major plugin like C7 can have so many problems.

  • Les Bischoff

    Just a note if you use an analytics plugin that disables tracking from logged in wordpress users like admin, the event wont fire because the analytics script probably wont be loaded. Test it on another machine or browser instance NOT logged into wordpress.

  • this code for destination url avail with contact form 7, but for Event Tracking this is useful or Not

  • hi, i also have the same problem as Brian Camarena and C Alexander – were you able to help them and what can i do to solve this? thanks

    • Hey Lindsay, in most cases it’s a JavaScript conflict. If you contact me offline via Twitter or direct message I’m happy to take a look for you.

  • Chris Buckley

    Same issue here. No confirmation message. James it’s seems a lot of people are having the same problem, so rather than contacting offline is it not easier to post any global solution here? It’s quite annoying when reading through the whole thread.

    • Hi Chris, im not sure what global solution I can offer as the tutorial I have outlined works assuming it is followed correctly and there are no existing JavaScript errors awaiting conflict. In every single instance that I have supported my tutorial there is either a JavaScript error in the console caused by another plugin or incorrectly coded theme, or the tutorial hasn’t been followed correctly. You may not want to hear this but please do contact me as I will do anything I can help solve the issue on your site.

      • Julie Draper

        Hi James, same issue here but I use Yoast SEO. Yoast has changed the global tracking function from the default ga() to the more unique __gaTracker(). I’ve changed my code to read on_sent_ok:__gaTracker “([‘_trackPageview’, ‘/test’]);”

        The confirmation message doesn’t show and I have no idea yet if it is tracking in Google. Any suggestions?

        • Hi Julie, the event may still be tracking. If you tried opening the browser console to see if there are any errors when you submit the form? Would love to take a closer look for you?

          • Julie Draper

            I would love you to take a closer look because it’s giving me a real headache. I can’t see any errors!

          • Great, if you Direct Message me on twitter @jamesbavington I’ll be able to take a look. I’m hoping to add some more content to this blog post to help people so if we can crack your site I can update my post.

  • Julie Draper

    Thank You James! Problem solved on two sites. No javascript conflicts as I thought and the code above works when inputted correctly – I had spaces where there should not have been spaces. Thanks again.

  • Jack Roberts

    Hi James. Any chance I could get your input on my own issues in getting Analytics goal tracking to work with Contact form 7 on our WP site? I found your tutorial very helpful but I have some kind of a bug in our instance that is preventing the script from sending the page view to Analytics. Please reply by email at if you prefer to take this offline. Thanks!

  • Hi James,

    I am getting same issue as other are facing – no confirmation message. As i have seen in the comments below, adding ‘submit’ in code solved the issue.

    Please let me know if lit is the coorect way.

    My code is: on_sent_ok: “ga(‘send’, ‘pageview’, ‘/goal/thankyou’);”

    If I add submit in this:

    on_sent_ok: “ga(‘send’, ‘pageview’, ‘/goal/thankyou’ ‘submit’);”

  • Mike

    I could be missing something but I had the same problem that many seem to be facing, i.e. no submission success message even though it was submitting successfully. I moved the semi-colon at the end outside of the quotation marks and started getting the submission success message again. I’m still waiting for GA to tick over to see if it is actually tracking the forms…

  • Thank’s for sharing this info!

    I tried to do it but nothing happened on my Analytics dashboard. What could be the problem?