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