SOLVED

JavaScript to Fire AdWords Conversion Pixel on Form Submit

Go to solution
Highlighted
Anonymous
Not applicable

JavaScript to Fire AdWords Conversion Pixel on Form Submit

I found a clever piece of code on this site to fire the AdWords conversion pixel by creating the 1x1 image that Google gives you in their conversion setup.

I'm trying to adapt it to Marketo forms, but I can't seem to get the code working.

Here's what I have so far (with the conversion numbers/labels replaced):

<script type="text/javascript">

MktoForms2.whenReady(function(form){

     form.onSuccess(function(){

          function trackConv() {

               var image = new Image(1,1);

               image.src = "//www.googleadservices.com/pagead/conversion/XXXXXXXXXX/?label=XXXXXXXXXXXXX&amp;guid=ON&amp;script=0"; 

          }

     });

});

</script>

Any ideas why I'm not seeing any conversions in AdWords? I'm thinking it may be a script error as I'm new to JavaScript.

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: JavaScript to Fire AdWords Conversion Pixel on Form Submit

It worked! Thank you so much!

Here's the finalized code:

<script type="text/javascript">

MktoForms2.whenReady(function(form){

     form.onSuccess(function(){

          !function trackAdWordsConversion() {

               var trackingPixel = new Image(1, 1);

                trackingPixel.src = "//www.googleadservices.com/pagead/conversion/xxxxxxxxxxx/?label=xxxxxxxxxxxxxxx&amp;guid=ON&amp;script=0";

           }();

     });

});

</script>

We created a conversion pixel in AdWords to track anytime someone comes to our site from an ad and then downloads an asset.

This is great for implementation on our templates.

So cool!

View solution in original post

4 REPLIES 4
Highlighted
Level 10 - Community Moderator

Re: JavaScript to Fire AdWords Conversion Pixel on Form Submit

You defined the function, but you didn't run it! As this is a one-time-use function (never used outside of this context), I'd do:

!function trackAdWordsConversion() {

     var trackingPixel = new Image(1, 1);

     trackingPixel.src = "//www.googleadservices.com/pagead/conversion/XXXXXXXXXX/?label=XXXXXXXXXXXXX&guid=ON&script=0";

}();

Note the use of verbose, accurate variable names -- best practice for development.  Stuff like 'image' and 'trackConv' will not make sense to you years from now, let alone to someone else.

Anonymous
Not applicable

Re: JavaScript to Fire AdWords Conversion Pixel on Form Submit

It worked! Thank you so much!

Here's the finalized code:

<script type="text/javascript">

MktoForms2.whenReady(function(form){

     form.onSuccess(function(){

          !function trackAdWordsConversion() {

               var trackingPixel = new Image(1, 1);

                trackingPixel.src = "//www.googleadservices.com/pagead/conversion/xxxxxxxxxxx/?label=xxxxxxxxxxxxxxx&amp;guid=ON&amp;script=0";

           }();

     });

});

</script>

We created a conversion pixel in AdWords to track anytime someone comes to our site from an ad and then downloads an asset.

This is great for implementation on our templates.

So cool!

View solution in original post

Highlighted

Re: JavaScript to Fire AdWords Conversion Pixel on Form Submit

Hello, this is really helpful. Only thing that would worry me is that some browsers may cache the image so repeated conversions would not be reported. Using date/time stamp should fix it, as follows:

<script type="text/javascript">

MktoForms2.whenReady(function(form){

     form.onSuccess(function(){

          !function trackAdWordsConversion() {

               var trackingPixel = new Image(1, 1);

                trackingPixel.src = "//www.googleadservices.com/pagead/conversion/xxxxxxxxxxx/?label=xxxxxxxxxxxxxxx&amp;guid=ON&amp;script=0&amp;ord=" + (new Date()).getTime();

           }();

     });

});

</script>

Highlighted
Level 10 - Community Moderator

Re: JavaScript to Fire AdWords Conversion Pixel on Form Submit

Wouldn't worry about that, Pavel. The pixel 302s to a random URL and the 302 itself won't be cached.