Skip to content

Instantly share code, notes, and snippets.

@randomweapon
Last active August 29, 2015 14:05
Show Gist options
  • Save randomweapon/1f108df42edfd1fcc51e to your computer and use it in GitHub Desktop.
Save randomweapon/1f108df42edfd1fcc51e to your computer and use it in GitHub Desktop.
Google AdWords Conversion Tracking with jQuery
// accepts 1 parameter which is passed straight through to php file for determining which tracking code to display
function fireConversionCode( code )
{
// check to see if iframe is already created. We only want to create one iframe on the page, but can load multiple pixels
if ( $('#trackingFrame').length == 0 )
{
// create empty iframe
var iframe = $('<iframe id="trackingFrame" width="0" height="0">').css({"width":"0px","height":"0px"});
// append to end of document
$('body').append(iframe);
}
else
{
// load tracking frame for use
iframe = $('#trackingFrame');
}
// now that we have the iframe loaded, call load page which will display the tracking code
// doesn't have to php, could point to a .html file
$(iframe).get(0).src = "tracking.php?code=" + code;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment