@yesplz-ai/analytics-react-native 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/analytics.ts","../src/constants.ts","../src/storage.ts","../src/ids.ts","../src/attribution.ts","../src/ga.ts","../src/beacon.ts"],"sourcesContent":["export { analytics, Analytics } from './analytics';\nexport {\n EventType,\n ItemListId,\n normalizeItemListId,\n VERSION,\n} from './constants';\nexport type {\n EventTypeValue,\n ItemListIdValue,\n} from './constants';\nexport type {\n AnalyticsConfig,\n TrackItem,\n TrackProperties,\n ApiEvent,\n EventMetadata,\n} from './types';\n","import { Platform, AppState, type AppStateStatus } from 'react-native';\nimport {\n API_EVENTS,\n EventType,\n GaEventType,\n GaEventTypeReverse,\n VERSION,\n} from './constants';\nimport { Storage, StorageKeys } from './storage';\nimport {\n generateId,\n loadIdentity,\n numericSessionId,\n saveSession,\n saveUser,\n clearUser as clearUserStorage,\n} from './ids';\nimport { handleAttribution } from './attribution';\nimport { sendToGA } from './ga';\nimport { Beacon } from './beacon';\nimport type {\n AnalyticsConfig,\n ApiEvent,\n EventMetadata,\n TrackProperties,\n} from './types';\n\nconst DEFAULT_DEBOUNCE_MS = 1000;\nconst DEFAULT_API_BASE_URL = 'https://api.yesplz.ai';\nconst DEFAULT_GA_PROXY_BASE_URL = 'https://ypsh-admin.yesplz.ai/api/mp/collect';\n\nfunction buildUserAgent(): string {\n const os = Platform.OS;\n const version = Platform.Version;\n return `YesPlzSDK-RN/${VERSION} (${os}; ${String(version)})`;\n}\n\nexport class Analytics {\n private config: Required<\n Pick<AnalyticsConfig, 'debug' | 'debounceMs' | 'cacheUserId' | 'idPrefix'>\n > &\n Omit<AnalyticsConfig, 'debug' | 'debounceMs' | 'cacheUserId' | 'idPrefix'> & {\n appId?: string;\n gaProxyUrl?: string;\n } = {\n debug: false,\n debounceMs: DEFAULT_DEBOUNCE_MS,\n cacheUserId: true,\n idPrefix: '',\n };\n\n private cid: string | null = null;\n private sessionId: string | null = null;\n private userId: string | null = null;\n private userProperties: Record<string, unknown> = {};\n private isInitialized = false;\n private initPromise: Promise<void> | null = null;\n private beacon: Beacon | null = null;\n private pendingTracks: { eventType: string; properties: TrackProperties }[] = [];\n private appStateSubscription: { remove(): void } | null = null;\n\n init(appId: string, config: AnalyticsConfig = {}): Analytics {\n if (this.isInitialized || this.initPromise) return this;\n this.initPromise = this.initInternal(appId, config);\n void this.initPromise;\n return this;\n }\n\n ready(): Promise<void> {\n return this.initPromise ?? Promise.resolve();\n }\n\n private async initInternal(appId: string, config: AnalyticsConfig): Promise<void> {\n const normalizedAppId = String(appId).trim();\n if (!normalizedAppId) {\n throw new Error('[YesPlz Analytics] appId must be a non-empty string');\n }\n\n const apiBaseUrl = (config.apiBaseUrl || DEFAULT_API_BASE_URL).replace(/\\/$/, '');\n const apiEndpoint =\n config.apiEndpoint ||\n `${apiBaseUrl}/api/v1/retailer/${encodeURIComponent(normalizedAppId)}/interactions/`;\n const gaProxyBaseUrl = config.gaProxyBaseUrl || DEFAULT_GA_PROXY_BASE_URL;\n const gaProxySep = gaProxyBaseUrl.includes('?') ? '&' : '?';\n const gaProxyUrl = `${gaProxyBaseUrl}${gaProxySep}shop=${encodeURIComponent(normalizedAppId)}`;\n\n const mergedDefaultParams: Record<string, unknown> = {\n ...(config.defaultParams || {}),\n };\n if (config.testMarker) {\n mergedDefaultParams.test_marker = config.testMarker;\n }\n\n this.config = {\n ...this.config,\n appId: normalizedAppId,\n apiEndpoint,\n apiBaseUrl,\n apiToken: config.apiToken ?? null,\n gaProxyBaseUrl,\n gaProxyUrl,\n idPrefix: config.idPrefix || '',\n defaultParams: mergedDefaultParams,\n testMarker: config.testMarker,\n debug: config.debug ?? false,\n cacheUserId: config.cacheUserId ?? true,\n debounceMs: config.debounceMs || DEFAULT_DEBOUNCE_MS,\n };\n\n const identity = await loadIdentity();\n this.cid = identity.cid;\n this.sessionId = identity.sessionId;\n this.userId = identity.userId;\n this.userProperties = identity.userProperties;\n\n if (config.userId) {\n await this.setUserInternal(config.userId, config.userProperties || {});\n }\n\n if (apiEndpoint) {\n this.beacon = new Beacon({\n apiEndpoint,\n apiToken: this.config.apiToken,\n defaultParams: this.config.defaultParams,\n idPrefix: this.config.idPrefix,\n debounceMs: this.config.debounceMs,\n debug: this.config.debug,\n });\n await this.beacon.restorePending();\n }\n\n this.appStateSubscription = AppState.addEventListener(\n 'change',\n (state: AppStateStatus) => {\n if (state === 'background' || state === 'inactive') {\n void this.beacon?.savePending();\n }\n }\n );\n\n this.isInitialized = true;\n this.log('Initialized');\n\n const queued = this.pendingTracks.splice(0, this.pendingTracks.length);\n for (const item of queued) {\n void this.dispatchTrack(item.eventType, item.properties);\n }\n }\n\n async setUser(\n userId: string | null,\n userProperties: Record<string, unknown> = {}\n ): Promise<Analytics> {\n await this.ready();\n if (userId === null) {\n this.userId = null;\n this.userProperties = {};\n await clearUserStorage();\n this.log('User cleared');\n return this;\n }\n await this.setUserInternal(userId, userProperties);\n return this;\n }\n\n private async setUserInternal(\n userId: string,\n userProperties: Record<string, unknown>\n ): Promise<void> {\n const id = String(userId);\n if (id.length === 0) {\n // eslint-disable-next-line no-console\n console.error('[YesPlz Analytics] User ID must be a non-empty value');\n return;\n }\n this.userId = id;\n this.userProperties = JSON.parse(JSON.stringify(userProperties));\n await saveUser(this.userId, this.userProperties, this.config.cacheUserId);\n this.log(`User set: ${id}`);\n }\n\n getUser(): { userId: string; userProperties: Record<string, unknown> } | null {\n if (!this.userId) return null;\n return { userId: this.userId, userProperties: this.userProperties };\n }\n\n getSessionId(): string | null {\n return this.sessionId;\n }\n\n getClientId(): string | null {\n return this.cid;\n }\n\n track(eventType: string, properties: TrackProperties = {}): Analytics {\n if (typeof eventType !== 'string' || eventType.length === 0) {\n // eslint-disable-next-line no-console\n console.error('[YesPlz Analytics] Event type must be a non-empty string');\n return this;\n }\n\n if (!this.isInitialized) {\n this.pendingTracks.push({\n eventType,\n properties: JSON.parse(JSON.stringify(properties)),\n });\n return this;\n }\n\n void this.dispatchTrack(eventType, properties);\n return this;\n }\n\n private async dispatchTrack(\n eventType: string,\n properties: TrackProperties\n ): Promise<void> {\n const props: TrackProperties = JSON.parse(JSON.stringify(properties));\n\n await handleAttribution(eventType, props, this.config.idPrefix);\n\n if (eventType === EventType.Purchase && !props.transaction_id) {\n props.transaction_id = generateId();\n }\n\n if (props.id && !Array.isArray(props.items)) {\n props.items = [{ item_id: props.id, ...(props as Record<string, unknown>) }];\n }\n\n const metadata = this.collectMetadata();\n Object.assign(props, metadata);\n props.data_provider = 'yesplz';\n if (this.config.testMarker) {\n props.test_marker = this.config.testMarker;\n }\n\n await this.sendGA(eventType, props);\n\n const apiEventType = GaEventTypeReverse[eventType] || eventType;\n if (API_EVENTS.includes(apiEventType)) {\n this.queueApi(apiEventType, props, metadata);\n }\n }\n\n private async sendGA(eventType: string, props: TrackProperties): Promise<void> {\n if (!this.config.gaProxyUrl) return;\n if (!this.cid || !this.sessionId) return;\n\n const gaEventName = GaEventType[eventType] ?? eventType;\n await sendToGA(eventType, props, {\n gaProxyUrl: this.config.gaProxyUrl,\n clientId: this.cid,\n sessionId: this.sessionId,\n numericSessionId: numericSessionId(this.sessionId),\n userId: this.userId,\n debug: this.config.debug,\n });\n this.log(`Track: ${gaEventName}`, props.items?.length ? { items: props.items.length } : undefined);\n }\n\n private queueApi(\n eventType: string,\n props: TrackProperties,\n metadata: EventMetadata\n ): void {\n if (!this.beacon) return;\n const items = props.items && props.items.length > 0 ? props.items : [props];\n const fallbackUrl = `app://${this.config.appId ?? 'yesplz'}/`;\n const url =\n typeof props.page_location === 'string' && props.page_location.length > 0\n ? props.page_location\n : fallbackUrl;\n const referrerUrl =\n typeof props.page_referrer === 'string' && props.page_referrer.length > 0\n ? props.page_referrer\n : null;\n\n const events: ApiEvent[] = items.map((item) => {\n const merged: Record<string, unknown> = {\n ...(props as Record<string, unknown>),\n ...(item as Record<string, unknown>),\n ...metadata,\n };\n const itemId = (item as { item_id?: string }).item_id;\n if (itemId) merged.id = itemId;\n merged.identifier_type = eventType.startsWith('yp_brand_')\n ? 'brand_name'\n : 'product_id';\n\n const event: ApiEvent = {\n event_type: eventType,\n url,\n referrer_url: referrerUrl,\n user_id: this.userId,\n session_id: this.sessionId,\n extra_data: merged,\n };\n if (Object.keys(this.userProperties).length > 0) {\n event.extra_user_data = this.userProperties;\n }\n return event;\n });\n\n this.beacon.enqueueAll(events);\n }\n\n private collectMetadata(): EventMetadata {\n const metadata: EventMetadata = {\n yp_client_time: Date.now(),\n yp_platform: Platform.OS,\n yp_platform_version: String(Platform.Version),\n yp_user_agent: buildUserAgent(),\n yp_timezone_offset: new Date().getTimezoneOffset(),\n };\n try {\n metadata.yp_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;\n } catch {\n // ignore\n }\n if (this.cid) metadata.google_client_id = this.cid;\n return metadata;\n }\n\n async flush(): Promise<Analytics> {\n await this.ready();\n await this.beacon?.flush();\n return this;\n }\n\n async reset(): Promise<Analytics> {\n await this.ready();\n this.userId = null;\n this.userProperties = {};\n await clearUserStorage();\n await Storage.removeItem(StorageKeys.PENDING_EVENTS);\n await Storage.removeItem(StorageKeys.ATTRIBUTION);\n const newSession = generateId();\n this.sessionId = newSession;\n await saveSession(newSession);\n this.log('Reset');\n return this;\n }\n\n teardown(): void {\n this.appStateSubscription?.remove();\n this.appStateSubscription = null;\n }\n\n private log(message: string, data?: unknown): void {\n if (this.config.debug) {\n // eslint-disable-next-line no-console\n console.log(`[YesPlz Analytics] ${message}`, data ?? '');\n }\n }\n}\n\nconst globalRef = (globalThis as unknown as { __yesplz_analytics_rn__?: Analytics });\nexport const analytics: Analytics =\n globalRef.__yesplz_analytics_rn__ ||\n (globalRef.__yesplz_analytics_rn__ = new Analytics());\n","export const VERSION = '0.1.0-rn';\n\nexport const EventType = {\n ViewItemList: 'view_item_list',\n ViewItem: 'yp_product_view',\n ViewProduct: 'yp_product_view',\n SelectItem: 'yp_product_select',\n SelectProduct: 'yp_product_select',\n AddToCart: 'yp_product_cart',\n RemoveFromCart: 'yp_product_remove_from_cart',\n BeginCheckout: 'yp_begin_checkout',\n Purchase: 'yp_product_purchase',\n FavoriteProduct: 'yp_product_favorite',\n UnfavoriteProduct: 'yp_product_unfavorite',\n AddToWishlist: 'yp_product_favorite',\n RemoveFromWishlist: 'yp_product_unfavorite',\n ViewBrand: 'yp_brand_view',\n FavoriteBrand: 'yp_brand_favorite',\n UnfavoriteBrand: 'yp_brand_unfavorite',\n} as const;\n\nexport type EventTypeValue = (typeof EventType)[keyof typeof EventType];\n\nexport const GaEventType: Record<string, string> = {\n [EventType.ViewProduct]: 'view_item',\n [EventType.SelectItem]: 'select_item',\n [EventType.AddToCart]: 'add_to_cart',\n [EventType.RemoveFromCart]: 'remove_from_cart',\n [EventType.BeginCheckout]: 'begin_checkout',\n [EventType.Purchase]: 'purchase',\n [EventType.FavoriteProduct]: 'add_to_wishlist',\n [EventType.UnfavoriteProduct]: 'remove_from_wishlist',\n};\n\nexport const GaEventTypeReverse: Record<string, string> = {\n view_item: EventType.ViewProduct,\n select_item: EventType.SelectItem,\n add_to_cart: EventType.AddToCart,\n remove_from_cart: EventType.RemoveFromCart,\n begin_checkout: EventType.BeginCheckout,\n purchase: EventType.Purchase,\n add_to_wishlist: EventType.FavoriteProduct,\n remove_from_wishlist: EventType.UnfavoriteProduct,\n};\n\nexport const ItemListId = {\n SEARCH_RESULTS: 'search-results',\n PRODUCT_LIST: 'product-list',\n YOU_MAY_ALSO_LIKE: 'you-may-also-like',\n COMPLETE_THE_LOOK: 'complete-the-look',\n COLLABORATIVE_FILTERING: 'collaborative-filtering',\n MORE_FROM_BRAND: 'more-from-brand',\n STYLE_WITH: 'style-with',\n SHOPPING_CART: 'shopping-cart',\n ITEM_FOR_YOU: 'item-for-you',\n BRAND_FOR_YOU: 'brand-for-you',\n} as const;\n\nexport type ItemListIdValue = (typeof ItemListId)[keyof typeof ItemListId];\n\nconst LIST_ID_ALIASES: Record<string, string> = {\n Search: ItemListId.SEARCH_RESULTS,\n 'search-results': ItemListId.SEARCH_RESULTS,\n PLP: ItemListId.PRODUCT_LIST,\n 'product-list': ItemListId.PRODUCT_LIST,\n YMAL: ItemListId.YOU_MAY_ALSO_LIKE,\n 'you-may-also-like': ItemListId.YOU_MAY_ALSO_LIKE,\n CTL: ItemListId.COMPLETE_THE_LOOK,\n 'complete-the-look': ItemListId.COMPLETE_THE_LOOK,\n CF: ItemListId.COLLABORATIVE_FILTERING,\n 'collaborative-filtering': ItemListId.COLLABORATIVE_FILTERING,\n 'frequently-bought-together': ItemListId.COLLABORATIVE_FILTERING,\n Brand: ItemListId.MORE_FROM_BRAND,\n 'more-from-brand': ItemListId.MORE_FROM_BRAND,\n STW: ItemListId.STYLE_WITH,\n 'style-with': ItemListId.STYLE_WITH,\n CART: ItemListId.SHOPPING_CART,\n 'shopping-cart': ItemListId.SHOPPING_CART,\n 'item-for-you': ItemListId.ITEM_FOR_YOU,\n 'brand-for-you': ItemListId.BRAND_FOR_YOU,\n};\n\nexport function normalizeItemListId(input: string | undefined | null): string | undefined | null {\n if (!input) return input;\n const alias = LIST_ID_ALIASES[input];\n if (alias) return alias;\n const canonical = Object.values(ItemListId) as string[];\n if (canonical.includes(input)) return input;\n return input;\n}\n\nexport const API_EVENTS: string[] = [\n EventType.ViewProduct,\n EventType.AddToCart,\n EventType.RemoveFromCart,\n EventType.BeginCheckout,\n EventType.Purchase,\n EventType.FavoriteProduct,\n EventType.UnfavoriteProduct,\n EventType.ViewBrand,\n EventType.FavoriteBrand,\n EventType.UnfavoriteBrand,\n];\n","import AsyncStorage from '@react-native-async-storage/async-storage';\n\nexport const StorageKeys = {\n CID: 'yp_cid',\n SESSION: 'yp_session',\n USER_ID: 'yp_user_id',\n USER_PROPS: 'yp_user_props',\n ATTRIBUTION: 'yp_attribution',\n PENDING_EVENTS: 'yp_pending_events',\n} as const;\n\nexport const Storage = {\n async getItem(key: string): Promise<string | null> {\n try {\n return await AsyncStorage.getItem(key);\n } catch {\n return null;\n }\n },\n async setItem(key: string, value: string): Promise<void> {\n try {\n await AsyncStorage.setItem(key, value);\n } catch {\n // ignore\n }\n },\n async removeItem(key: string): Promise<void> {\n try {\n await AsyncStorage.removeItem(key);\n } catch {\n // ignore\n }\n },\n async getJSON<T>(key: string, fallback: T): Promise<T> {\n const raw = await Storage.getItem(key);\n if (!raw) return fallback;\n try {\n return JSON.parse(raw) as T;\n } catch {\n return fallback;\n }\n },\n async setJSON(key: string, value: unknown): Promise<void> {\n try {\n await Storage.setItem(key, JSON.stringify(value));\n } catch {\n // ignore\n }\n },\n};\n","import { Storage, StorageKeys } from './storage';\n\nexport function generateId(): string {\n return Date.now().toString(36) + Math.random().toString(36).substring(2);\n}\n\nexport function hashCode(str: string): number {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = (hash << 5) - hash + str.charCodeAt(i);\n hash |= 0;\n }\n return hash;\n}\n\nexport function numericSessionId(sessionId: string | null | undefined): number {\n if (!sessionId) return Math.floor(Date.now() / 1000);\n return Math.abs(hashCode(sessionId)) || Math.floor(Date.now() / 1000);\n}\n\nexport interface Identity {\n cid: string;\n sessionId: string;\n userId: string | null;\n userProperties: Record<string, unknown>;\n}\n\nexport async function loadIdentity(): Promise<Identity> {\n const [cidStored, sessionStored, userIdStored, userPropsStored] = await Promise.all([\n Storage.getItem(StorageKeys.CID),\n Storage.getItem(StorageKeys.SESSION),\n Storage.getItem(StorageKeys.USER_ID),\n Storage.getItem(StorageKeys.USER_PROPS),\n ]);\n\n let cid = cidStored;\n if (!cid) {\n cid = generateId();\n await Storage.setItem(StorageKeys.CID, cid);\n }\n\n let sessionId = sessionStored;\n if (!sessionId) {\n sessionId = generateId();\n await Storage.setItem(StorageKeys.SESSION, sessionId);\n }\n\n let userProperties: Record<string, unknown> = {};\n if (userPropsStored) {\n try {\n userProperties = JSON.parse(userPropsStored) as Record<string, unknown>;\n } catch {\n userProperties = {};\n }\n }\n\n return { cid, sessionId, userId: userIdStored, userProperties };\n}\n\nexport async function saveCid(cid: string): Promise<void> {\n await Storage.setItem(StorageKeys.CID, cid);\n}\n\nexport async function saveSession(sessionId: string): Promise<void> {\n await Storage.setItem(StorageKeys.SESSION, sessionId);\n}\n\nexport async function saveUser(\n userId: string,\n userProperties: Record<string, unknown>,\n cacheUserId: boolean\n): Promise<void> {\n if (cacheUserId) {\n await Storage.setItem(StorageKeys.USER_ID, userId);\n }\n await Storage.setJSON(StorageKeys.USER_PROPS, userProperties);\n}\n\nexport async function clearUser(): Promise<void> {\n await Storage.removeItem(StorageKeys.USER_ID);\n await Storage.removeItem(StorageKeys.USER_PROPS);\n}\n","import { Storage, StorageKeys } from './storage';\nimport { EventType, GaEventTypeReverse } from './constants';\nimport type { TrackProperties } from './types';\n\nconst EXPIRY_MS = 30 * 60 * 1000;\n\ntype AttributionRecord = { source: string; ts: number };\ntype AttributionStore = Record<string, AttributionRecord>;\n\nfunction normalizeId(rawId: unknown, idPrefix?: string): string | null {\n if (!rawId) return null;\n const idStr = String(rawId);\n if (idPrefix && idStr.startsWith(idPrefix)) {\n return idStr.slice(idPrefix.length);\n }\n const match = idStr.match(/^[a-zA-Z]+-(.+)$/);\n return match ? match[1] : idStr;\n}\n\nasync function loadStore(): Promise<AttributionStore> {\n return Storage.getJSON<AttributionStore>(StorageKeys.ATTRIBUTION, {});\n}\n\nasync function saveStore(store: AttributionStore): Promise<void> {\n await Storage.setJSON(StorageKeys.ATTRIBUTION, store);\n}\n\nfunction pruneExpired(store: AttributionStore): AttributionStore {\n const now = Date.now();\n const next: AttributionStore = {};\n for (const [k, v] of Object.entries(store)) {\n if (now - v.ts <= EXPIRY_MS) next[k] = v;\n }\n return next;\n}\n\nexport async function handleAttribution(\n eventType: string,\n props: TrackProperties,\n idPrefix?: string\n): Promise<void> {\n const normalizedEventType = GaEventTypeReverse[eventType] || eventType;\n\n if (normalizedEventType === EventType.SelectItem) {\n const itemListId = props.item_list_id;\n const rawId = props.id ?? props.items?.[0]?.item_id;\n const productId = normalizeId(rawId, idPrefix);\n if (itemListId && productId) {\n let store = await loadStore();\n store = pruneExpired(store);\n store[productId] = { source: itemListId, ts: Date.now() };\n await saveStore(store);\n }\n return;\n }\n\n if (normalizedEventType === EventType.ViewProduct) {\n const rawId = props.id ?? props.items?.[0]?.item_id;\n const productId = normalizeId(rawId, idPrefix);\n if (!productId) return;\n const store = await loadStore();\n const entry = store[productId];\n if (entry && Date.now() - entry.ts <= EXPIRY_MS) {\n props.item_list_id = entry.source;\n if (Array.isArray(props.items)) {\n props.items = props.items.map((item) => ({ ...item, item_list_id: entry.source }));\n }\n }\n return;\n }\n\n if (normalizedEventType === EventType.AddToCart) {\n if (!Array.isArray(props.items)) return;\n const store = await loadStore();\n props.items = props.items.map((item) => {\n const productId = normalizeId(item.item_id, idPrefix);\n const entry = productId ? store[productId] : null;\n if (entry && Date.now() - entry.ts <= EXPIRY_MS) {\n return { ...item, item_list_id: entry.source };\n }\n return item;\n });\n const firstMatch = props.items.find((item) => item.item_list_id);\n if (firstMatch?.item_list_id) {\n props.item_list_id = firstMatch.item_list_id;\n }\n }\n}\n\nexport async function getAttribution(productId: string): Promise<string | null> {\n const store = await loadStore();\n const entry = store[String(productId)];\n if (entry && Date.now() - entry.ts < EXPIRY_MS) return entry.source;\n return null;\n}\n","import { GaEventType } from './constants';\nimport type { TrackProperties } from './types';\n\nfunction toSnakeCase(str: string): string {\n return str.replace(/-/g, '_');\n}\n\nexport interface GaSendOptions {\n gaProxyUrl: string;\n clientId: string;\n sessionId: string;\n numericSessionId: number;\n userId?: string | null;\n debug?: boolean;\n}\n\nexport async function sendToGA(\n eventType: string,\n props: TrackProperties,\n options: GaSendOptions\n): Promise<void> {\n const gaEvent = GaEventType[eventType] || toSnakeCase(eventType);\n const {\n items,\n currency,\n value,\n transaction_id,\n tax,\n shipping,\n coupon,\n ...rest\n } = props;\n\n const params: Record<string, unknown> = {\n session_id: options.numericSessionId,\n engagement_time_msec: 1,\n session_engaged: '1',\n };\n\n if (currency) params.currency = currency;\n if (value !== undefined) params.value = value;\n if (transaction_id) params.transaction_id = transaction_id;\n if (tax !== undefined) params.tax = tax;\n if (shipping !== undefined) params.shipping = shipping;\n if (coupon) params.coupon = coupon;\n if (items) params.items = items;\n\n const passthroughKeys = [\n 'item_list_id',\n 'data_provider',\n 'event_source',\n 'id',\n 'search_term',\n 'total',\n 'total_text',\n 'total_vector',\n 'page_location',\n 'page_title',\n 'page_referrer',\n 'language',\n 'test_marker',\n 'yp_platform',\n 'yp_platform_version',\n 'yp_user_agent',\n ];\n for (const key of passthroughKeys) {\n if (rest[key] !== undefined) params[key] = rest[key];\n }\n\n const body: Record<string, unknown> = {\n client_id: options.clientId || options.sessionId,\n timestamp_micros: Date.now() * 1000,\n events: [{ name: gaEvent, params }],\n };\n\n if (options.userId) body.user_id = options.userId;\n\n const sep = options.gaProxyUrl.includes('?') ? '&' : '?';\n const url = options.debug\n ? `${options.gaProxyUrl}${sep}debug=1`\n : options.gaProxyUrl;\n\n try {\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n });\n if (options.debug) {\n // eslint-disable-next-line no-console\n console.log(`[YesPlz Analytics] GA MP → ${gaEvent} (status ${res.status})`);\n }\n } catch (e) {\n if (options.debug) {\n // eslint-disable-next-line no-console\n console.log(`[YesPlz Analytics] GA MP error: ${(e as Error).message}`);\n }\n }\n}\n","import { Storage, StorageKeys } from './storage';\nimport type { ApiEvent } from './types';\n\nexport interface BeaconOptions {\n apiEndpoint: string;\n apiToken?: string | null;\n defaultParams?: Record<string, unknown>;\n idPrefix?: string;\n debounceMs?: number;\n debug?: boolean;\n}\n\nexport class Beacon {\n private queue: ApiEvent[] = [];\n private isSending = false;\n private debounceTimer: ReturnType<typeof setTimeout> | null = null;\n\n constructor(private options: BeaconOptions) {}\n\n enqueue(event: ApiEvent): void {\n this.queue.push(event);\n this.scheduleSend();\n }\n\n enqueueAll(events: ApiEvent[]): void {\n this.queue.push(...events);\n this.scheduleSend();\n }\n\n private scheduleSend(): void {\n if (this.debounceTimer) clearTimeout(this.debounceTimer);\n this.debounceTimer = setTimeout(() => {\n void this.send();\n }, this.options.debounceMs ?? 1000);\n }\n\n async send(retryCount = 0): Promise<void> {\n if (this.queue.length === 0) return;\n if (!this.options.apiEndpoint) return;\n if (this.isSending) return;\n\n this.isSending = true;\n const eventsToSend = this.queue.splice(0, this.queue.length);\n\n const events = eventsToSend.map((event) => {\n const merged: Record<string, unknown> = {\n ...event,\n ...(this.options.defaultParams ?? {}),\n };\n const rawId = (event.extra_data as Record<string, unknown>).id;\n if (rawId && this.options.idPrefix) {\n merged.extra_data = {\n ...event.extra_data,\n id: `${this.options.idPrefix}${rawId}`,\n };\n }\n return merged;\n });\n\n try {\n const headers: Record<string, string> = { 'Content-Type': 'application/json' };\n if (this.options.apiToken) headers.Authorization = `Token ${this.options.apiToken}`;\n\n const res = await fetch(this.options.apiEndpoint, {\n method: 'POST',\n headers,\n body: JSON.stringify(events),\n });\n\n if (res.status > 299) {\n throw new Error(`Failed to send events (status ${res.status})`);\n }\n\n if (this.options.debug) {\n // eslint-disable-next-line no-console\n console.log(`[YesPlz Analytics] Sync: ${events.length} events sent`);\n }\n await Storage.removeItem(StorageKeys.PENDING_EVENTS);\n } catch (e) {\n if (this.options.debug) {\n // eslint-disable-next-line no-console\n console.log(`[YesPlz Analytics] Sync failed: ${(e as Error).message}`);\n }\n this.queue.unshift(...eventsToSend);\n this.isSending = false;\n if (retryCount < 1) {\n setTimeout(() => void this.send(retryCount + 1), 2000);\n }\n return;\n }\n\n this.isSending = false;\n if (this.queue.length > 0) this.scheduleSend();\n }\n\n async flush(): Promise<void> {\n if (this.debounceTimer) {\n clearTimeout(this.debounceTimer);\n this.debounceTimer = null;\n }\n await this.send();\n }\n\n async savePending(): Promise<void> {\n if (this.queue.length === 0) return;\n const toSave = this.queue.slice(-100);\n await Storage.setJSON(StorageKeys.PENDING_EVENTS, toSave);\n this.queue = [];\n }\n\n async restorePending(): Promise<void> {\n const pending = await Storage.getJSON<ApiEvent[]>(StorageKeys.PENDING_EVENTS, []);\n if (pending.length > 0) {\n this.queue.unshift(...pending);\n await Storage.removeItem(StorageKeys.PENDING_EVENTS);\n this.scheduleSend();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,0BAAwD;;;ACAjD,IAAM,UAAU;AAEhB,IAAM,YAAY;AAAA,EACvB,cAAc;AAAA,EACd,UAAU;AAAA,EACV,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,UAAU;AAAA,EACV,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,iBAAiB;AACnB;AAIO,IAAM,cAAsC;AAAA,EACjD,CAAC,UAAU,WAAW,GAAG;AAAA,EACzB,CAAC,UAAU,UAAU,GAAG;AAAA,EACxB,CAAC,UAAU,SAAS,GAAG;AAAA,EACvB,CAAC,UAAU,cAAc,GAAG;AAAA,EAC5B,CAAC,UAAU,aAAa,GAAG;AAAA,EAC3B,CAAC,UAAU,QAAQ,GAAG;AAAA,EACtB,CAAC,UAAU,eAAe,GAAG;AAAA,EAC7B,CAAC,UAAU,iBAAiB,GAAG;AACjC;AAEO,IAAM,qBAA6C;AAAA,EACxD,WAAW,UAAU;AAAA,EACrB,aAAa,UAAU;AAAA,EACvB,aAAa,UAAU;AAAA,EACvB,kBAAkB,UAAU;AAAA,EAC5B,gBAAgB,UAAU;AAAA,EAC1B,UAAU,UAAU;AAAA,EACpB,iBAAiB,UAAU;AAAA,EAC3B,sBAAsB,UAAU;AAClC;AAEO,IAAM,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AS,mBAAmB,KAAK;AAC/C,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAA4B;AAChC,UAAM,KAAK,MAAM;AACjB,UAAM,KAAK,QAAQ,MAAM;AACzB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAA4B;AAChC,UAAM,KAAK,MAAM;AACjB,SAAK,SAAS;AACd,SAAK,iBAAiB,CAAC;AACvB,UAAM,UAAiB;AACvB,UAAM,QAAQ,WAAW,YAAY,cAAc;AACnD,UAAM,QAAQ,WAAW,YAAY,WAAW;AAChD,UAAM,aAAa,WAAW;AAC9B,SAAK,YAAY;AACjB,UAAM,YAAY,UAAU;AAC5B,SAAK,IAAI,OAAO;AAChB,WAAO;AAAA,EACT;AAAA,EAEA,WAAiB;AACf,SAAK,sBAAsB,OAAO;AAClC,SAAK,uBAAuB;AAAA,EAC9B;AAAA,EAEQ,IAAI,SAAiB,MAAsB;AACjD,QAAI,KAAK,OAAO,OAAO;AAErB,cAAQ,IAAI,sBAAsB,OAAO,IAAI,QAAQ,EAAE;AAAA,IACzD;AAAA,EACF;AACF;AAEA,IAAM,YAAa;AACZ,IAAM,YACX,UAAU,4BACT,UAAU,0BAA0B,IAAI,UAAU;","names":["AsyncStorage"]}
@@ -0,0 +1,130 @@
1
+ interface AnalyticsConfig {
2
+ apiEndpoint?: string;
3
+ apiBaseUrl?: string;
4
+ apiToken?: string | null;
5
+ gaProxyBaseUrl?: string;
6
+ userId?: string;
7
+ userProperties?: Record<string, unknown>;
8
+ idPrefix?: string;
9
+ defaultParams?: Record<string, unknown>;
10
+ debug?: boolean;
11
+ debounceMs?: number;
12
+ cacheUserId?: boolean;
13
+ testMarker?: string;
14
+ }
15
+ interface TrackItem {
16
+ item_id?: string;
17
+ item_list_id?: string;
18
+ index?: number;
19
+ quantity?: number;
20
+ price?: number;
21
+ [key: string]: unknown;
22
+ }
23
+ interface TrackProperties {
24
+ id?: string;
25
+ item_list_id?: string;
26
+ items?: TrackItem[];
27
+ currency?: string;
28
+ value?: number;
29
+ transaction_id?: string;
30
+ tax?: number;
31
+ shipping?: number;
32
+ coupon?: string;
33
+ search_term?: string;
34
+ data_provider?: string;
35
+ page_location?: string;
36
+ page_title?: string;
37
+ page_referrer?: string;
38
+ language?: string;
39
+ [key: string]: unknown;
40
+ }
41
+ interface ApiEvent {
42
+ event_type: string;
43
+ url: string | null;
44
+ referrer_url: string | null;
45
+ user_id: string | null;
46
+ session_id: string | null;
47
+ extra_data: Record<string, unknown>;
48
+ extra_user_data?: Record<string, unknown>;
49
+ }
50
+ interface EventMetadata {
51
+ yp_client_time: number;
52
+ yp_platform?: string;
53
+ yp_platform_version?: string;
54
+ yp_user_agent?: string;
55
+ yp_is_online?: boolean | string;
56
+ yp_timezone_offset?: number;
57
+ yp_timezone?: string;
58
+ google_client_id?: string;
59
+ }
60
+
61
+ declare class Analytics {
62
+ private config;
63
+ private cid;
64
+ private sessionId;
65
+ private userId;
66
+ private userProperties;
67
+ private isInitialized;
68
+ private initPromise;
69
+ private beacon;
70
+ private pendingTracks;
71
+ private appStateSubscription;
72
+ init(appId: string, config?: AnalyticsConfig): Analytics;
73
+ ready(): Promise<void>;
74
+ private initInternal;
75
+ setUser(userId: string | null, userProperties?: Record<string, unknown>): Promise<Analytics>;
76
+ private setUserInternal;
77
+ getUser(): {
78
+ userId: string;
79
+ userProperties: Record<string, unknown>;
80
+ } | null;
81
+ getSessionId(): string | null;
82
+ getClientId(): string | null;
83
+ track(eventType: string, properties?: TrackProperties): Analytics;
84
+ private dispatchTrack;
85
+ private sendGA;
86
+ private queueApi;
87
+ private collectMetadata;
88
+ flush(): Promise<Analytics>;
89
+ reset(): Promise<Analytics>;
90
+ teardown(): void;
91
+ private log;
92
+ }
93
+ declare const analytics: Analytics;
94
+
95
+ declare const VERSION = "0.1.0-rn";
96
+ declare const EventType: {
97
+ readonly ViewItemList: "view_item_list";
98
+ readonly ViewItem: "yp_product_view";
99
+ readonly ViewProduct: "yp_product_view";
100
+ readonly SelectItem: "yp_product_select";
101
+ readonly SelectProduct: "yp_product_select";
102
+ readonly AddToCart: "yp_product_cart";
103
+ readonly RemoveFromCart: "yp_product_remove_from_cart";
104
+ readonly BeginCheckout: "yp_begin_checkout";
105
+ readonly Purchase: "yp_product_purchase";
106
+ readonly FavoriteProduct: "yp_product_favorite";
107
+ readonly UnfavoriteProduct: "yp_product_unfavorite";
108
+ readonly AddToWishlist: "yp_product_favorite";
109
+ readonly RemoveFromWishlist: "yp_product_unfavorite";
110
+ readonly ViewBrand: "yp_brand_view";
111
+ readonly FavoriteBrand: "yp_brand_favorite";
112
+ readonly UnfavoriteBrand: "yp_brand_unfavorite";
113
+ };
114
+ type EventTypeValue = (typeof EventType)[keyof typeof EventType];
115
+ declare const ItemListId: {
116
+ readonly SEARCH_RESULTS: "search-results";
117
+ readonly PRODUCT_LIST: "product-list";
118
+ readonly YOU_MAY_ALSO_LIKE: "you-may-also-like";
119
+ readonly COMPLETE_THE_LOOK: "complete-the-look";
120
+ readonly COLLABORATIVE_FILTERING: "collaborative-filtering";
121
+ readonly MORE_FROM_BRAND: "more-from-brand";
122
+ readonly STYLE_WITH: "style-with";
123
+ readonly SHOPPING_CART: "shopping-cart";
124
+ readonly ITEM_FOR_YOU: "item-for-you";
125
+ readonly BRAND_FOR_YOU: "brand-for-you";
126
+ };
127
+ type ItemListIdValue = (typeof ItemListId)[keyof typeof ItemListId];
128
+ declare function normalizeItemListId(input: string | undefined | null): string | undefined | null;
129
+
130
+ export { Analytics, type AnalyticsConfig, type ApiEvent, type EventMetadata, EventType, type EventTypeValue, ItemListId, type ItemListIdValue, type TrackItem, type TrackProperties, VERSION, analytics, normalizeItemListId };
@@ -0,0 +1,130 @@
1
+ interface AnalyticsConfig {
2
+ apiEndpoint?: string;
3
+ apiBaseUrl?: string;
4
+ apiToken?: string | null;
5
+ gaProxyBaseUrl?: string;
6
+ userId?: string;
7
+ userProperties?: Record<string, unknown>;
8
+ idPrefix?: string;
9
+ defaultParams?: Record<string, unknown>;
10
+ debug?: boolean;
11
+ debounceMs?: number;
12
+ cacheUserId?: boolean;
13
+ testMarker?: string;
14
+ }
15
+ interface TrackItem {
16
+ item_id?: string;
17
+ item_list_id?: string;
18
+ index?: number;
19
+ quantity?: number;
20
+ price?: number;
21
+ [key: string]: unknown;
22
+ }
23
+ interface TrackProperties {
24
+ id?: string;
25
+ item_list_id?: string;
26
+ items?: TrackItem[];
27
+ currency?: string;
28
+ value?: number;
29
+ transaction_id?: string;
30
+ tax?: number;
31
+ shipping?: number;
32
+ coupon?: string;
33
+ search_term?: string;
34
+ data_provider?: string;
35
+ page_location?: string;
36
+ page_title?: string;
37
+ page_referrer?: string;
38
+ language?: string;
39
+ [key: string]: unknown;
40
+ }
41
+ interface ApiEvent {
42
+ event_type: string;
43
+ url: string | null;
44
+ referrer_url: string | null;
45
+ user_id: string | null;
46
+ session_id: string | null;
47
+ extra_data: Record<string, unknown>;
48
+ extra_user_data?: Record<string, unknown>;
49
+ }
50
+ interface EventMetadata {
51
+ yp_client_time: number;
52
+ yp_platform?: string;
53
+ yp_platform_version?: string;
54
+ yp_user_agent?: string;
55
+ yp_is_online?: boolean | string;
56
+ yp_timezone_offset?: number;
57
+ yp_timezone?: string;
58
+ google_client_id?: string;
59
+ }
60
+
61
+ declare class Analytics {
62
+ private config;
63
+ private cid;
64
+ private sessionId;
65
+ private userId;
66
+ private userProperties;
67
+ private isInitialized;
68
+ private initPromise;
69
+ private beacon;
70
+ private pendingTracks;
71
+ private appStateSubscription;
72
+ init(appId: string, config?: AnalyticsConfig): Analytics;
73
+ ready(): Promise<void>;
74
+ private initInternal;
75
+ setUser(userId: string | null, userProperties?: Record<string, unknown>): Promise<Analytics>;
76
+ private setUserInternal;
77
+ getUser(): {
78
+ userId: string;
79
+ userProperties: Record<string, unknown>;
80
+ } | null;
81
+ getSessionId(): string | null;
82
+ getClientId(): string | null;
83
+ track(eventType: string, properties?: TrackProperties): Analytics;
84
+ private dispatchTrack;
85
+ private sendGA;
86
+ private queueApi;
87
+ private collectMetadata;
88
+ flush(): Promise<Analytics>;
89
+ reset(): Promise<Analytics>;
90
+ teardown(): void;
91
+ private log;
92
+ }
93
+ declare const analytics: Analytics;
94
+
95
+ declare const VERSION = "0.1.0-rn";
96
+ declare const EventType: {
97
+ readonly ViewItemList: "view_item_list";
98
+ readonly ViewItem: "yp_product_view";
99
+ readonly ViewProduct: "yp_product_view";
100
+ readonly SelectItem: "yp_product_select";
101
+ readonly SelectProduct: "yp_product_select";
102
+ readonly AddToCart: "yp_product_cart";
103
+ readonly RemoveFromCart: "yp_product_remove_from_cart";
104
+ readonly BeginCheckout: "yp_begin_checkout";
105
+ readonly Purchase: "yp_product_purchase";
106
+ readonly FavoriteProduct: "yp_product_favorite";
107
+ readonly UnfavoriteProduct: "yp_product_unfavorite";
108
+ readonly AddToWishlist: "yp_product_favorite";
109
+ readonly RemoveFromWishlist: "yp_product_unfavorite";
110
+ readonly ViewBrand: "yp_brand_view";
111
+ readonly FavoriteBrand: "yp_brand_favorite";
112
+ readonly UnfavoriteBrand: "yp_brand_unfavorite";
113
+ };
114
+ type EventTypeValue = (typeof EventType)[keyof typeof EventType];
115
+ declare const ItemListId: {
116
+ readonly SEARCH_RESULTS: "search-results";
117
+ readonly PRODUCT_LIST: "product-list";
118
+ readonly YOU_MAY_ALSO_LIKE: "you-may-also-like";
119
+ readonly COMPLETE_THE_LOOK: "complete-the-look";
120
+ readonly COLLABORATIVE_FILTERING: "collaborative-filtering";
121
+ readonly MORE_FROM_BRAND: "more-from-brand";
122
+ readonly STYLE_WITH: "style-with";
123
+ readonly SHOPPING_CART: "shopping-cart";
124
+ readonly ITEM_FOR_YOU: "item-for-you";
125
+ readonly BRAND_FOR_YOU: "brand-for-you";
126
+ };
127
+ type ItemListIdValue = (typeof ItemListId)[keyof typeof ItemListId];
128
+ declare function normalizeItemListId(input: string | undefined | null): string | undefined | null;
129
+
130
+ export { Analytics, type AnalyticsConfig, type ApiEvent, type EventMetadata, EventType, type EventTypeValue, ItemListId, type ItemListIdValue, type TrackItem, type TrackProperties, VERSION, analytics, normalizeItemListId };