Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

javascript - How to implement a Google Adwords "conversion pixel" using ajax on a submit button (no "thank you" page)

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

<!-- Google Code for General_Lead Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 000;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "hahaha";
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/975247275153/?label=IiuoCNO17lcQgZ2P0QM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

to a contact form on my website which doesn't lead to a "thank you" page. This is my submit form code. (The validation isn't 100% done :P )

// Send button for the "contact form".
$('#sendBtn').click(function(){
    //get info 
    var fullname = $("#fullname").val();
    var email = $("#email").val();
    var text = $("#text").val();
    //send info to php 
    $.ajax({
        beforeSend: function() {
            if ( IsEmail(email) == false) {
                $('#aboutUnsuccess').show("slow");
                $('#contactform').hide("slow");
            }
        },
        url: 'http://www.example.com/contact.php', 
        type: "POST", 
        data: ({ "fullname": fullname, "email": email, "text": text }), 
        success: function (results){
            if ( IsEmail(email) == true) {
                //hide table 
                $('#contactform').hide('slow', function() {
                    $('#contactform').hide( "slow" );
                  });
                //show textboxes
                $('#aboutSuccess').show("slow");
            }
        }
    }); 


});

I tried using .append that I found out it doesn't work after googleing.

and tried to follow this post: How to track a Google Adwords conversion onclick? - which didn't work too

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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,
    // ...
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...