diff --git a/src/content_script/embed_script.ts b/src/content_script/embed_script.ts index 282e7e1..95751b9 100644 --- a/src/content_script/embed_script.ts +++ b/src/content_script/embed_script.ts @@ -7,10 +7,19 @@ import type { Options, Result, TrackingCallback, + TrackingData, + UserContext, } from "@growthbook/growthbook"; import type { ErrorMessage, SDKHealthCheckResult } from "devtools"; import { Attributes } from "@growthbook/growthbook"; + +type TrackingCallbackWithUser = ( + experiment: Experiment, + result: Result, + user?: UserContext, +) => void; + type LogUnionWithSource = LogUnion & { source?: string; clientKey?: string }; type StateObj = { @@ -458,6 +467,7 @@ function subscribeToSdkChanges( const patchedCallBack = ( experiment: Experiment, result: Result, + user?: UserContext, ) => { if (!hasSdkLogSupport) { gb.logs!.push({ @@ -470,10 +480,10 @@ function subscribeToSdkChanges( if ("isNoopCallback" in callback && callback.isNoopCallback) { gb.setDeferredTrackingCalls?.([ ...gb.getDeferredTrackingCalls(), - { experiment, result }, + { experiment, result, user } as TrackingData, ]); } - callback(experiment, result); + (callback as TrackingCallbackWithUser)(experiment, result, user); }; if ("isNoopCallback" in callback && callback.isNoopCallback) { patchedCallBack.isNoopCallback = true;