Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Johnson (Evo) hitGovernor

View GitHub Profile
@hitGovernor
hitGovernor / tealium_assetScraper.js
Last active Mar 26, 2021
Scrapes the Tealium IQ (TiQ) web interface to retrieve all Data Layer variables, Load Rules, Tags, and Extensions. Output is written to the browser console either using console.table() or as a comma-delimited string, suitable for copy/paste use. To use, you must be logged into TiQ, viewing the Data Layer tab. Feedback is appreciated.
View tealium_assetScraper.js
// if the element exists, returns the innerText, otherwise an empty string
function getInnerText(ele) {
if (ele) {
return ele.innerText;
}
return "";
}
// executes the query selectors and builds the output
@hitGovernor
hitGovernor / tealium_debugToggle.js
Last active Jan 26, 2021
tealium_debugToggle.js
View tealium_debugToggle.js
// tiq toggle debug
(document.cookie.indexOf("utagdb=true") > -1) ? document.cookie = "utagdb=false" : document.cookie = "utagdb=true";
// bookmarklet: javascript:(function()%7B(document.cookie.indexOf("utagdb%3Dtrue")>-1)%3Fdocument.cookie%3D"utagdb%3Dfalse":document.cookie%3D"utagdb%3Dtrue"%3B%7D)()%3B
View Untitled-2
s.registerPreTrackCallback(function(requestUrl, allowList, hostname) {
var doTrack = (allowList.indexOf(hostname) > -1);
console.log(allowList, hostname, doTrack);
}, ['sandbox.test.com'], document.location.hostname);
@hitGovernor
hitGovernor / launchCookieStorageDataElement.js
Created Dec 3, 2020
building a data element to store info in a cookie on the root domain
View launchCookieStorageDataElement.js
/**
* Steps:
* 1. Create a data element to retrieve the query parameter; set storage to "none"
* 2. Create a second data element that sets the cookie on your domain's root
* 3. Reference the second data element on load of every page (it won't fire if it's not referenced)
* 4. When you need the info in the cookie, pull it from the data element created in step 2
*/
// check for the query param first (this always overrides a saved value)
var retval = _satellite.getVar("qsp:ex_id");
@hitGovernor
hitGovernor / aep_scrolldemo.js
Created Dec 2, 2020
basic js scroll tracker with added scrollTimer for aep conversation
View aep_scrolldemo.js
var govScroll = {
measurements: {
initial: {},
current: {},
max: {},
},
config: {
hasMilestoneOccurred: {
25: false, // false indicates it has not fired, but should; true indicates it already has (or shouldn't)
50: false,
View aelc_20200930.js
// default the flag to false (it gets set to true in registerPostTrackCallback)
var flag = false;
// wait for flag=true (set in registerPostTrackCallback) to fire the s.tl() call
var waitForFlag = setInterval(function() {
if(flag) {
console.log("fire s.tl() here");
clearInterval(waitForFlag);
}
}, 50);
View regexEscapes.js
var x = {
regexEscapes: function (str) {
str = str.replace(/\//g, "\\/");
str = str.replace(/\?/g, "\\?");
return str;
}
}
var val = x.regexEscapes("/test/this/here?for=now");
@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,
@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 / 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,