|
85 | 85 | <link rel="shortcut icon" href="favicon.ico"> |
86 | 86 | <link rel="manifest" href="site.webmanifest"> |
87 | 87 |
|
88 | | - <!-- Google tag (gtag.js) --> |
89 | | - <script async src="https://www.googletagmanager.com/gtag/js?id=AW-18022556253"></script> |
90 | 88 | <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 | + } |
94 | 100 |
|
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 | + } |
97 | 120 |
|
| 121 | + function waitForTrackers(attempts = 20) { |
| 122 | + if (!hasConsent()) return; |
98 | 123 |
|
| 124 | + const googleReady = typeof window.gtag === 'function'; |
| 125 | + const redditReady = typeof window.rdt === 'function'; |
99 | 126 |
|
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()); |
105 | 138 | </script> |
106 | 139 |
|
107 | 140 | </head> |
|
0 commit comments