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

Function FbTracking

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

Source from the content-addressed store, hash-verified

51};
52
53const FbTracking = ({ userId, consent, email }: PixelProps): ReactElement => {
54 useEffect(() => {
55 if (typeof globalThis.fbq === 'function') {
56 globalThis.fbq('consent', consent ? 'grant' : 'revoke');
57 }
58 }, [consent]);
59
60 useEffect(() => {
61 let isCurrent = true;
62
63 hashEmailForMeta(email).then((emailHash) => {
64 if (isCurrent && typeof globalThis.updateFbUserData === 'function') {
65 globalThis.updateFbUserData(userId, emailHash);
66 }
67 });
68
69 return () => {
70 isCurrent = false;
71 };
72 }, [email, userId]);
73
74 return (
75 <>
76 <Script
77 id="fb-pixel"
78 strategy="afterInteractive"
79 data-pixel-id={FB_PIXEL_ID}
80 data-user-id={userId}
81 data-email={email}
82 data-consent={consent}
83 >
84 {`
85 (function() {
86 const PIXEL_ID = document.currentScript.getAttribute('data-pixel-id');
87 const userId = document.currentScript.getAttribute('data-user-id');
88 const email = document.currentScript.getAttribute('data-email');
89 const consent = document.currentScript.getAttribute('data-consent');
90
91 const queryString = window.location.search;
92 const urlParams = new URLSearchParams(queryString);
93 const anonId = urlParams.get('fb_anon_id');
94
95 function initializeFacebookPixel(f, b, e, v, n, t, s) {
96 if (f.fbq) return;
97 n = f.fbq = function() {
98 n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
99 };
100 if (!f._fbq) f._fbq = n;
101 n.push = n;
102 n.loaded = !0;
103 n.version = '2.0';
104 n.queue = [];
105 t = b.createElement(e);
106 t.async = !0;
107 t.src = v;
108 s = b.getElementsByTagName(e)[0];
109 s.parentNode.insertBefore(t, s);
110 }

Callers

nothing calls this directly

Calls 1

hashEmailForMetaFunction · 0.85

Tested by

no test coverage detected