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&guid=ON&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.
Solved! Go to Solution.
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&guid=ON&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!
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.
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&guid=ON&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!
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&guid=ON&script=0&ord=" + (new Date()).getTime();
}();
});
});
</script>
Wouldn't worry about that, Pavel. The pixel 302s to a random URL and the 302 itself won't be cached.