Skip to content

Instantly share code, notes, and snippets.

@hitGovernor
Created January 31, 2020 21:58
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/3e142f1e910db1e33dc87f182f63660f to your computer and use it in GitHub Desktop.
Save hitGovernor/3e142f1e910db1e33dc87f182f63660f to your computer and use it in GitHub Desktop.
Checks for specified Ensighten data definition, ensuring only an expected value is returned. The primary benefit is that "data does not exist" messages are not captured in your data.
/**
* checks for specified data definition, ensuring only an expected value is returned.
* the primary benefit is that "data does not exist" messages are not captured in your data
* @param dataDefId {number} data definition id
*/
function getDataDef(dataDefId) {
// check the list of data definition ids on the current page before attempting to resolve
if (Bootstrapper.dataDefinitionIds.indexOf(dataDefId) > -1) {
return Bootstrapper.data.resolve(dataDefId);
} else {
// try the request anyway to let the "failure" get logged in an e.gif request
var dataDefValue = Bootstrapper.data.resolve(dataDefId);
return !/data\sdefinition.*does\snot\sexist/i.test(dataDefValue) ? dataDefValue : "";
}
}
console.log(getDataDef(12345));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment