How to implement a Google Adwords “conversion pixel” using ajax on a submit button (no “thank you” page)

前端 未结 4 360
名媛妹妹
名媛妹妹 2020-12-08 15:30

I want to implement an adwords \"conversion pixel\" script - this is the script:




        
相关标签:
4条回答
  • 2020-12-08 15:59

    100% working Google Conversion Tracking concept using Ajax on a submit button :

     $.ajax({
            type: "POST",
            url: "enquiry-submit.php",
            data: data,
            success: function (result) {
              $("#msg").fadeIn(400).html(result);
    
              /* Conversion Tracking Start */
              var google_conversion_id = YOUR_CONVERSION_ID_HERE;
              var google_conversion_language = "en";
              var google_conversion_format = "3";
              var google_conversion_color = "ffffff";
              var google_conversion_label = "YOUR_CONVERSION_LABEL_HERE";
              var google_remarketing_only = false;
    
              $.getScript('//www.googleadservices.com/pagead/conversion.js');
    
              var image = new Image(1, 1); 
              image.src = "//www.googleadservices.com/pagead/conversion/YOUR_CONVERSION_ID_HERE/?label=YOUR_CONVERSION_LABEL_HERE&guid=ON&script=0";  
              /* Conversion Tracking End */
            }
          });
    

    It is working on my Google Ads Campaign.

    Note: You must try or test this by clicking on your ad. The effect of conversion will be visible after 15 minutes on your Google AdWords Console

    0 讨论(0)
  • 2020-12-08 16:00

    function for creating iframe and put adwords code in thanks.php file

    function conversionTracker()  {
                    var  iframe = document.createElement('iframe');
                    iframe.style.width = '0px';
                    iframe.style.height = '0px';
                    document.body.appendChild(iframe);
                    iframe.src = 'thanks.php'; //Make sure path is correct! (update with bloginfo var for nebula)
                };
    call conversionTracker() in ajax success function
    ....
    success: function(response){
    conversionTracker();
    }
    

    then create a thanks.php file and put adwords code in this file

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Thank You</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    
    </head>
    <body>
        <!-- Google Code for Frachiseglobal Conversion Page -->
        <script type="text/javascript">
        /* <![CDATA[ */
        var google_conversion_id = 1234;
        var google_conversion_language = "en";
        var google_conversion_format = "3";
        var google_conversion_color = "ffffff";
        var google_conversion_label = "dummy";
        var google_conversion_value = 1.00;
        var google_conversion_currency = "INR";
        var google_remarketing_only = false;
        /* ]]> */
        </script>
        <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
        </script>
        <noscript>
        <div style="display:inline;">
        <img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/1234/?value=1&amp;currency_code=INR&amp;label=dsfdsf&amp;guid=ON&amp;script=0"/>
        </div>
        </noscript>
    </body>
    </html>
    

    Note : here label and conversion_id are fake values, Please put your own.

    0 讨论(0)
  • 2020-12-08 16:03

    Google supports async conversions:

    https://developers.google.com/adwords-remarketing-tag/asynchronous/

    Load this script in your html file:

    <script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script>
    

    And then call the function google_trackConversion when your user clicks the button:

    window.google_trackConversion({
        google_conversion_id: 1234,
        google_remarketing_only: true,
        // ...
    });
    
    0 讨论(0)
  • 2020-12-08 16:09
     $.ajax({
       dataType: "script",
       cache: true,
       url: 'https://www.googleadservices.com/pagead/conversion_async.js'
     }).done(function () {
       isInitialized = true;
     });
    
    google_trackConversion({
       google_conversion_id: 12345,
       google_conversion_language: "en",
       google_conversion_format: "3",
       google_conversion_color: "ffffff",
       google_conversion_label: "label",
       google_conversion_value: 0,
       google_remarketing_only: false
    });
    
    0 讨论(0)
提交回复
热议问题