Patch GrowthBook and set feature callback
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
diff --git a/node_modules/@growthbook/growthbook/dist/GrowthBook.d.ts b/node_modules/@growthbook/growthbook/dist/GrowthBook.d.ts
|
||||||
|
index ec532b0..d96a5f1 100644
|
||||||
|
--- a/node_modules/@growthbook/growthbook/dist/GrowthBook.d.ts
|
||||||
|
+++ b/node_modules/@growthbook/growthbook/dist/GrowthBook.d.ts
|
||||||
|
@@ -1,4 +1,4 @@
|
||||||
|
-import type { ApiHost, Attributes, AutoExperiment, AutoExperimentVariation, ClientKey, Options, Experiment, FeatureApiResponse, FeatureDefinition, FeatureResult, LoadFeaturesOptions, RefreshFeaturesOptions, RenderFunction, Result, SubscriptionFunction, TrackingCallback, TrackingData, WidenPrimitives, InitOptions, InitResponse, InitSyncOptions, PrefetchOptions, StickyAssignmentsDocument, EventLogger, LogUnion, DestroyOptions } from "./types/growthbook";
|
||||||
|
+import type { ApiHost, Attributes, AutoExperiment, AutoExperimentVariation, ClientKey, Options, Experiment, FeatureApiResponse, FeatureDefinition, FeatureResult, FeatureUsageCallback, LoadFeaturesOptions, RefreshFeaturesOptions, RenderFunction, Result, SubscriptionFunction, TrackingCallback, TrackingData, WidenPrimitives, InitOptions, InitResponse, InitSyncOptions, PrefetchOptions, StickyAssignmentsDocument, EventLogger, LogUnion, DestroyOptions } from "./types/growthbook";
|
||||||
|
import { StickyBucketServiceSync } from "./sticky-bucket-service";
|
||||||
|
export declare class GrowthBook<AppFeatures extends Record<string, any> = Record<string, any>> {
|
||||||
|
private context;
|
||||||
|
@@ -106,6 +106,7 @@ export declare class GrowthBook<AppFeatures extends Record<string, any> = Record
|
||||||
|
setDeferredTrackingCalls(calls: TrackingData[]): void;
|
||||||
|
fireDeferredTrackingCalls(): Promise<void>;
|
||||||
|
setTrackingCallback(callback: TrackingCallback): void;
|
||||||
|
+ setFeatureUsageCallback(callback: FeatureUsageCallback): void;
|
||||||
|
setEventLogger(logger: EventLogger): void;
|
||||||
|
logEvent(eventName: string, properties?: Record<string, unknown>): Promise<void>;
|
||||||
|
private _saveDeferredTrack;
|
||||||
|
diff --git a/node_modules/@growthbook/growthbook/dist/esm/GrowthBook.mjs b/node_modules/@growthbook/growthbook/dist/esm/GrowthBook.mjs
|
||||||
|
index e0847f0..4bcc20f 100644
|
||||||
|
--- a/node_modules/@growthbook/growthbook/dist/esm/GrowthBook.mjs
|
||||||
|
+++ b/node_modules/@growthbook/growthbook/dist/esm/GrowthBook.mjs
|
||||||
|
@@ -682,6 +682,9 @@ export class GrowthBook {
|
||||||
|
this._options.trackingCallback = callback;
|
||||||
|
this.fireDeferredTrackingCalls();
|
||||||
|
}
|
||||||
|
+ setFeatureUsageCallback(callback) {
|
||||||
|
+ this._options.onFeatureUsage = callback;
|
||||||
|
+ }
|
||||||
|
setEventLogger(logger) {
|
||||||
|
this._options.eventLogger = logger;
|
||||||
|
}
|
||||||
|
diff --git a/node_modules/@growthbook/growthbook/src/GrowthBook.ts b/node_modules/@growthbook/growthbook/src/GrowthBook.ts
|
||||||
|
index 907fc97..e59201c 100644
|
||||||
|
--- a/node_modules/@growthbook/growthbook/src/GrowthBook.ts
|
||||||
|
+++ b/node_modules/@growthbook/growthbook/src/GrowthBook.ts
|
||||||
|
@@ -16,6 +16,7 @@ import type {
|
||||||
|
Result,
|
||||||
|
SubscriptionFunction,
|
||||||
|
TrackingCallback,
|
||||||
|
+ FeatureUsageCallback,
|
||||||
|
TrackingData,
|
||||||
|
WidenPrimitives,
|
||||||
|
EvalContext,
|
||||||
|
@@ -952,6 +953,10 @@ export class GrowthBook<
|
||||||
|
this.fireDeferredTrackingCalls();
|
||||||
|
}
|
||||||
|
|
||||||
|
+ public setFeatureUsageCallback(callback: FeatureUsageCallback) {
|
||||||
|
+ this._options.onFeatureUsage = callback;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
public setEventLogger(logger: EventLogger) {
|
||||||
|
this._options.eventLogger = logger;
|
||||||
|
}
|
||||||
+17
-12
@@ -1,4 +1,4 @@
|
|||||||
import {createContext, useContext, useEffect, useMemo} from 'react'
|
import {createContext, useContext, useMemo} from 'react'
|
||||||
import {Platform} from 'react-native'
|
import {Platform} from 'react-native'
|
||||||
|
|
||||||
import {Logger} from '#/logger'
|
import {Logger} from '#/logger'
|
||||||
@@ -181,20 +181,25 @@ export function AnalyticsFeaturesContext({
|
|||||||
const parentContext = useContext(Context)
|
const parentContext = useContext(Context)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Side-effect: we need to synchronously set this during the
|
* Side-effects: we need to synchronously set these during the same render
|
||||||
* same render cycle. It does not trigger a re-render, it just
|
* cycle. These calls do not trigger re-renders, they just set properties on
|
||||||
* sets properties on the singleton GrowthBook instance.
|
* the singleton GrowthBook instance.
|
||||||
*/
|
*/
|
||||||
setAttributes(parentContext.metadata)
|
setAttributes(parentContext.metadata)
|
||||||
|
feats.setTrackingCallback((experiment, result) => {
|
||||||
useEffect(() => {
|
parentContext.metric('experiment:viewed', {
|
||||||
feats.setTrackingCallback((experiment, result) => {
|
experimentId: experiment.key,
|
||||||
parentContext.metric('experiment:viewed', {
|
variationId: result.key,
|
||||||
experimentId: experiment.key,
|
|
||||||
variationId: result.key,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}, [parentContext.metric])
|
})
|
||||||
|
feats.setFeatureUsageCallback((feature, result) => {
|
||||||
|
parentContext.metric('feature:viewed', {
|
||||||
|
featureId: feature,
|
||||||
|
featureResultValue: result.value,
|
||||||
|
experimentId: result.experiment?.key,
|
||||||
|
variationId: result.experimentResult?.key,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const childContext = useMemo<AnalyticsContextType>(() => {
|
const childContext = useMemo<AnalyticsContextType>(() => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ export type Events = {
|
|||||||
experimentId: string
|
experimentId: string
|
||||||
variationId: string
|
variationId: string
|
||||||
}
|
}
|
||||||
|
'feature:viewed': {
|
||||||
|
featureId: string
|
||||||
|
featureResultValue: unknown
|
||||||
|
/** Only available if feature has experiment rules applied */
|
||||||
|
experimentId?: string
|
||||||
|
/** Only available if feature has experiment rules applied */
|
||||||
|
variationId?: string
|
||||||
|
}
|
||||||
|
|
||||||
'account:loggedIn': {
|
'account:loggedIn': {
|
||||||
logContext:
|
logContext:
|
||||||
|
|||||||
Reference in New Issue
Block a user