Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save icetee/2fb391954dbf16dfc81bc08ce8436f3f to your computer and use it in GitHub Desktop.
Save icetee/2fb391954dbf16dfc81bc08ce8436f3f to your computer and use it in GitHub Desktop.
Google Adwords Asynchronous Remarketing Javascript Module - Lazy Loading Adwords Conversion Code
// https://gist.github.com/icetee/2fb391954dbf16dfc81bc08ce8436f3f
// Usage : googremarketing.loadTag(conversionid, conversionlabel)
// Start Google Remarketing Module
var googremarketing = (function() {
var asyncload = 0;
// Load Async Google Adwords remarketing code
function Gremloader() {
if (asyncload == 0) {
var g = document.createElement('script');
var s = document.getElementsByTagName('script')[0];
g.src = 'https://www.googleadservices.com/pagead/conversion_async.js';
s.parentNode.insertBefore(g, s);
asyncload = 1;
}
}
// Wait...
function whenAvailable(name, callback) {
var interval = 20; // ms
var loop = function() {
window.setTimeout(function() {
if (window[name]) return callback(window[name]);
loop();
}, interval);
}
loop();
}
//Set Google Remarketing Tag
function setTag(convid, convlabel) {
window.google_trackConversion({
google_conversion_id: convid,
google_conversion_label: convlabel,
google_remarketing_only: true
});
}
return {
loadTag: function(conversionid, conversionlabel) {
Gremloader();
whenAvailable("google_trackConversion", function(t) {
setTag(conversionid, conversionlabel);
});
}
}
}());
// End of Google Remarketing module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment