Skip to content

Instantly share code, notes, and snippets.

View hitGovernor's full-sized avatar

Brian Johnson (Evo) hitGovernor

View GitHub Profile
@hitGovernor
hitGovernor / ensighten_overwriteDataElementExtractLogic.js
Created February 10, 2020 19:21
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) {
@hitGovernor
hitGovernor / ens_cookieModuleFix.js
Created February 3, 2020 18:56
ens_cookieModuleFix.js
//Begin Cookie Module
//Pull Date: 10-17-18
//Be sure to update domain to top level domain of client website
// @updated 01-22-2020 bjohnson@evolytics.com update set() to account for sameSite + Secure
Bootstrapper.Cookies = function () {
return {
domain: 'intuit.com' || location.hostname,
get: function (a, c) {
for (var b = document.cookie.split(";"), d = 0; d < b.length; d++) {
var e = b[d].replace(/^\s+/, "").split("=");
@hitGovernor
hitGovernor / ens_getDataDef.js
Created January 31, 2020 21:58
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 {
@hitGovernor
hitGovernor / getHotJarUserID.js
Last active April 12, 2023 11:17
Retrieves the HotJar user ID from the browser. The ID can be passed to analytics or other systems as a way to connect HotJar recordings to other systems.
(function () {
// gets hotjar user id (hjUID)
var hjUID = "";
try {
if (typeof (hj) != "undefined" && hj.hasOwnProperty("globals")) {
// sample: a21c0a02-3b48-53c6-94b4-5604e281e5d8
// the value before the first "-" ("a21c0a02") is the user identifier that can be referenced in the hj interface
// use the following snippet to return only the user identifier (eg// "a21c0a02"):
// hjUID =hj.globals.get("userId").split("-").shift();
@hitGovernor
hitGovernor / ensightenPrivacyGateway_blockedResources.js
Last active December 21, 2019 16:36
Consoles out a table of all resources blocked by Ensighten's Privacy Gateway
if (typeof (gateway) != "undefined") {
/**
* consoles out the provided array using the provided status as a header
* @param status {string}
* @param output {array}
*/
function gwLogger(status, output) {
if (output.length > 0) {
console.log(status + " REQUESTS:");
console.table(output);
@hitGovernor
hitGovernor / getParams.js
Last active August 20, 2020 14:18
turns query params into key:value pairs
/**
* returns an object with all query parameters as key/value pairs
* @param payload - if ommitted, returns all params as an object; if passed as string specifying a parameter,
* returns the value of the specified parameter name; can be passed as object { search: document.location.search, returnKey: {{parameter-name}} }
* @returns {object} - example: http://example.com?a=a-value&B=B-VALUE = > { "a": "a-value", "b": "B-VALUE"}
*/
function getParams(payload) {
var searchString = document.location.search,
returnKey = "";
@hitGovernor
hitGovernor / timeParting.js
Last active August 30, 2019 14:45
timeParting.js - Returns {day|julian|yyyy-mm-dd|hh:00|offset|timezone}
var timeParting = {
/**
* @description returns utc offset based on local time (eg//utc-05 = central daylight time, north america)
* a list of utc offsets and timezones can be found here: http://forbrains.co.uk/international_tools/earth_timezones
* @param pv_date {date}
*/
getTimezoneOffset: function (pv_date) {
var offset = ((pv_date.getTimezoneOffset() / 60) * -1); //multiply by -1 to account for inverted utc offset in JS getTimezoneOffset()
var posOrNeg = (offset > 0) ? "+" : "-";
var tmpOffset = offset + "";