Last active
August 29, 2015 14:05
-
-
Save randomweapon/1f108df42edfd1fcc51e to your computer and use it in GitHub Desktop.
Google AdWords Conversion Tracking with jQuery
This file contains hidden or 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
// 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