This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DV - 2022 - ES5 | |
// Check if GA4 has been loaded | |
var getLoadedGA4Containers = function() { | |
return Object.keys( | |
window.google_tag_data && | |
window.google_tag_data.tidr && | |
window.google_tag_data.tidr.container || {} | |
).filter(function(e){ return e.startsWith('G-') }) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------------------- | |
// Privacy Sandbox Relevance & Measurement APIs Check | |
// ---------------------------------------------------------------------- | |
const privacySandboxApisAvailability = { | |
topics: 'browsingTopics'in document ? true : false, | |
attributionReporting: document.featurePolicy.allowsFeature('attribution-reporting') ? true : false, | |
protectedAudience: 'runAdAuction'in navigator ? true : false, | |
fencedFrames: 'HTMLFencedFrameElement'in window ? true : false, | |
sharedStorage: 'sharedStorage'in window ? true : false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns a list of current Optimize Containers on a page | |
alert(`Found Optimize Containers: ${Object.keys(window.google_tag_manager || []).filter(e=> e.match(/^(GTM|OPT)/) && !window.google_tag_manager[e].onHtmlFailure)}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getGa4LinkerParam = function() { | |
try { | |
if (!window.google_tag_data || !window.google_tag_data.glBridge) | |
return; | |
var cookies = {}; | |
('; ' + document.cookie).split('; ').forEach(function(ck) { | |
var name = ck.split("=")[0]; | |
var value = ck.split("=")[1]; | |
if (name && value && name.match(/^_ga$|^_ga_[A-Z,0-9]/)) { | |
cookies[name] = value.match(/[A-Z,0-9]\.[0-9]\.(.*)/)[1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
/* | |
* | |
* ( David Vallejo @thyng ) | |
* MIT License | |
* Remap _et ( Event Time ) as a customEvent Perameter | |
* | |
*/ | |
try { | |
// Monkey Patch, sendBeacon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSON.stringify(obj, function (k, v) { | |
return (v === undefined) ? "undefined" : v | |
}).replace(/\"undefined\"/g,undefined); |
NewerOlder