JavaScript to Fire AdWords Conversion Pixel on Form Submit | Community
Skip to main content
September 3, 2015
Solved

JavaScript to Fire AdWords Conversion Pixel on Form Submit

  • September 3, 2015
  • 1 reply
  • 4197 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by

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!

1 reply

SanfordWhiteman
New Participant
September 3, 2015

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.

Accepted solution
September 4, 2015

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!

pavel_plachky
New Participant
June 20, 2017

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>