Skip to content

Instantly share code, notes, and snippets.

@doublejosh
Created December 8, 2017 21:44
Show Gist options
  • Save doublejosh/9cbee024e14b8d41df750e38ca46660c to your computer and use it in GitHub Desktop.
Save doublejosh/9cbee024e14b8d41df750e38ca46660c to your computer and use it in GitHub Desktop.
Eloqua tracking script - Namespacing (jQuery flavor)
/**
* @file Eloqua visitor tracking (jQuery flavor).
*/
var Eloqua = window.Eloqua || {};
(function(Eloqua, $, window, _elqQ) {
Eloqua.timerId = null;
Eloqua.timeout = 5;
/**
* Retrieve Eloqua GUID and set form field value.
*
* Copied from Eloqua docs (and at least namespaced)...
* https://docs.oracle.com/cloud/latest/marketingcs_gs/OMCAA/#Help/EloquaAsynchronousTrackingScripts/Tasks/RepostingExternalForms.htm
*
* @todo Create promise function to retrieve GUID vs this nonsense.
*/
Eloqua.waitForEloquaGUID = function () {
if (!!(Eloqua.timerId)) {
if (Eloqua.timeout == 0) {
return;
}
if (typeof window.GetElqCustomerGUID === 'function') {
$('[name="elqCustomerGUID"]').val(GetElqCustomerGUID());
return;
}
Eloqua.timeout -= 1;
}
Eloqua.timerId = setTimeout(Eloqua.waitForEloquaGUID, 500);
return;
};
// Fire on window load.
window.onload = Eloqua.waitForEloquaGUID;
// Issue request for ID from Eloqua server.
_elqQ.push(['elqGetCustomerGUID']);
}(Eloqua, $, window, _elqQ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment