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

Function GtagTracking

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

Source from the content-addressed store, hash-verified

120};
121
122const GtagTracking = ({
123 userId,
124 instanceId,
125 consent,
126}: PixelProps): ReactElement => {
127 useEffect(() => {
128 if (typeof globalThis.gtag === 'function') {
129 globalThis.gtag('consent', 'update', {
130 ad_storage: consent ? 'granted' : 'denied',
131 analytics_storage: consent ? 'granted' : 'denied',
132 functionality_storage: consent ? 'granted' : 'denied',
133 personalization_storage: consent ? 'granted' : 'denied',
134 ad_user_data: consent ? 'granted' : 'denied',
135 ad_personalization: consent ? 'granted' : 'denied',
136 });
137 }
138 }, [consent]);
139
140 return (
141 <>
142 <Script
143 strategy="afterInteractive"
144 src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
145 />
146 <Script
147 id="ga-script"
148 strategy="afterInteractive"
149 data-ga-id={GA_TRACKING_ID}
150 data-user-id={userId}
151 data-instance-id={instanceId}
152 data-consent={consent}
153 >
154 {`
155 (function() {
156 const GA_ID = document.currentScript.getAttribute('data-ga-id');
157 const consent = document.currentScript.getAttribute('data-consent');
158
159 window.dataLayer = window.dataLayer || [];
160
161 window.gtag = window.gtag || function gtag() {
162 dataLayer.push(arguments);
163 };
164
165 gtag('consent', 'default', {
166 'ad_storage': consent ? 'granted' : 'denied',
167 'analytics_storage': consent ? 'granted' : 'denied',
168 'functionality_storage': consent ? 'granted' : 'denied',
169 'personalization_storage': consent ? 'granted' : 'denied',
170 'ad_user_data': consent ? 'granted' : 'denied',
171 'ad_personalization': consent ? 'granted' : 'denied',
172 });
173
174 gtag('js', new Date());
175 gtag('config', GA_ID);
176})();
177 `}
178 </Script>
179 </>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected