Search code examples
javascriptphpwordpressgoogle-analyticscontact-form-7

Adding Google Conversion code to WordPress Contact Form 7


I found a tutorial for adding Google Conversion code to WordPress Contact Form 7 plugin which can be found here.

Currently I've added

<script type="text/javascript">
    $(".wpcf7-form").submit(function(){
        var google_conversion_id = "12345678910";
        var google_conversion_label = "xxxxxxxxxxx";
        var image = new Image(1,1); 
        image.src = "http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?label="+google_conversion_label+"&script=0";
    });
</script>

to my footer, but it doesn't send correct results. Could someone help me out with what I should add to my Contact Form Plugin, through the control panel of WordPress, to make my Analytics show correct results. I would not prefer redirecting to another page.


Solution

  • You are on right track. As this script runs you get your results recorded at server.

    1. The easiest and most common way to achieve this is to place the script on a separate page(generally a thank-you.php) and redirect user to that page so after completion of his activity we can run this script and record this activity. OR
    2. The other way(a tricky one though) is to make this script run on the same page using ajax/javascript after user's activity.

    If you want to set it without any redirection you may find this helpful.

    Google Conversion Tracking Without Redirection