Created
April 14, 2026 15:33
-
-
Save ceaksan/d17abac202fa820661d9d8451fa46d71 to your computer and use it in GitHub Desktop.
DNM Attribution: Browser console debug script — Displays dnm_src/dnm_cid cookie status, dataLayer push history, and test URL examples. Paste in console or append ?dnm_debug=1 to any page.
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
| /** | |
| * DNM Attribution — Browser console debug script | |
| * File: dnm-debug.js | |
| * | |
| * Usage: | |
| * 1. Open browser console (F12 → Console) | |
| * 2. Paste this script and run it | |
| * 3. Or append ?dnm_debug=1 to any URL (purchase enrichment logs automatically) | |
| * | |
| * Test scenario URLs: | |
| * Google Ads: https://example.com/?gclid=Cj0KCQjwTest123 | |
| * Facebook: https://example.com/?fbclid=Ab12TestFb&utm_source=facebook&utm_medium=paid_social&utm_campaign=TR_retargeting | |
| * UTM manual: https://example.com/?utm_source=newsletter&utm_medium=email&utm_campaign=april_campaign | |
| */ | |
| (function dnmDebug() { | |
| /* --- Cookie reader --------------------------------------------- */ | |
| function getCookie(name) { | |
| var match = document.cookie.match( | |
| new RegExp("(?:^|; )" + name + "=([^;]*)"), | |
| ); | |
| return match ? decodeURIComponent(match[1]) : null; | |
| } | |
| /* --- Display current cookies ----------------------------------- */ | |
| var rawSrc = getCookie("dnm_src"); | |
| var rawCid = getCookie("dnm_cid"); | |
| console.group( | |
| "%c[DNM] Attribution cookie status", | |
| "color:#6c5ce7;font-weight:bold", | |
| ); | |
| if (!rawSrc) { | |
| console.warn( | |
| "dnm_src cookie not found. Landing script has not run yet or cookie has been cleared.", | |
| ); | |
| } else { | |
| var parts = rawSrc.split("|"); | |
| console.log("%cdnm_src", "color:#00b894;font-weight:bold", rawSrc); | |
| console.table({ | |
| source: parts[0] || "—", | |
| medium: parts[1] || "—", | |
| campaign: parts[2] || "—", | |
| content: parts[3] || "—", | |
| term: parts[4] || "—", | |
| }); | |
| } | |
| if (!rawCid) { | |
| console.info("dnm_cid cookie not found (expected for non-paid traffic)"); | |
| } else { | |
| var cidParts = rawCid.split(":"); | |
| console.log("%cdnm_cid", "color:#0984e3;font-weight:bold", rawCid); | |
| console.table({ | |
| type: cidParts[0] || "—", | |
| value: cidParts.slice(1).join(":") || "—", // safe parse in case value contains ':' | |
| }); | |
| } | |
| console.groupEnd(); | |
| /* --- Show recent dataLayer pushes ------------------------------ */ | |
| var dl = window.dataLayer || []; | |
| var dnmEvents = dl.filter(function (e) { | |
| return ( | |
| e.event === "dnm_source_captured" || e.event === "dnm_purchase_enriched" | |
| ); | |
| }); | |
| if (dnmEvents.length) { | |
| console.group( | |
| "%c[DNM] DataLayer push history", | |
| "color:#e17055;font-weight:bold", | |
| ); | |
| dnmEvents.forEach(function (e) { | |
| console.log(e); | |
| }); | |
| console.groupEnd(); | |
| } | |
| /* --- Print test URLs ------------------------------------------- */ | |
| console.group("%c[DNM] Test URL examples", "color:#fdcb6e;font-weight:bold"); | |
| console.log( | |
| "Google Ads → " + window.location.origin + "/?gclid=TEST_GCLID_123", | |
| ); | |
| console.log( | |
| "Facebook → " + | |
| window.location.origin + | |
| "/?fbclid=TEST_FBCLID_456&utm_source=facebook&utm_medium=paid_social&utm_campaign=test", | |
| ); | |
| console.log( | |
| "Email → " + | |
| window.location.origin + | |
| "/?utm_source=newsletter&utm_medium=email&utm_campaign=april", | |
| ); | |
| console.log("Debug mode → append ?dnm_debug=1 to any page"); | |
| console.groupEnd(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment