Skip to content

Instantly share code, notes, and snippets.

@thyngster
thyngster / getGa4LinkerParam.js
Created September 15, 2022 21:42
Grab GA4 "linkerParam"
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];
@thyngster
thyngster / return_optimize_containers.js
Created September 26, 2023 15:56
check_optimize_containers
// 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)}`)
@thyngster
thyngster / privacy_sandbox_apis_check.js
Created February 27, 2024 21:18
Privacy Sandbox Relevance & Measurement APIs Check
// ----------------------------------------------------------------------
// 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,
@thyngster
thyngster / getLoadedGA4Containers.js
Last active May 2, 2024 12:39
Small function to check if any GA4 Container has been currently been loaded.
// 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-') })
}