Skip to content

Instantly share code, notes, and snippets.

View iampatgrady's full-sized avatar
🎯
Thinking about data challenges

iampatgrady

🎯
Thinking about data challenges
View GitHub Profile
@iampatgrady
iampatgrady / quantile-filter-example.ipynb
Created May 24, 2023 14:54
quantile filter example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iampatgrady
iampatgrady / Session ID - Cookie.js
Created April 18, 2022 23:19
Proof-of-concept for setting and managing a 30-minute session ID as a GTM Custom Javascript Variable.
@iampatgrady
iampatgrady / Session ID - Local Storage.js
Last active April 18, 2022 23:23
Proof-of-concept for setting and managing a 30-minute session ID as a GTM Custom Javascript Variable.
function(){
const storageName = "session_id_with_expiry";
function genId() {
return ([1e8]+-1e3).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
}
function setSessionId(name, value, ts) {
@iampatgrady
iampatgrady / bq_sql_joins_demo.sql
Last active August 23, 2018 18:30
BigQuery - SQL joins: all in one
-- zjuul wrote: https://gist.github.com/zjuul/aabde0ac52f3ee2974833cde718c56c6
-- I converted to BigQuery syntax:
with l as (
select 'both' as val
union all
select 'left_only' as val
), r as (
select 'both' as val
union all
select 'right_only' as val
@iampatgrady
iampatgrady / all_join_types.sql
Created August 23, 2018 18:05 — forked from zjuul/all_join_types.sql
SQL joins: all in one
-- create two tables: L and R
-- content of tables a "val" column with two rows.
-- rows in L: "left only" and "both"
-- rows in R: "right only" and "both"
with l as (
select 'both' as val
union
select 'left_only' as val
), r as (
@iampatgrady
iampatgrady / convert_classic_to_universal.js
Last active November 17, 2017 20:36
Convert Classic GA integrations to work with new Universal or GTM
// Code Example taken from Jeff Pierce's dataLayer Inspector+ Chrome Extension
// https://chrome.google.com/webstore/detail/analytics-pros-datalayer/kmcbdogdandhihllalknlcjfpdjcleom?hl=en-US
// create the handler object, and initialize the _gaq array
var a = window["_gaq"] = window["_gaq"] || [];
// for Data Layer Support:
window.dataLayer = window.dataLayer || [];
// b() is where you invoke business logic as a result of data pushed in _gaq
@iampatgrady
iampatgrady / Tracking Incremental Search.js
Last active November 26, 2021 22:41
The script tracks search experiences that update automatically as you type. Known as Incremental Search in software and As-You-Type in web applications. This solution offers a way to track the value as a timeout expires after keypress. There is logic to prevent redundant events from firing.
/*
* Based on example at https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout
* Usage: edit config variables, copy+paste into JS console, type in search field and wait for dataLayer push
*/
(function(dL) {
/*
* Application Functions
*/
@iampatgrady
iampatgrady / form-field-tracking.js
Last active October 3, 2018 04:46
Google Analytics - Dynamic Form Field Tracking Data Layer Implementation
/*
* Analytics Pros, 2017
*/
(function(data_layer) {
var start_time = Date.now() // start timer on page load
// loop through all forms on the page, keep track of index with "i"
document.querySelectorAll("form").forEach(function(form,i) {
var position_index = 1,
<script>
//TODO: Anyone using this script will likely want to extend. This is a guide to get started
(function(dataLayer){
var i = 0;
//array of percentages at which progress notifications are pushed to the dataLayer
var markers = [10,25,50,75]; //adjust these values if you want different progress reports
var playersMarkers = [];
function findObjectIndexById(haystack, key, needle) {