Skip to content

Instantly share code, notes, and snippets.

View smhmic's full-sized avatar

Stephen Harris smhmic

  • Philadelphia, PA
View GitHub Profile
@smhmic
smhmic / hyperlink_list.gas.js
Created March 17, 2023 02:43
G Apps Script - hyperlink list / multiple hyperlists in gsheet cell
View hyperlink_list.gas.js
@smhmic
smhmic / - README - Hubspot refinement CSS & JS .md
Last active September 17, 2021 15:45
Hubspot refinement css/js
View - README - Hubspot refinement CSS & JS .md
@smhmic
smhmic / - README - Add event_id to FB pixels (for redundant deduplicated CAPI tracking).md
Last active May 4, 2023 16:00
Add event_id to FB pixels (for redundant deduplicated CAPI tracking)
View - README - Add event_id to FB pixels (for redundant deduplicated CAPI tracking).md

This does not cover all aspects of setup; just the web pixel side. All this does is add an event_id to all FB pixels (arguably the most complex part of the clientside setup) without having to modify any pixels directly.

This code is for GTM, but would be trivial to modify code for use anywhere.

Usage:

In GTM web container ...

  1. Add Facebook Pixel CAPI Helper as a tag; fire on All Pages.
  2. Add Facebook Event ID as a variable.
  3. In GA4 config tag, set event_id = {{Facebook Event ID}}.
@smhmic
smhmic / get_set_cookie.js
Created February 2, 2021 16:44
Generic Get/Set Cookie Functions
View get_set_cookie.js
@smhmic
smhmic / - README.md
Last active November 25, 2020 15:47
Track Web Vitals via GTM
View - README.md

This is a pared-down version of Google's web-vitals library for tracking core web vitals RUM via GTM, with various changes.

Google recommends loading it's web-vitals library via a CDN, which adversely impacts performance -- the very thing we're trying to measure & optimize! Using a common CDN has certain benefits mitigating the performance impact, but if we're already loading GTM it would be ideal to instead add the library as a GTM tag. (Actually the ideal way is to package this library with first-party code, but the purpose of Web Vitals trackings aligns nicely with the core needs of teams using GTM.) We lose the advantage of automatic library updates, but we want to make some tweaks anyway...

Primary changes:

  • Only include what we need. This script is ~1/3 smaller than the UMD base+polyfill version of G's library. This script focuses on the three core web vitals,
@smhmic
smhmic / allowlinker-ga.js
Last active October 22, 2020 00:26 — forked from sahava/allowlinker-ga.js
This script reproduces Google Analytics' (analytics.js) allowLinker/autolinker logic, resulting in a function that returns the GA client id, but only if the autolinker parameter is valid. Uses the "old" linker plugin format. You can also pass a string as an argument to check if that string is a valid linker parameter.
View allowlinker-ga.js
// Mirrors analytics.js logic to validate autolinker param, and returns cid if valid.
// Returns false if autolinker param found, but invalid.
// Otherwise returns undefined.
var getCidFromAutolinker = function(str) {
var joiner = function (cidGid, offset) {
var a = new Date,
b = window.navigator,
c = b.plugins || [];
var d = [cidGid, b.userAgent, a.getTimezoneOffset(), a.getYear(), a.getDate(), a.getHours(), a.getMinutes() + offset];
@smhmic
smhmic / GTM AMP Container Proxy (for sharing a first-party GA client id) .md
Last active July 23, 2020 14:46
GTM AMP Container Proxy (for sharing GA Client ID with non-AMP pages)
View GTM AMP Container Proxy (for sharing a first-party GA client id) .md

This code is for serving an AMP GTM container from your own domain, so that the GA Client ID can be shared between your AMP pages and the rest of your site (enabling them to be tracked together in the same GA property).

Once the endpoint is deployed, you'll need to replace //www.googletagmanager.com/amp.json in the <amp-analytics> embed with the path to your endpoint (leaving the query parameters in place) within your AMP template's source code:

<amp-analytics 
  config="//www.googletagmanager.com/amp.json?id=GTM-XXXXX&gtm.url=SOURCE_URL" 
  data-credentials="include"></amp-analytics>

You can specifiy the cookie domain by appending &amp;cookieDomain=YOURDOMAIN.COM to the endpoint URL.

@smhmic
smhmic / getTLD.js
Last active March 3, 2021 21:13
Get top-level domain (TLD) of current page
View getTLD.js
function getTLD(){
var cookieName = '_tmp_detect_tld',
globalNamespacePageloadCache = cookieName;
return window[globalNamespacePageloadCache] || ( window[globalNamespacePageloadCache] = (function(){
var i, domain, parts = location.hostname.split('.'),
UNDEFINED = '{{UNDEFINED}}', cKeyValPair, c;
if( window.navigator && navigator.cookieEnabled === false ){ return UNDEFINED+' cookies disabled'; }
for( i=parts.length-1; i>=0; i-- ){
domain = parts.slice(i).join('.');
cKeyValPair = cookieName+'_'+domain+'=1';
@smhmic
smhmic / - Test GA CID persistence in iframe - README.md
Last active October 21, 2020 22:14
Test GA CID persistence in iframe
View - Test GA CID persistence in iframe - README.md

Test

  1. (optional) Edit code to have custom domain
  2. Paste code into console on any page
  3. Select iframe in console, and paste same code.
  4. Click reload in iframe, and repeat step 3.

Fix

@smhmic
smhmic / ( USAGE ).sh
Created March 21, 2018 19:06
Create new BitBucket repo
View ( USAGE ).sh
# Create an OAuth consumer with write access.
# For a callback URL, you can use: `https://www.google.com/`
# https://bitbucket.org/account/user/USERNAME/oauth-consumers/new
# Optional: Hardcode username, client key, and client secret into script.
# (but be aware of the danger of hardcoding credentials into any code!!)
# (if skipped, the script will securely prompt for info).
# Edit values
NEW_REPO_USER_OR_ORG="editme"