Skip to content

Instantly share code, notes, and snippets.

@thyngster
Last active April 12, 2025 01:15
Show Gist options
  • Save thyngster/05d771b2eb15aa672a9e65bf99308448 to your computer and use it in GitHub Desktop.
Save thyngster/05d771b2eb15aa672a9e65bf99308448 to your computer and use it in GitHub Desktop.
Monitor GA Client ID
(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