Skip to content

Instantly share code, notes, and snippets.

jsn789

Block or report user

Report or block jsn789

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jsn789
jsn789 / jQuery_click_listener_for_GTM.html
Last active May 28, 2019
jQuery Click Listener for Google Tag Manager replicating the "Click Element" and "Link Click" functionality within Google Tag Manager.
View jQuery_click_listener_for_GTM.html
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
/* jQuery is required for this script.
*/
/// load jQuery in no-conflict mode
jQuery.noConflict();
(function($) {
/// dom ready
$(function() {
$('body').on('click', function(e){
@jsn789
jsn789 / customTask_duplicateHits.js
Created May 16, 2019
customTask to duplicate hits for a specific domain
View customTask_duplicateHits.js
function() {
//Credit to Simo Ahava
//https://www.simoahava.com
var url = {{Page URL}}
if(url == "specific domain you are interested in")
{
// Replace newTrackingId value with the UA property to which you want to duplicate hits
var newTrackingId = 'UA-XXXXX-Y';
var globalSendTaskName = '_' + newTrackingId + '_originalSendTask';
return function(customModel) {
@jsn789
jsn789 / dataLayerHistory.js
Created Nov 24, 2018 — forked from sahava/dataLayerHistory.js
JavaScript for persisting dataLayer array and data model composition across pages
View dataLayerHistory.js
(function() {
// Set the timeout for when the dataLayer history should be purged. The default is 30 minutes.
// The timeout needs to be in milliseconds.
var timeout = 30*60*1000;
// Change dataLayerName only if you've defined another named for the dataLayer array in your
// GTM container snippet.
var dataLayerName = 'dataLayer';
// Don't change anything below.
@jsn789
jsn789 / shrink-nav-x.css
Last active Apr 14, 2018
Shrink navigation for X Theme
View shrink-nav-x.css
/*SHRINKING HEADER*/
@media (min-width: 980px) {
.x-navbar .x-navbar-inner,
.x-navbar .x-brand img,
.x-navbar .desktop .x-nav > li > a {
transition: 0.25s all linear;
}
.x-navbar.navScroll .x-navbar-inner {
min-height: 50px;
transition: 0.25s all linear;
@jsn789
jsn789 / page-document-window-height-ratio.js
Created Apr 11, 2018
GTM Custom JavaScript Variable For Scroll Tracking - Get Page Height
View page-document-window-height-ratio.js
//Use as Event Action
function(){
pageHeight = 'Not Set',
//the height of the browser window's viewport - alternative is window.innerHeight
//https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
windowHeight = window.innerHeight
//the height of the document object. In most cases, this is equal to the <body> element of the document
@jsn789
jsn789 / add-gtm-wp.php
Last active Dec 20, 2018
Add Google Tag Manager through functions.php in WordPress
View add-gtm-wp.php
/* Add Google Tag Manager javascript code as close to
the opening <head> tag as possible
=====================================================*/
function add_gtm_head(){
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
@jsn789
jsn789 / get-hit-timestamp.js
Last active Apr 9, 2018
GTM Custom JavaScript - Hit Timestamp used for a Custom Dimension
View get-hit-timestamp.js
function() {
// Get local time as ISO string with offset at the end
var now = new Date();
var tzo = -now.getTimezoneOffset();
var dif = tzo >= 0 ? '+' : '-';
var pad = function(num) {
var norm = Math.abs(Math.floor(num));
return (norm < 10 ? '0' : '') + norm;
};
return now.getFullYear()
@jsn789
jsn789 / set-clientid.js
Last active Apr 9, 2018
GTM Custom JavaScript - Set Client ID in a Custom Dimension. Used as a {{Variable}} in a customTask
View set-clientid.js
function () {
return function () {
try {
// Retrieve all trackers
var trackers = ga.getAll();
trackers.forEach(function(tracker) {
// Get the Client ID
var cid = tracker.get('clientId');
// Set the Client ID in a custom dimension
tracker.set('dimension1', cid); //change dimension number here
@jsn789
jsn789 / pdf-name-cleaner.js
Last active Apr 9, 2018
GTM Custom JavaScript - Cleans up downloaded PDF file name. Used for GA Events Label
View pdf-name-cleaner.js
function() {
// Example url: https://website.com/2015/10/File-Name.pdf
return {{Clicks - URL Path}}.split("/").slice(-1).join().split(".").shift();
// Returns: File-Name
}
@jsn789
jsn789 / non-Interaction-determinant.js
Last active Apr 11, 2018
GTM Custom JavaScript Variable For Scroll Tracking - non-Interaction logic
View non-Interaction-determinant.js
//Use as a variable in the "Non-interaction Hit" field of the Event Tag
function(){
nonInteraction = 'Not Set'
//the height of the browser window's viewport
//https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
windowHeight = window.innerHeight
//the height of the document object. In most cases, this is equal to the <body> element of the document
You can’t perform that action at this time.