Created
February 10, 2020 19:21
-
-
Save hitGovernor/0ac92f41cc2958d3389b013185c38138 to your computer and use it in GitHub Desktop.
Client-side option to overwrite Ensighten data element extraction logic. Works well for SPA implementations
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
/** | |
* overwrite ensighten data element extraction logic, forcing the provided | |
* value to be returned the next time Bootstrapper.data.resolve("{{ID}}"); is | |
* called. this essentially changes the extraction logic to: return(value); | |
* @param dataId {string} ensighten data element id | |
* @param value {string} new value | |
* @example setDataElementValue("12345", "winner!"); => "winner!" | |
*/ | |
function setDataElementValue(dataId, value) { | |
if (dataId) { | |
try { | |
Bootstrapper.data.getDataDefinitionById(dataId).extract = function () { | |
return (value) ? value : ""; | |
}; | |
} catch (err) { | |
/** ignore **/ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment