Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitGovernor/0ac92f41cc2958d3389b013185c38138 to your computer and use it in GitHub Desktop.
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
/**
* 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