Google Adwords Conversion with AJAX

I had a Google Adwords Conversion tracking code that I needed to implement basically on an onclick event. The form I am tracking, submits information using AJAX and then renders a ‘Thank you‘ message to the page by replacing the form’s div with the ‘Thank you‘ HTML.

I googled for this requirement and found a solution on Google Adwords Conversion with AJAX which I am sharing here.

Google Adwords Conversion with AJAX

Actually Google itself provides an asynchronous version of the AdWords Remarketing Tag because it is useful for websites where the tag needs to be fired other than during a page load means like AJAX.

There are 2 steps to implement asynchronous version of the AdWords in the website:

1. Loads the conversion_async.js script from the ‘googleadservices.com‘ server. This can be loaded by adding the following snippet inside of the head section of your site:

What this step does: By loading conversion_async.js, google_trackConversion function will be added to the window object.

2. Call the google_trackConversion function. We can call this function whether on page load or at appropriate time by programmatically.

When calling the google_trackConversion function the parameters that were globally-scoped for the standard AdWords Remarketing Tag are now encapsulated within an object passed as an argument.

Firing the asynchronous AdWords on page load:

We can directly call google_trackConversion function on page load with in a ‘script‘ tag like above given example.

Firing the asynchronous AdWords Remarketing Tag programmatically

We can also fired asynchronous AdWords by calling google_trackConversion function from our existing JavaScript code whenever is appropriate, for example as part of a ‘XMLHttpRequest‘ or AJAX or on any form or form controls events.

On XMLHttpRequest :

This is all light above is an example to understand how can we integrate Google Adwords Conversion with AJAX.

Like this Post? Share