Forked from vhsu/Lazy Load Google Remarketing & Conversion Javascript Module.js
Last active
August 29, 2015 14:16
-
-
Save LCHCAPITALHUMAIN/d25372d27c692bdcce06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This module can be used to trigger the Google Adwords remarketing tag asynchronously, without loading unused ressources | |
// Mostly useful when the Google Remarketing tag is triggered only on specific conditions. | |
// Author : Vincent Hsu -> twitter.com/suisseo -> http://www.suisseo.ch | |
// Language : Javascript | |
// 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 | |
window.setTimeout(function() { | |
if (window[name]) { | |
callback(window[name]); | |
} else { | |
window.setTimeout(arguments.callee, interval); | |
} | |
}, interval); | |
} | |
//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