({
userId,
instanceId,
consent,
}: PixelProps)
| 153 | }; |
| 154 | |
| 155 | const GtagTracking = ({ |
| 156 | userId, |
| 157 | instanceId, |
| 158 | consent, |
| 159 | }: PixelProps): ReactElement => { |
| 160 | useEffect(() => { |
| 161 | if (typeof globalThis.gtag === 'function') { |
| 162 | globalThis.gtag('consent', 'update', { |
| 163 | ad_storage: consent ? 'granted' : 'denied', |
| 164 | analytics_storage: consent ? 'granted' : 'denied', |
| 165 | functionality_storage: consent ? 'granted' : 'denied', |
| 166 | personalization_storage: consent ? 'granted' : 'denied', |
| 167 | ad_user_data: consent ? 'granted' : 'denied', |
| 168 | ad_personalization: consent ? 'granted' : 'denied', |
| 169 | }); |
| 170 | } |
| 171 | }, [consent]); |
| 172 | |
| 173 | return ( |
| 174 | <> |
| 175 | <Script |
| 176 | strategy="afterInteractive" |
| 177 | src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`} |
| 178 | /> |
| 179 | <Script |
| 180 | id="ga-script" |
| 181 | strategy="afterInteractive" |
| 182 | data-ga-id={GA_TRACKING_ID} |
| 183 | data-user-id={userId} |
| 184 | data-instance-id={instanceId} |
| 185 | data-consent={consent} |
| 186 | > |
| 187 | {` |
| 188 | (function() { |
| 189 | const GA_ID = document.currentScript.getAttribute('data-ga-id'); |
| 190 | const consent = document.currentScript.getAttribute('data-consent'); |
| 191 | |
| 192 | window.dataLayer = window.dataLayer || []; |
| 193 | |
| 194 | window.gtag = window.gtag || function gtag() { |
| 195 | dataLayer.push(arguments); |
| 196 | }; |
| 197 | |
| 198 | gtag('consent', 'default', { |
| 199 | 'ad_storage': consent ? 'granted' : 'denied', |
| 200 | 'analytics_storage': consent ? 'granted' : 'denied', |
| 201 | 'functionality_storage': consent ? 'granted' : 'denied', |
| 202 | 'personalization_storage': consent ? 'granted' : 'denied', |
| 203 | 'ad_user_data': consent ? 'granted' : 'denied', |
| 204 | 'ad_personalization': consent ? 'granted' : 'denied', |
| 205 | }); |
| 206 | |
| 207 | gtag('js', new Date()); |
| 208 | gtag('config', GA_ID); |
| 209 | })(); |
| 210 | `} |
| 211 | </Script> |
| 212 | </> |
nothing calls this directly
no outgoing calls
no test coverage detected