Skip to content

Commit 46ed00b

Browse files
author
ghost
committed
added consent to lead submission event and reddit event as well
1 parent 5eac4c7 commit 46ed00b

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

thank-you.html

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,56 @@
8585
<link rel="shortcut icon" href="favicon.ico">
8686
<link rel="manifest" href="site.webmanifest">
8787

88-
<!-- Google tag (gtag.js) -->
89-
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-18022556253"></script>
9088
<script>
91-
window.dataLayer = window.dataLayer || [];
92-
function gtag() { dataLayer.push(arguments); }
93-
gtag('js', new Date());
89+
function hasConsent() {
90+
try {
91+
const CONSENT_KEY = 'mousaConsentV1';
92+
const raw = localStorage.getItem(CONSENT_KEY);
93+
if (!raw) return false;
94+
const c = JSON.parse(raw);
95+
return c && c.accepted === true;
96+
} catch (e) {
97+
return false;
98+
}
99+
}
94100

95-
gtag('config', 'AW-18022556253');
96-
</script>
101+
function fireConversionEvents() {
102+
if (!hasConsent()) return;
103+
104+
if (typeof window.rdt === 'function') {
105+
try {
106+
window.rdt('track', 'Lead');
107+
} catch (e) {
108+
console.warn('reddit pixel error', e);
109+
}
110+
}
111+
112+
if (typeof window.gtag === 'function') {
113+
try {
114+
window.gtag('event', 'conversion_event_submit_lead_form_1');
115+
} catch (e) {
116+
console.warn('gtag error', e);
117+
}
118+
}
119+
}
97120

121+
function waitForTrackers(attempts = 20) {
122+
if (!hasConsent()) return;
98123

124+
const googleReady = typeof window.gtag === 'function';
125+
const redditReady = typeof window.rdt === 'function';
99126

100-
<!-- Google tag (gtag.js) event -->
101-
<script>
102-
gtag('event', 'conversion_event_submit_lead_form_1', {
103-
// <event_parameters>
104-
});
127+
if (googleReady || redditReady) {
128+
fireConversionEvents();
129+
return;
130+
}
131+
132+
if (attempts > 0) {
133+
setTimeout(() => waitForTrackers(attempts - 1), 250);
134+
}
135+
}
136+
137+
window.addEventListener('load', () => waitForTrackers());
105138
</script>
106139

107140
</head>

0 commit comments

Comments
 (0)