Skip to content

Instantly share code, notes, and snippets.

@smhmic
smhmic / ( USAGE ).sh
Created March 21, 2018 19:06
Create new BitBucket repo
# 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"
@smhmic
smhmic / GA Management - list recent views (paste in GA UI console).js
Last active November 20, 2017 20:48
GA Management - get list of recent accounts/properties/views (paste in GA UI console)
(function(){
var aI, pI, vI, a, p, v, rows = [], row;
for( aI = 0; aI<window.preload.accounts.length; aI++ ){
row = [];
a = window.preload.accounts[aI];
for( pI = 0; pI<a.wprops.length; pI++ ){
@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 / 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 / - 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 / Event-less Data Layer Push Listener.html
Last active May 5, 2016 17:34
Lets you use data layer pushes with no 'event' for a GTM Trigger.
<script>
/**
* Data layer pushes should always have an event (even in simple <head> snippets).
* But if you're dealing with an event-less push upon which you need to be able
* to fire a Trigger, and you cannot change the push snippet, this code will
* let you detect the push and add an event dynamically.
*
* Tested in Chrome, Firefox, and IE9.
*/
(function(){
@smhmic
smhmic / GA Cross-Library Cross-Domain Tracking (simple).html
Last active December 5, 2017 08:32
This is for a site on UA, that needs to track sessions across some digital assets/platforms that are stuck on legacy versions of GA. This only works for traffic clicking from the UA site to the asset. (But after clicking from UA > Asset once, all subsequent Asset > UA clicks do not need cross-domain tracking and will not break the session).
<script>
/**
* This script facilitates cross-domain tracking when one site is runs
* GA Universal and another runs legacy GA (Traditional or Async/Classic).
*
* This integration currently unilateral, working only for users
* navigating from Universal > Legacy. For example: if a user clicks
* on a paid ad and lands directly on your asset/platform (legacy),
* then goes to your main site (UA), then clicks back to your asset/platform
* and converts, it will be tracked as two users: one that bounced from a
@smhmic
smhmic / . pfxwp_nav_option_auto_add_subpages.php
Last active April 25, 2016 21:58
Add an option for nav menus for new child pages of contained parent pages to be automatically added as sub items under that page in the nav.
<?php
//
// ADD OPTION IN wp-admin/nav-menus.php
//
#\pfxwp\hook::add_filter_after( 'pre_option_nav_menu_options', 'gettext', 'pfxwp_nav_option_auto_add_subpages' );
add_filter( 'pre_option_nav_menu_options', 'pfxwp_nav_option_hook' );