Skip to content

Instantly share code, notes, and snippets.

View hitGovernor's full-sized avatar

Brian Johnson (Evo) hitGovernor

View GitHub Profile
@hitGovernor
hitGovernor / cookies.js
Last active April 13, 2020 20:16
A simple cookie module, accounts for setting, getting, and removing client-side cookies via JavaScript.
var cookies = {
/**
* @param payload {object}
* @param payload.cookieName {string}
* @param payload.cookieValue {string}
* @param payload.days {=Number} - number of days before cookie expires
* @param payload.sameSite {=string} sameSite setting, default to "None" if not provided
* @param payload.secure {=Boolean} default to not secure
*/
set: function (payload) {
@hitGovernor
hitGovernor / buildCIDfromUTM.js
Created April 8, 2020 12:30
A simple function to build a single campaign identifier (CID) string out of a collection of utm_ parameters.
/**
* builds a single campaign identifier (CID) string out of a collection of utm_ parameters
* payload is required, but all properties of payload are optional
*/
function buildCIDfromUTM(payload) {
var delimiter = payload.delimiter || '_';
var cid = payload.cid || [
payload.medium,
payload.source,
payload.campaign,
@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 / 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 / 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 + "";