MCPcopy Create free account
hub / github.com/dailydotdev/apps / GtagTracking

Function GtagTracking

packages/webapp/components/Pixels.tsx:161–220  ·  view source on GitHub ↗
({
  userId,
  instanceId,
  consent,
}: PixelProps)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected