Skip to content

Instantly share code, notes, and snippets.

@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' );
@smhmic
smhmic / . pfx_wp_email_config (simple WordPress email config).php
Last active April 25, 2016 21:44
Configure WordPress built-in email system (phpmail) to send mail using an SMTP account (like Gmail, Yahoo, etc).
<?php
/**
* Configure WP's PHP mailer to send emails from a SMTP account.
* Intended to be used as callback for action `phpmailer_init`.
* @see https://codex.wordpress.org/Plugin_API/Action_Reference/phpmailer_init
* @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference.
* @version 0.2.1
*/
function pfx_wp_email_config( $phpmailer ){
@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 / - USAGE.php
Last active March 14, 2016 13:15
HTML-only social share buttons generator w/ utm auto-tagging and bitly shortening
<?php
seer_html_social_share_links( array(
'url' => THE URL TO SHARE, // The URL to share
'text' => '', // Default share text
'image' => IMAGE URL, // URL of the image for the share
//'text_before' => '', // The text to show before the buttons
//'text_after' => '', // The text to show after the buttons
'class' => '', // HTML wrapper class(es)
'_use_the_post' => false, // If true, uses Wordpress functions to populate default options
@smhmic
smhmic / gtm.user.css
Last active January 31, 2017 14:20
GTM admin userstyles
/**### General - Full-Width Content ###*/
.gtm-container-page-content-wrapper {
max-width: none;
}
/** fix width of folder select box column **/
.gtm-folder-card col[width="4%"]:nth-of-type(1) { width: 2.5% !important }
@smhmic
smhmic / the.js
Last active July 28, 2017 19:46
Javascript HEREDOC (and simple method for injecting CSS as style block)
/** Created by stephen on 3/12/15. */
'use strict';
/**
* Convenience function for hardocding multiline strings, without needing use explicit "\n" and concatenate lines.
* @param {function} fn - A function with a block comment as it's entire definition. Will not be executed.
* @return {string} The contents of the block comment in the definition of @param fn.
*/
function HEREDOC( fn ){
return fn.toString().match( /\/\*[\n\l]?([\s\S]*?)\*\//m )[1];
function(){
var k, timestamp;
timestamp = google_tag_manager[{{Container ID}}].dataLayer.get('gtm.start');
for( k in window ){
if( window[k] && window[k][0] && timestamp === window[k][0]['gtm.start'] ){
return k;
}
}
}