()
| 26 | } |
| 27 | |
| 28 | export function ImpactIdentify() { |
| 29 | const { data: user } = useUser(); |
| 30 | |
| 31 | useEffect(() => { |
| 32 | let cancelled = false; |
| 33 | let retryTimeout: ReturnType<typeof setTimeout> | null = null; |
| 34 | |
| 35 | const runIdentify = async (retriesRemaining: number): Promise<void> => { |
| 36 | if (cancelled) return; |
| 37 | |
| 38 | if (typeof window.ire !== 'function') { |
| 39 | if (retriesRemaining <= 0) { |
| 40 | logImpactReferralDebug('Impact UTT identify skipped; window.ire unavailable', { |
| 41 | userId: user?.id ?? null, |
| 42 | }); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | retryTimeout = setTimeout(() => { |
| 47 | void runIdentify(retriesRemaining - 1); |
| 48 | }, 250); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | const customProfileId = user?.id ? `kilo-user:${user.id}` : getStableAnonymousProfileId(); |
| 53 | const customerId = user?.id ?? ''; |
| 54 | const customerEmail = user ? await sha1Hex(user.google_user_email) : ''; |
| 55 | |
| 56 | if (cancelled || typeof window.ire !== 'function') return; |
| 57 | |
| 58 | logImpactReferralDebug('Calling Impact UTT identify', { |
| 59 | userId: user?.id ?? null, |
| 60 | customerIdPresent: Boolean(customerId), |
| 61 | customerEmailHashPresent: Boolean(customerEmail), |
| 62 | customProfileIdPresent: Boolean(customProfileId), |
| 63 | }); |
| 64 | |
| 65 | window.ire('identify', { |
| 66 | customerId, |
| 67 | customerEmail, |
| 68 | customProfileId, |
| 69 | }); |
| 70 | }; |
| 71 | |
| 72 | void runIdentify(10).catch(error => { |
| 73 | console.error('ImpactIdentify failed', error); |
| 74 | }); |
| 75 | |
| 76 | return () => { |
| 77 | cancelled = true; |
| 78 | if (retryTimeout) { |
| 79 | clearTimeout(retryTimeout); |
| 80 | } |
| 81 | }; |
| 82 | }, [user?.google_user_email, user?.id]); |
| 83 | |
| 84 | return null; |
| 85 | } |
no test coverage detected