Skip to content

Instantly share code, notes, and snippets.

@smhmic
smhmic / console.js
Created February 27, 2024 00:00
Show filtered data layer as table
console.table(dataLayer.filter(v=>v.event=="eventTracking"),['label','action','value'])
@smhmic
smhmic / - G Apps Script - Open URL .md
Last active June 15, 2023 23:52
Google Apps Script - Open a URL in a new tab (such as directly from clicking a menu item, w/o further user interaction).

Open a URL using Google Apps Script without requiring additional user interaction.

Code also on StackOverflow.

@smhmic
smhmic / view gtm data layer state .js
Last active May 4, 2023 16:04
Paste into console to view current gtm data layer state
/*
SIMPLEST USAGE:
Copy all this code and paste it in the console to see all the data layer's available data
in different formats, and learn about the data layer queue vs data layer state.
USAGE:
// See data layer state as nested objects.
datalayerGetAll( dataLayer );
@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)

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 / hyperlink_list.gas.js
Created March 17, 2023 02:43
G Apps Script - hyperlink list / multiple hyperlists in gsheet cell
@smhmic
smhmic / Listener - YouTube .gtm.tag.html
Last active November 8, 2022 15:52
Add YouTube JS API support for embedded YouTube videos
<script>(function(){
/*
This script is an alternative to the 'Add JavaScript API support to all YouTube videos'
setting in GTM's YT trigger. GTM's YT trigger will not load the YT API if no videos are
present at page load (it does add the enablejsapi param to dynanmically inserted videos,
but it will not load the YT API js). This script, on the other hand, should work in all cases.
*/
if( window.YT ) return;
@smhmic
smhmic / functions.php
Last active July 19, 2022 07:17 — forked from un1ko85/new_gist_file.php
wordpress - disable all rss and pingbacks and trackbacks on dev/staging sites
<?php
if( IS_DEV_SITE ) {
//Disable RSS Feeds functions
add_action('do_feed', array( $this, 'disabler_kill_rss' ), 1);
add_action('do_feed_rdf', array( $this, 'disabler_kill_rss' ), 1);
add_action('do_feed_rss', array( $this, 'disabler_kill_rss' ), 1);
add_action('do_feed_rss2', array( $this, 'disabler_kill_rss' ), 1);
add_action('do_feed_atom', array( $this, 'disabler_kill_rss' ), 1);
if(function_exists('disabler_kill_rss')) {
@smhmic
smhmic / - README - URL parameter blocklist OR allowlist in GTM.md
Last active May 17, 2022 14:31
URL parameter blocklist/allowlist in GTM.md
@smhmic
smhmic / onDomInsert.js
Created August 3, 2016 20:39
Listener for dynamically inserted DOM elements
/**
* @function onDomInsert - Listener for nodes inserted into DOM.
* Does NOT monitor when things are removed.
* Based on http://stackoverflow.com/a/14570614/445295
* @param [DOMNode] el - Optional. The element to listen on. Defaults to document.
* @param [Function] cb - Callback. Called with inserted element as only arg.
*/
var onDomInsert = (function(){
'use strict';
@smhmic
smhmic / - README - Hubspot refinement CSS & JS .md
Last active September 17, 2021 15:45
Hubspot refinement css/js