Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Johnson (Evo) hitGovernor

View GitHub Profile
@hitGovernor
hitGovernor / timeParting.js
Last active Aug 30, 2019
timeParting.js - Returns {day|julian|yyyy-mm-dd|hh:00|offset|timezone}
View timeParting.js
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 + "";
@hitGovernor
hitGovernor / getParams.js
Last active Aug 20, 2020
turns query params into key:value pairs
View getParams.js
/**
* 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 / ensightenPrivacyGateway_blockedResources.js
Last active Dec 21, 2019
Consoles out a table of all resources blocked by Ensighten's Privacy Gateway
View ensightenPrivacyGateway_blockedResources.js
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 / getHotJarUserID.js
Last active Jan 18, 2022
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.
View getHotJarUserID.js
(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 / ens_getDataDef.js
Created Jan 31, 2020
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.
View ens_getDataDef.js
/**
* 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 {
View 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 / ensighten_overwriteDataElementExtractLogic.js
Created Feb 10, 2020
Client-side option to overwrite Ensighten data element extraction logic. Works well for SPA implementations
View ensighten_overwriteDataElementExtractLogic.js
/**
* 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 / buildCIDfromUTM.js
Created Apr 8, 2020
A simple function to build a single campaign identifier (CID) string out of a collection of utm_ parameters.
View buildCIDfromUTM.js
/**
* 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 / cookies.js
Last active Apr 13, 2020
A simple cookie module, accounts for setting, getting, and removing client-side cookies via JavaScript.
View cookies.js
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 / wistia_milestone_tracking.js
Created Jul 27, 2020
Leverages Wistia JS API to monitor specified video milestones
View wistia_milestone_tracking.js
window.videos = {};
wistiaEmbeds.forEach(function (vid) {
window.videos[vid.hashedId()] = {
id: vid.hashedId(),
name: vid.name(),
duration: vid.duration(),
status: {
step_play: false,
step_25: false,
step_50: false,