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

Function FbTracking

packages/webapp/components/Pixels.tsx:31–120  ·  view source on GitHub ↗
({ userId, consent, email }: PixelProps)

Source from the content-addressed store, hash-verified

29};
30
31const FbTracking = ({ userId, consent, email }: PixelProps): ReactElement => {
32 useEffect(() => {
33 if (typeof globalThis.fbq === 'function') {
34 globalThis.fbq('consent', consent ? 'grant' : 'revoke');
35 }
36 }, [consent]);
37
38 useEffect(() => {
39 if (typeof globalThis.updateFbUserData === 'function') {
40 globalThis.updateFbUserData(userId, email);
41 }
42 }, [email, userId]);
43
44 return (
45 <>
46 <Script
47 id="fb-pixel"
48 strategy="afterInteractive"
49 data-pixel-id={FB_PIXEL_ID}
50 data-user-id={userId}
51 data-email={email}
52 data-consent={consent}
53 >
54 {`
55 (function() {
56 const PIXEL_ID = document.currentScript.getAttribute('data-pixel-id');
57 const userId = document.currentScript.getAttribute('data-user-id');
58 const email = document.currentScript.getAttribute('data-email');
59 const consent = document.currentScript.getAttribute('data-consent');
60
61 const queryString = window.location.search;
62 const urlParams = new URLSearchParams(queryString);
63 const anonId = urlParams.get('fb_anon_id');
64
65 function initializeFacebookPixel(f, b, e, v, n, t, s) {
66 if (f.fbq) return;
67 n = f.fbq = function() {
68 n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
69 };
70 if (!f._fbq) f._fbq = n;
71 n.push = n;
72 n.loaded = !0;
73 n.version = '2.0';
74 n.queue = [];
75 t = b.createElement(e);
76 t.async = !0;
77 t.src = v;
78 s = b.getElementsByTagName(e)[0];
79 s.parentNode.insertBefore(t, s);
80 }
81
82 initializeFacebookPixel(
83 window,
84 document,
85 'script',
86 'https://connect.facebook.net/en_US/fbevents.js',
87 );
88

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected