diff --git a/src/analytics.ts b/src/analytics.ts index 246d0c8..6d5b722 100644 --- a/src/analytics.ts +++ b/src/analytics.ts @@ -85,6 +85,12 @@ export function createAnalyticsInstance(options?: Options) { ...(growthbookOptions?.attributes?.network_downlink && { network_downlink: growthbookOptions?.attributes.network_downlink, }), + ...(growthbookOptions?.attributes?.user_id && { + user_id: growthbookOptions?.attributes?.user_id, + }), + ...(growthbookOptions?.attributes?.anonymous_id && { + anonymous_id: growthbookOptions?.attributes?.anonymous_id || _rudderstack.getAnonymousId(), + }), } growthbookOptions ??= {} growthbookOptions.attributes ??= {} @@ -115,6 +121,7 @@ export function createAnalyticsInstance(options?: Options) { device_type, account_type, user_id, + anonymous_id, app_id, utm_source, utm_medium, @@ -148,8 +155,13 @@ export function createAnalyticsInstance(options?: Options) { url, domain, loggedIn, + user_id, + anonymous_id, + } + if (user_identity) { + config.id = user_identity + config.user_id = user_identity } - if (user_identity) config.id = user_identity _growthbook.setAttributes(config) } @@ -167,6 +179,8 @@ export function createAnalyticsInstance(options?: Options) { ...(network_downlink && { network_downlink }), ...(network_rtt && { network_rtt }), ...(network_type && { network_type }), + ...(user_id && { user_id }), + ...(anonymous_id && { anonymous_id }), } } diff --git a/src/growthbook.ts b/src/growthbook.ts index f78ad3a..db49607 100644 --- a/src/growthbook.ts +++ b/src/growthbook.ts @@ -90,11 +90,15 @@ export class Growthbook { loggedIn, network_type, network_downlink, + user_id, + anonymous_id, }: TGrowthbookAttributes) => { const CURRENT_ATTRIBUTES = this.GrowthBook.getAttributes() this.GrowthBook.setAttributes({ ...CURRENT_ATTRIBUTES, id, + ...(user_id && { user_id }), + ...(anonymous_id && { anonymous_id }), ...(country && { country }), ...(residence_country && { residence_country }), ...(user_language && { user_language }), diff --git a/src/types.ts b/src/types.ts index 9f549b0..91602b1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,6 +23,8 @@ export type TGrowthbookAttributes = { loggedIn?: boolean network_type?: string network_downlink?: number + user_id?: string + anonymous_id?: string } export type TGrowthbookOptions = Partial & { attributes: TCoreAttributes }>