Skip to content

Instantly share code, notes, and snippets.

/*!
* Spam Referrals Buster
*
* author: David Vallejo (@thyng)
* version: 0.2 Beta
* date: 2015-07-19
*
* @link https://www.thyngster.com
*/
@thyngster
thyngster / GTMDebugOff.js
Created August 24, 2015 14:14
GTM Debug Disabler
document.querySelector('iframe[src*="about"]').contentWindow.angular.element(document.querySelector('iframe[src*="about"]').contentWindow.document.querySelector('[ng-app]')).injector().get("$log").debug = function(){};
@thyngster
thyngster / dlobserver.js
Created November 27, 2015 16:22
dataLayer Object Observer
// Simple dataLayer object observer for Chrome +36
// David Vallejo (@thyng)
// 2014
Object.observe(dataLayer,function(e){for(i=0;i<e.length;i++)"add"==e[i].type&&console.table([e[i].object[e[i].object.length-1]])});
@thyngster
thyngster / get_root_domain.js
Created November 27, 2016 20:24
Grab top domain name based on cookie write testing
var getRootDomain = function(domain=document.location.host){
var rootDomain = null;
if (domain.substring(0,4)=="www.") {
domain=domain.substring(4,domain.length);
}
var domParts = domain.split('.');
for(var i=1;i<=domParts.length;i++)
{
document.cookie="testcookie=1; path=/; domain="+domParts.slice(i*-1).join('.');
if(document.cookie.indexOf("testcookie") != -1){
@thyngster
thyngster / object_to_json
Created January 18, 2018 13:40
Exports object as JSON string keeping undefined values
JSON.stringify(obj, function (k, v) {
return (v === undefined) ? "undefined" : v
}).replace(/\"undefined\"/g,undefined);
if (window.fetch)
fetch('https://www.google-analytics.com/collect').then(function(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}).then(function(response) {}).catch(function(error) {
window.dataLayer.push({
'event': 'ga-blocked'
});
@thyngster
thyngster / gtm-debug-ui-macro-parser.js
Last active October 28, 2019 13:49
Small Snippet to parse Macros on GTM Debug Interface
// Small Snippet to Parse GTM Macros on GTM Debug Interface
// Idea From Simo's Post: #GTMTips: The Mysterious .macro() Call In Custom HTML Tags
// URL: https://www.simoahava.com/gtm-tips/mysterious-macro-call-custom-html-tags/
// Current Version, does not take care of current variable type, all is replaces as str.
(function() {
const iframe = document.querySelector('iframe[src="about:blank"]');
iframe.contentDocument.querySelectorAll('.CodeMirror-code').forEach(function(e) {
if (e.querySelectorAll('.CodeMirror-line').length > 0) {
let _code = [...e.querySelectorAll('pre.CodeMirror-line')].map(function(e) {
@thyngster
thyngster / gtm_share_button.js
Last active October 19, 2020 12:46
Enable Share Preview Button . New GTM Preview
(function() {
document.querySelector('.domain-dialog__start-button button').insertAdjacentHTML('afterend', `<button id="share-preview-link" class="btn btn--create" > Share Preview </button>`);
document.querySelector('#share-preview-link').addEventListener("click", function() {
const dummy = document.createElement('p');
dummy.textContent = window.location.href;
document.body.appendChild(dummy);
const range = document.createRange();
range.setStartBefore(dummy);
range.setEndAfter(dummy);
const selection = window.getSelection();
@thyngster
thyngster / cloudflare_analytics_gtm_compliant_snippet.js
Created December 3, 2020 21:41
CloudFlare Analytics Snippet for GTM
<!-- Cloudflare Web Analytics -->
<script>
(function(){
var s,
r,
t;
r = false;
s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'https://static.cloudflareinsights.com/beacon.min.js';
@thyngster
thyngster / GA4_eventTimeRemap.js
Last active September 20, 2021 17:55
Remap Events Event Time Parameter as an Event Parameter
(function() {
/*
*
* ( David Vallejo @thyng )
* MIT License
* Remap _et ( Event Time ) as a customEvent Perameter
*
*/
try {
// Monkey Patch, sendBeacon