Last active
April 12, 2025 01:15
-
-
Save thyngster/05d771b2eb15aa672a9e65bf99308448 to your computer and use it in GitHub Desktop.
Monitor GA Client ID
This file contains hidden or 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() { | |
let ga_cid = document.cookie | |
.split('; ') | |
.find(row => row.startsWith('_ga=')) | |
?.split('=')[1]; | |
// Listen for changes in the cookie store | |
cookieStore.addEventListener('change', (e) => { | |
e.changed.forEach(c => { | |
if (c.name.startsWith('_ga')) { | |
if (c.value !== ga_cid) { | |
ga_cid = c.value; // Update stored client ID | |
window.dataLayer.push({ | |
event: 'ga_client_id_changed' | |
}); | |
console.log(`Changed: ${c.name} = ${c.value}`); | |
} | |
} | |
}); | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment