@od-oneapp/analytics 2026.1.1301

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.
Files changed (184) hide show
  1. package/README.md +509 -0
  2. package/dist/ai-YMnynb-t.mjs +3347 -0
  3. package/dist/ai-YMnynb-t.mjs.map +1 -0
  4. package/dist/chunk-DQk6qfdC.mjs +18 -0
  5. package/dist/client-CTzJVFU5.mjs +9 -0
  6. package/dist/client-CTzJVFU5.mjs.map +1 -0
  7. package/dist/client-CcFTauAh.mjs +54 -0
  8. package/dist/client-CcFTauAh.mjs.map +1 -0
  9. package/dist/client-CeOLjbac.mjs +281 -0
  10. package/dist/client-CeOLjbac.mjs.map +1 -0
  11. package/dist/client-D339NFJS.mjs +267 -0
  12. package/dist/client-D339NFJS.mjs.map +1 -0
  13. package/dist/client-next.d.mts +62 -0
  14. package/dist/client-next.d.mts.map +1 -0
  15. package/dist/client-next.mjs +525 -0
  16. package/dist/client-next.mjs.map +1 -0
  17. package/dist/client.d.mts +30 -0
  18. package/dist/client.d.mts.map +1 -0
  19. package/dist/client.mjs +186 -0
  20. package/dist/client.mjs.map +1 -0
  21. package/dist/config-DPS6bSYo.d.mts +34 -0
  22. package/dist/config-DPS6bSYo.d.mts.map +1 -0
  23. package/dist/config-P6P5adJg.mjs +287 -0
  24. package/dist/config-P6P5adJg.mjs.map +1 -0
  25. package/dist/console-8bND3mMU.mjs +128 -0
  26. package/dist/console-8bND3mMU.mjs.map +1 -0
  27. package/dist/ecommerce-Cgu4wlux.mjs +993 -0
  28. package/dist/ecommerce-Cgu4wlux.mjs.map +1 -0
  29. package/dist/emitters-6-nKo8i-.mjs +208 -0
  30. package/dist/emitters-6-nKo8i-.mjs.map +1 -0
  31. package/dist/emitters-DldkVSPp.d.mts +12 -0
  32. package/dist/emitters-DldkVSPp.d.mts.map +1 -0
  33. package/dist/index-BfNWgfa5.d.mts +1494 -0
  34. package/dist/index-BfNWgfa5.d.mts.map +1 -0
  35. package/dist/index-BkIWe--N.d.mts +953 -0
  36. package/dist/index-BkIWe--N.d.mts.map +1 -0
  37. package/dist/index-jPzXRn52.d.mts +184 -0
  38. package/dist/index-jPzXRn52.d.mts.map +1 -0
  39. package/dist/manager-DvRRjza6.d.mts +76 -0
  40. package/dist/manager-DvRRjza6.d.mts.map +1 -0
  41. package/dist/posthog-bootstrap-CYfIy_WS.mjs +1769 -0
  42. package/dist/posthog-bootstrap-CYfIy_WS.mjs.map +1 -0
  43. package/dist/posthog-bootstrap-DWxFrxlt.d.mts +81 -0
  44. package/dist/posthog-bootstrap-DWxFrxlt.d.mts.map +1 -0
  45. package/dist/providers-http-client.d.mts +37 -0
  46. package/dist/providers-http-client.d.mts.map +1 -0
  47. package/dist/providers-http-client.mjs +320 -0
  48. package/dist/providers-http-client.mjs.map +1 -0
  49. package/dist/providers-http-server.d.mts +31 -0
  50. package/dist/providers-http-server.d.mts.map +1 -0
  51. package/dist/providers-http-server.mjs +297 -0
  52. package/dist/providers-http-server.mjs.map +1 -0
  53. package/dist/providers-http.d.mts +46 -0
  54. package/dist/providers-http.d.mts.map +1 -0
  55. package/dist/providers-http.mjs +4 -0
  56. package/dist/server-edge.d.mts +9 -0
  57. package/dist/server-edge.d.mts.map +1 -0
  58. package/dist/server-edge.mjs +373 -0
  59. package/dist/server-edge.mjs.map +1 -0
  60. package/dist/server-next.d.mts +67 -0
  61. package/dist/server-next.d.mts.map +1 -0
  62. package/dist/server-next.mjs +193 -0
  63. package/dist/server-next.mjs.map +1 -0
  64. package/dist/server.d.mts +10 -0
  65. package/dist/server.mjs +7 -0
  66. package/dist/service-cYtBBL8x.mjs +945 -0
  67. package/dist/service-cYtBBL8x.mjs.map +1 -0
  68. package/dist/shared.d.mts +16 -0
  69. package/dist/shared.d.mts.map +1 -0
  70. package/dist/shared.mjs +93 -0
  71. package/dist/shared.mjs.map +1 -0
  72. package/dist/types-BxBnNQ0V.d.mts +354 -0
  73. package/dist/types-BxBnNQ0V.d.mts.map +1 -0
  74. package/dist/types-CBvxUEaF.d.mts +216 -0
  75. package/dist/types-CBvxUEaF.d.mts.map +1 -0
  76. package/dist/types.d.mts +4 -0
  77. package/dist/types.mjs +0 -0
  78. package/dist/vercel-types-lwakUfoI.d.mts +102 -0
  79. package/dist/vercel-types-lwakUfoI.d.mts.map +1 -0
  80. package/package.json +129 -0
  81. package/src/client/index.ts +164 -0
  82. package/src/client/manager.ts +71 -0
  83. package/src/client/next/components.tsx +270 -0
  84. package/src/client/next/hooks.ts +217 -0
  85. package/src/client/next/manager.ts +141 -0
  86. package/src/client/next.ts +144 -0
  87. package/src/client-next.ts +101 -0
  88. package/src/client.ts +89 -0
  89. package/src/examples/ai-sdk-patterns.ts +583 -0
  90. package/src/examples/emitter-patterns.ts +476 -0
  91. package/src/examples/nextjs-emitter-patterns.tsx +403 -0
  92. package/src/next/app-router.tsx +564 -0
  93. package/src/next/client.ts +419 -0
  94. package/src/next/index.ts +84 -0
  95. package/src/next/middleware.ts +429 -0
  96. package/src/next/rsc.tsx +300 -0
  97. package/src/next/server.ts +253 -0
  98. package/src/next/types.d.ts +220 -0
  99. package/src/providers/base-provider.ts +419 -0
  100. package/src/providers/console/client.ts +10 -0
  101. package/src/providers/console/index.ts +152 -0
  102. package/src/providers/console/server.ts +6 -0
  103. package/src/providers/console/types.ts +15 -0
  104. package/src/providers/http/client.ts +464 -0
  105. package/src/providers/http/index.ts +30 -0
  106. package/src/providers/http/server.ts +396 -0
  107. package/src/providers/http/types.ts +135 -0
  108. package/src/providers/posthog/client.ts +518 -0
  109. package/src/providers/posthog/index.ts +11 -0
  110. package/src/providers/posthog/server.ts +329 -0
  111. package/src/providers/posthog/types.ts +104 -0
  112. package/src/providers/segment/client.ts +113 -0
  113. package/src/providers/segment/index.ts +11 -0
  114. package/src/providers/segment/server.ts +115 -0
  115. package/src/providers/segment/types.ts +51 -0
  116. package/src/providers/vercel/client.ts +102 -0
  117. package/src/providers/vercel/index.ts +11 -0
  118. package/src/providers/vercel/server.ts +89 -0
  119. package/src/providers/vercel/types.ts +27 -0
  120. package/src/server/index.ts +103 -0
  121. package/src/server/manager.ts +62 -0
  122. package/src/server/next.ts +210 -0
  123. package/src/server-edge.ts +442 -0
  124. package/src/server-next.ts +39 -0
  125. package/src/server.ts +106 -0
  126. package/src/shared/emitters/ai/README.md +981 -0
  127. package/src/shared/emitters/ai/events/agent.ts +130 -0
  128. package/src/shared/emitters/ai/events/artifacts.ts +167 -0
  129. package/src/shared/emitters/ai/events/chat.ts +126 -0
  130. package/src/shared/emitters/ai/events/chatbot-ecommerce.ts +133 -0
  131. package/src/shared/emitters/ai/events/completion.ts +103 -0
  132. package/src/shared/emitters/ai/events/content-generation.ts +347 -0
  133. package/src/shared/emitters/ai/events/conversation.ts +332 -0
  134. package/src/shared/emitters/ai/events/product-features.ts +1402 -0
  135. package/src/shared/emitters/ai/events/streaming.ts +114 -0
  136. package/src/shared/emitters/ai/events/tool.ts +93 -0
  137. package/src/shared/emitters/ai/index.ts +69 -0
  138. package/src/shared/emitters/ai/track-ai-sdk.ts +74 -0
  139. package/src/shared/emitters/ai/track-ai.ts +50 -0
  140. package/src/shared/emitters/ai/types.ts +1041 -0
  141. package/src/shared/emitters/ai/utils.ts +468 -0
  142. package/src/shared/emitters/ecommerce/events/cart-checkout.ts +106 -0
  143. package/src/shared/emitters/ecommerce/events/coupon.ts +49 -0
  144. package/src/shared/emitters/ecommerce/events/engagement.ts +61 -0
  145. package/src/shared/emitters/ecommerce/events/marketplace.ts +119 -0
  146. package/src/shared/emitters/ecommerce/events/order.ts +199 -0
  147. package/src/shared/emitters/ecommerce/events/product.ts +205 -0
  148. package/src/shared/emitters/ecommerce/events/registry.ts +123 -0
  149. package/src/shared/emitters/ecommerce/events/wishlist-sharing.ts +140 -0
  150. package/src/shared/emitters/ecommerce/index.ts +46 -0
  151. package/src/shared/emitters/ecommerce/track-ecommerce.ts +53 -0
  152. package/src/shared/emitters/ecommerce/types.ts +314 -0
  153. package/src/shared/emitters/ecommerce/utils.ts +216 -0
  154. package/src/shared/emitters/emitter-types.ts +974 -0
  155. package/src/shared/emitters/emitters.ts +292 -0
  156. package/src/shared/emitters/helpers.ts +419 -0
  157. package/src/shared/emitters/index.ts +66 -0
  158. package/src/shared/index.ts +142 -0
  159. package/src/shared/ingestion/index.ts +66 -0
  160. package/src/shared/ingestion/schemas.ts +386 -0
  161. package/src/shared/ingestion/service.ts +628 -0
  162. package/src/shared/node22-features.ts +848 -0
  163. package/src/shared/providers/console-provider.ts +160 -0
  164. package/src/shared/types/base-types.ts +54 -0
  165. package/src/shared/types/console-types.ts +19 -0
  166. package/src/shared/types/posthog-types.ts +131 -0
  167. package/src/shared/types/segment-types.ts +15 -0
  168. package/src/shared/types/types.ts +397 -0
  169. package/src/shared/types/vercel-types.ts +19 -0
  170. package/src/shared/utils/config-client.ts +19 -0
  171. package/src/shared/utils/config.ts +250 -0
  172. package/src/shared/utils/emitter-adapter.ts +212 -0
  173. package/src/shared/utils/manager.test.ts +36 -0
  174. package/src/shared/utils/manager.ts +1322 -0
  175. package/src/shared/utils/posthog-bootstrap.ts +136 -0
  176. package/src/shared/utils/posthog-client-utils.ts +48 -0
  177. package/src/shared/utils/posthog-next-utils.ts +282 -0
  178. package/src/shared/utils/posthog-server-utils.ts +210 -0
  179. package/src/shared/utils/rate-limit.ts +289 -0
  180. package/src/shared/utils/security.ts +545 -0
  181. package/src/shared/utils/validation-client.ts +161 -0
  182. package/src/shared/utils/validation.ts +399 -0
  183. package/src/shared.ts +155 -0
  184. package/src/types/index.ts +62 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecommerce-Cgu4wlux.mjs","names":[],"sources":["../src/shared/emitters/ecommerce/types.ts","../src/shared/emitters/ecommerce/utils.ts","../src/shared/emitters/ecommerce/track-ecommerce.ts","../src/shared/emitters/ecommerce/events/cart-checkout.ts","../src/shared/emitters/ecommerce/events/coupon.ts","../src/shared/emitters/ecommerce/events/engagement.ts","../src/shared/emitters/ecommerce/events/marketplace.ts","../src/shared/emitters/ecommerce/events/order.ts","../src/shared/emitters/ecommerce/events/product.ts","../src/shared/emitters/ecommerce/events/registry.ts","../src/shared/emitters/ecommerce/events/wishlist-sharing.ts","../src/shared/emitters/ecommerce/index.ts"],"sourcesContent":["/**\n * @fileoverview Platform-standard ecommerce event types\n * Platform-standard ecommerce event types\n * Based on industry best practices for ecommerce tracking\n */\n\n// Base product properties shared across events\nexport interface BaseProductProperties {\n affiliate_link?: string | undefined;\n affiliate_network?: string | undefined;\n availability?: 'in_stock' | 'out_of_stock' | 'preorder' | 'discontinued' | undefined;\n brand?: string | undefined;\n category?: string | undefined;\n commission_amount?: number | undefined;\n commission_rate?: number | undefined;\n condition?: 'new' | 'used' | 'refurbished' | undefined;\n coupon?: string | undefined;\n gtin?: string | undefined;\n image_url?: string | undefined;\n // Marketplace/affiliate properties (optional for any product)\n merchant_id?: string | undefined;\n merchant_name?: string | undefined;\n merchant_url?: string | undefined;\n mpn?: string | undefined;\n name?: string | undefined;\n original_price?: number | undefined;\n position?: number | undefined;\n price?: number | undefined;\n product_id: string;\n quantity?: number | undefined;\n sale_price?: number | undefined;\n url?: string | undefined;\n variant?: string | undefined;\n}\n\n// Extended product properties for detailed tracking\nexport interface ExtendedProductProperties extends BaseProductProperties {\n currency?: string | undefined;\n value?: number | undefined;\n}\n\n// Registry-specific properties\nexport interface RegistryProperties {\n co_registrant_id?: string | undefined;\n co_registrant_name?: string | undefined;\n event_date?: string | undefined;\n privacy_setting?: 'public' | 'private' | 'unlisted' | undefined;\n registry_id: string;\n registry_name?: string | undefined;\n registry_type?: 'wedding' | 'baby' | 'birthday' | 'universal' | 'custom' | undefined;\n registry_url?: string | undefined;\n}\n\n// Registry item properties\nexport interface RegistryItemProperties extends BaseProductProperties {\n merchant_id?: string | undefined;\n merchant_name?: string | undefined;\n notes?: string | undefined;\n priority?: 'high' | 'medium' | 'low' | undefined;\n purchased_quantity?: number | undefined;\n registry_id: string;\n requested_quantity?: number | undefined;\n}\n\n// Properties for product list events\nexport interface ProductListProperties {\n category?: string | undefined;\n list_id?: string | undefined;\n products?: BaseProductProperties[] | undefined;\n}\n\n// Properties for cart events\nexport interface CartProperties {\n cart_id?: string | undefined;\n products?: BaseProductProperties[] | undefined;\n}\n\n// Properties for checkout events\nexport interface CheckoutProperties {\n checkout_id?: string | undefined;\n payment_method?: string | undefined;\n products?: BaseProductProperties[] | undefined;\n shipping_method?: string | undefined;\n step?: number | undefined;\n}\n\n// Properties for order events\nexport interface OrderProperties {\n affiliation?: string | undefined;\n coupon?: string | undefined;\n currency?: string | undefined;\n discount?: number | undefined;\n order_id: string;\n products?: BaseProductProperties[] | undefined;\n revenue?: number | undefined;\n shipping?: number | undefined;\n tax?: number | undefined;\n total?: number | undefined;\n}\n\n// Properties for coupon events\nexport interface CouponProperties {\n cart_id?: string | undefined;\n coupon_id?: string | undefined;\n coupon_name?: string | undefined;\n discount?: number | undefined;\n order_id?: string | undefined;\n reason?: string | undefined;\n}\n\n// Properties for wishlist events\nexport interface WishlistProperties extends BaseProductProperties {\n wishlist_id?: string | undefined;\n wishlist_name?: string | undefined;\n}\n\n// Properties for sharing events\nexport interface SharingProperties {\n recipient?: string | undefined;\n share_message?: string | undefined;\n share_via?: string | undefined;\n}\n\n// Properties for review events\nexport interface ReviewProperties {\n product_id: string;\n rating?: string | undefined;\n review_body?: string | undefined;\n review_id?: string | undefined;\n}\n\n// Properties for search results\nexport interface SearchResultsProperties {\n filters_applied?: Record<string, any>;\n products?: BaseProductProperties[];\n query: string;\n results_count: number;\n sort_order?: string;\n}\n\n// Properties for cart updates\nexport interface CartUpdateProperties {\n action: 'added' | 'removed' | 'updated';\n cart_id?: string;\n cart_total?: number;\n product: BaseProductProperties;\n quantity_change?: number;\n}\n\n// Properties for cart abandonment\nexport interface CartAbandonmentProperties {\n abandonment_reason?: 'timeout' | 'navigation' | 'closed';\n cart_id: string;\n cart_value: number;\n products: BaseProductProperties[];\n time_in_cart?: number;\n}\n\n// Properties for checkout progression\nexport interface CheckoutProgressProperties {\n action: 'viewed' | 'completed' | 'abandoned' | 'error';\n checkout_id?: string;\n error_message?: string;\n payment_method?: string;\n products?: BaseProductProperties[];\n shipping_method?: string;\n step: number;\n step_name: string;\n}\n\n// Properties for order status updates\nexport interface OrderStatusProperties {\n carrier?: string;\n estimated_delivery?: string;\n order_id: string;\n previous_status?: string;\n status:\n | 'confirmed'\n | 'processing'\n | 'shipped'\n | 'out_for_delivery'\n | 'delivered'\n | 'returned'\n | 'failed';\n tracking_number?: string;\n}\n\n// Properties for product comparison\nexport interface ProductComparisonProperties {\n action: 'added' | 'removed' | 'viewed';\n comparison_list?: BaseProductProperties[];\n product: BaseProductProperties;\n}\n\n// Properties for recommendations\nexport interface RecommendationProperties {\n algorithm?: string;\n products: BaseProductProperties[];\n recommendation_type:\n | 'similar'\n | 'frequently_bought'\n | 'trending'\n | 'personalized'\n | 'upsell'\n | 'cross_sell';\n source: string; // e.g., 'product_page', 'cart', 'checkout'\n}\n\n// Properties for engagement events\nexport interface EngagementProperties {\n action_type: 'price_alert' | 'back_in_stock' | 'favorite';\n notification_method?: 'email' | 'sms' | 'push';\n product_id: string;\n threshold_price?: number;\n}\n\n// Properties for returns\nexport interface ReturnProperties {\n order_id: string;\n products: BaseProductProperties[];\n reason: string;\n refund_amount?: number;\n return_id?: string;\n return_method?: 'mail' | 'store' | 'pickup';\n}\n\n// Standard ecommerce event names\nexport const ECOMMERCE_EVENTS = {\n PRODUCT_CLICKED: 'Product Clicked',\n PRODUCT_COMPARED: 'Product Compared',\n PRODUCT_LIST_FILTERED: 'Product List Filtered',\n PRODUCT_LIST_VIEWED: 'Product List Viewed',\n PRODUCT_RECOMMENDATION_CLICKED: 'Product Recommendation Clicked',\n PRODUCT_RECOMMENDATION_VIEWED: 'Product Recommendation Viewed',\n // Search & Discovery events\n PRODUCT_SEARCHED: 'Product Searched',\n PRODUCT_VIEWED: 'Product Viewed',\n SEARCH_RESULTS_VIEWED: 'Search Results Viewed',\n\n CART_ABANDONED: 'Cart Abandoned',\n // Cart events\n CART_UPDATED: 'Cart Updated',\n CART_VIEWED: 'Cart Viewed',\n\n // Checkout events\n CHECKOUT_PROGRESSED: 'Checkout Progressed',\n\n ORDER_CANCELLED: 'Order Cancelled',\n // Order events\n ORDER_COMPLETED: 'Order Completed',\n ORDER_FAILED: 'Order Failed',\n ORDER_REFUNDED: 'Order Refunded',\n ORDER_STATUS_UPDATED: 'Order Status Updated',\n\n // Coupon events\n COUPON_APPLIED: 'Coupon Applied',\n COUPON_REMOVED: 'Coupon Removed',\n\n // Wishlist events\n PRODUCT_ADDED_TO_WISHLIST: 'Product Added to Wishlist',\n PRODUCT_REMOVED_FROM_WISHLIST: 'Product Removed from Wishlist',\n WISHLIST_PRODUCT_ADDED_TO_CART: 'Wishlist Product Added to Cart',\n\n CART_SHARED: 'Cart Shared',\n // Sharing events\n PRODUCT_SHARED: 'Product Shared',\n\n // Review events\n PRODUCT_REVIEWED: 'Product Reviewed',\n\n AFFILIATE_CONVERSION_TRACKED: 'Affiliate Conversion Tracked',\n AFFILIATE_LINK_CLICKED: 'Affiliate Link Clicked',\n // Marketplace-specific events\n MERCHANT_SELECTED: 'Merchant Selected',\n PRICE_COMPARISON_VIEWED: 'Price Comparison Viewed',\n\n REGISTRY_ITEM_MANAGED: 'Registry Item Managed',\n // Registry events\n REGISTRY_MANAGED: 'Registry Managed',\n REGISTRY_SHARED: 'Registry Shared',\n REGISTRY_VIEWED: 'Registry Viewed',\n\n RETURN_COMPLETED: 'Return Completed',\n // Post-purchase events\n RETURN_REQUESTED: 'Return Requested',\n\n BACK_IN_STOCK_REQUESTED: 'Back In Stock Requested',\n // Engagement events\n PRICE_ALERT_SET: 'Price Alert Set',\n} as const;\n\nexport type EcommerceEventName = (typeof ECOMMERCE_EVENTS)[keyof typeof ECOMMERCE_EVENTS];\n\n// Event specification interface\nexport interface EcommerceEventSpec<T = any> {\n category: 'ecommerce';\n name: EcommerceEventName;\n properties: T;\n requiredProperties: (keyof T)[];\n}\n\n// Union type for all ecommerce event properties\nexport type EcommerceEventProperties =\n | BaseProductProperties\n | ExtendedProductProperties\n | ProductListProperties\n | CartProperties\n | CheckoutProperties\n | OrderProperties\n | CouponProperties\n | WishlistProperties\n | (BaseProductProperties & SharingProperties)\n | (CartProperties & SharingProperties)\n | ReviewProperties;\n","/**\n * @fileoverview Utilities for normalizing and validating ecommerce event properties\n * Utilities for normalizing and validating ecommerce event properties\n */\n\nimport type { BaseProductProperties, EcommerceEventProperties } from './types';\n\n/**\n * Input product type for normalization functions\n * Accepts various property naming conventions\n */\ninterface ProductInput {\n // ID variations\n product_id?: string;\n productId?: string;\n id?: string;\n // Name variations\n name?: string;\n title?: string;\n productName?: string;\n // Image URL variations\n image_url?: string;\n imageUrl?: string;\n image?: string;\n // URL variations\n url?: string;\n link?: string;\n product_url?: string;\n // Other properties\n brand?: string;\n manufacturer?: string;\n category?: string;\n coupon?: string;\n couponCode?: string;\n coupon_code?: string;\n position?: number | string;\n price?: number | string;\n quantity?: number | string;\n variant?: string;\n variation?: string;\n [key: string]: unknown;\n}\n\n/**\n * Normalizes product properties to ensure consistent naming\n * Handles common variations like productId vs product_id\n */\nexport function normalizeProductProperties(\n product?: ProductInput | unknown,\n): BaseProductProperties {\n if (!product || typeof product !== 'object') {\n throw new Error('Product properties are required');\n }\n\n const p = product as ProductInput;\n\n // Normalize product ID (required) - using ES2022 nullish coalescing\n const product_id = p.product_id ?? p.productId ?? p.id;\n if (!product_id) {\n throw new Error('Product must have an id (product_id, productId, or id)');\n }\n\n const normalized = {\n product_id,\n name: p.name ?? p.title ?? p.productName,\n image_url: p.image_url ?? p.imageUrl ?? p.image,\n url: p.url ?? p.link ?? p.product_url,\n brand: p.brand ?? p.manufacturer,\n category: p.category,\n coupon: p.coupon ?? p.couponCode ?? p.coupon_code,\n position: normalizePosition(p.position),\n price: normalizePrice(p.price),\n quantity: normalizeQuantity(p.quantity),\n variant: p.variant ?? p.variation,\n };\n\n // Remove undefined and null values - using ES2022 Object.hasOwn\n const result: BaseProductProperties = { product_id };\n Object.entries(normalized).forEach(([key, value]) => {\n if (\n value !== undefined &&\n value !== null &&\n Object.hasOwn(normalized, key) &&\n key !== 'product_id'\n ) {\n // Cast to any to allow dynamic property assignment\n (result as any)[key] = value;\n }\n });\n\n return result;\n}\n\n/**\n * Normalizes an array of products\n */\nexport function normalizeProducts(products: unknown[]): BaseProductProperties[] {\n if (!Array.isArray(products)) {\n return [];\n }\n return products.map(product => normalizeProductProperties(product as ProductInput));\n}\n\n/**\n * ES2022 enhanced product validation with Error.cause\n */\nexport function validateProductWithContext(product: unknown, context?: string): void {\n try {\n normalizeProductProperties(product as ProductInput);\n } catch (error) {\n throw new Error(`Product validation failed${context ? ` in ${context}` : ''}`, {\n cause: error,\n });\n }\n}\n\n/**\n * Normalizes price to a number\n */\nfunction normalizePrice(price: unknown): number | undefined {\n if (price === undefined || price === null) {\n return undefined;\n }\n const normalized = typeof price === 'string' ? Number.parseFloat(price) : Number(price);\n return Number.isNaN(normalized) ? undefined : normalized;\n}\n\n/**\n * Normalizes quantity to a positive integer\n */\nfunction normalizeQuantity(quantity: unknown): number | undefined {\n if (quantity === undefined || quantity === null) {\n return undefined;\n }\n const normalized = Number.parseInt(String(quantity), 10);\n return Number.isNaN(normalized) || normalized < 0 ? undefined : normalized;\n}\n\n/**\n * Normalizes position to a positive integer\n */\nfunction normalizePosition(position: unknown): number | undefined {\n if (position === undefined || position === null) {\n return undefined;\n }\n const normalized = Number.parseInt(String(position), 10);\n return Number.isNaN(normalized) || normalized < 0 ? undefined : normalized;\n}\n\n/**\n * Validates required properties for an event\n */\nexport function validateRequiredProperties<T extends Record<string, any>>(\n properties: T,\n required: (keyof T)[],\n): void {\n const missing = required.filter(prop => {\n const value = properties[prop];\n return value === undefined || value === null || value === '';\n });\n if (missing.length > 0) {\n throw new Error(`Missing required properties: ${missing.join(', ')}`);\n }\n}\n\n/**\n * Removes undefined values from an object\n */\nexport function cleanProperties<T extends Record<string, any>>(obj: T): Partial<T> {\n const cleaned: Partial<T> = {};\n for (const [key, value] of Object.entries(obj)) {\n if (value !== undefined) {\n cleaned[key as keyof T] = value;\n }\n }\n return cleaned;\n}\n\n/**\n * Merges common fields with event-specific properties\n */\nexport function mergeEventProperties(\n specific: EcommerceEventProperties,\n common?: Record<string, any>,\n): EcommerceEventProperties {\n return {\n ...common,\n ...specific,\n };\n}\n\n/**\n * Validates currency code (ISO 4217)\n */\nexport function validateCurrency(currency?: string): string | undefined {\n if (!currency || typeof currency !== 'string') return undefined;\n\n // Basic validation - should be 3 uppercase letters\n const normalized = currency.toUpperCase();\n if (!/^[A-Z]{3}$/.test(normalized)) {\n // Invalid currency code - return undefined\n return undefined;\n }\n\n return normalized;\n}\n\n/**\n * Creates a consistent context object for ecommerce events\n */\nexport function createEcommerceContext(additionalContext?: Record<string, any>) {\n return {\n ...additionalContext,\n category: 'ecommerce',\n };\n}\n","/**\n * @fileoverview Ecommerce tracking wrapper that integrates with the core emitter system\n * Ecommerce tracking wrapper that integrates with the core emitter system\n */\n\nimport { track } from '../emitters';\n\nimport type { EmitterOptions, EmitterTrackPayload } from '../emitter-types';\nimport type { EcommerceEventSpec } from './types';\n\n/**\n * Convert an ecommerce event specification to a track payload\n *\n * @param eventSpec - The ecommerce event specification\n * @param options - Optional emitter options\n * @returns Track payload ready to be sent to analytics providers\n */\nexport function trackEcommerce(\n eventSpec: EcommerceEventSpec,\n options?: EmitterOptions,\n): EmitterTrackPayload {\n // Add ecommerce context to options\n const enrichedOptions: EmitterOptions = {\n ...options,\n context: {\n ...options?.context,\n // Add ecommerce-specific context if needed\n ...(eventSpec.category && {\n // Store category as a custom field since EmitterContext doesn't have category\n traits: {\n ...options?.context?.traits,\n event_category: eventSpec.category,\n },\n }),\n },\n };\n\n // Return the track payload with the event name and properties\n return track(eventSpec.name, eventSpec.properties, enrichedOptions);\n}\n\n/**\n * Helper to create a tracking function for a specific ecommerce event\n * This allows for cleaner usage in applications\n */\nexport function createEcommerceTracker<T extends Record<string, any>>(\n eventFactory: (properties: T) => EcommerceEventSpec,\n) {\n return (properties: T, options?: EmitterOptions): EmitterTrackPayload => {\n const eventSpec = eventFactory(properties);\n return trackEcommerce(eventSpec, options);\n };\n}\n","/**\n * @fileoverview Cart and checkout-related ecommerce events\n * Cart and checkout-related ecommerce events\n */\n\nimport { trackEcommerce } from '../track-ecommerce';\nimport {\n type CartAbandonmentProperties,\n type CartProperties,\n type CartUpdateProperties,\n type CheckoutProgressProperties,\n ECOMMERCE_EVENTS,\n type EcommerceEventSpec,\n} from '../types';\nimport {\n cleanProperties,\n normalizeProductProperties,\n normalizeProducts,\n validateRequiredProperties,\n} from '../utils';\n\nimport type { EmitterOptions, EmitterTrackPayload } from '../../emitter-types';\n\n/**\n * Track cart updates (add, remove, update) with a single event\n */\nexport function cartUpdated(\n properties: CartUpdateProperties,\n options?: EmitterOptions,\n): EmitterTrackPayload {\n const { cart_id, action, cart_total, product, quantity_change } = properties;\n const normalizedProduct = normalizeProductProperties(product);\n\n validateRequiredProperties(properties, ['action']);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n\n const eventSpec: EcommerceEventSpec = {\n name: ECOMMERCE_EVENTS.CART_UPDATED,\n category: 'ecommerce',\n properties: cleanProperties({\n action,\n ...normalizedProduct,\n cart_id,\n cart_total,\n quantity_change,\n }),\n requiredProperties: ['action', 'product_id'],\n };\n\n return trackEcommerce(eventSpec, options);\n}\n\n/**\n * Track when a user views their shopping cart\n */\nexport function cartViewed(properties: CartProperties): EcommerceEventSpec<CartProperties> {\n const normalizedProps: CartProperties = {\n cart_id: properties.cart_id,\n products: properties.products ? normalizeProducts(properties.products) : undefined,\n };\n\n return {\n name: ECOMMERCE_EVENTS.CART_VIEWED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: [],\n };\n}\n\n/**\n * Track when a cart is abandoned\n */\nexport function cartAbandoned(properties: CartAbandonmentProperties): EcommerceEventSpec {\n validateRequiredProperties(properties, ['cart_id', 'cart_value']);\n\n const normalizedProps = {\n ...properties,\n products: normalizeProducts(properties.products),\n };\n\n return {\n name: ECOMMERCE_EVENTS.CART_ABANDONED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['cart_id', 'cart_value'],\n };\n}\n\n/**\n * Track checkout progression with a single event\n */\nexport function checkoutProgressed(properties: CheckoutProgressProperties): EcommerceEventSpec {\n validateRequiredProperties(properties, ['step', 'step_name', 'action']);\n\n const normalizedProps = {\n ...properties,\n products: properties.products ? normalizeProducts(properties.products) : undefined,\n };\n\n return {\n name: ECOMMERCE_EVENTS.CHECKOUT_PROGRESSED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['step', 'step_name', 'action'],\n };\n}\n","/**\n * @fileoverview Coupon-related ecommerce events\n * Coupon-related ecommerce events\n */\n\nimport { type CouponProperties, ECOMMERCE_EVENTS, type EcommerceEventSpec } from '../types';\nimport { cleanProperties } from '../utils';\n\n/**\n * Track when a coupon is successfully applied\n */\nexport function couponApplied(properties: CouponProperties): EcommerceEventSpec<CouponProperties> {\n const normalizedProps: CouponProperties = {\n cart_id: properties.cart_id,\n coupon_id: properties.coupon_id,\n order_id: properties.order_id,\n coupon_name: properties.coupon_name,\n discount: properties.discount,\n reason: properties.reason,\n };\n\n return {\n name: ECOMMERCE_EVENTS.COUPON_APPLIED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: [],\n };\n}\n\n/**\n * Track when a coupon is removed\n */\nexport function couponRemoved(properties: CouponProperties): EcommerceEventSpec<CouponProperties> {\n const normalizedProps: CouponProperties = {\n cart_id: properties.cart_id,\n coupon_id: properties.coupon_id,\n order_id: properties.order_id,\n coupon_name: properties.coupon_name,\n discount: properties.discount,\n reason: properties.reason,\n };\n\n return {\n name: ECOMMERCE_EVENTS.COUPON_REMOVED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: [],\n };\n}\n","/**\n * @fileoverview Customer engagement events for ecommerce\n * Customer engagement events for ecommerce\n * Track user interactions that indicate interest but aren't direct purchases\n */\n\nimport { type BaseProductProperties, ECOMMERCE_EVENTS, type EcommerceEventSpec } from '../types';\nimport { cleanProperties, normalizeProductProperties, validateRequiredProperties } from '../utils';\n\n/**\n * Track when a user sets a price alert for a product\n */\nexport function priceAlertSet(\n properties: BaseProductProperties & {\n threshold_price: number;\n notification_method?: 'email' | 'sms' | 'push';\n currency?: string;\n },\n): EcommerceEventSpec {\n const { currency, notification_method, threshold_price, ...productProps } = properties;\n const normalizedProduct = normalizeProductProperties(productProps);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n validateRequiredProperties({ threshold_price }, ['threshold_price']);\n\n return {\n name: ECOMMERCE_EVENTS.PRICE_ALERT_SET,\n category: 'ecommerce',\n properties: cleanProperties({\n ...normalizedProduct,\n action_type: 'price_alert',\n currency,\n notification_method,\n threshold_price,\n }),\n requiredProperties: ['product_id', 'threshold_price'],\n };\n}\n\n/**\n * Track when a user requests notification for out-of-stock items\n */\nexport function backInStockRequested(\n properties: BaseProductProperties & {\n notification_method?: 'email' | 'sms' | 'push';\n },\n): EcommerceEventSpec {\n const { notification_method, ...productProps } = properties;\n const normalizedProduct = normalizeProductProperties(productProps);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.BACK_IN_STOCK_REQUESTED,\n category: 'ecommerce',\n properties: cleanProperties({\n ...normalizedProduct,\n action_type: 'back_in_stock',\n notification_method,\n }),\n requiredProperties: ['product_id'],\n };\n}\n","/**\n * @fileoverview Marketplace and affiliate-specific ecommerce events\n * Marketplace and affiliate-specific ecommerce events\n * These events track user interactions unique to marketplace/affiliate models\n */\n\nimport { type BaseProductProperties, ECOMMERCE_EVENTS, type EcommerceEventSpec } from '../types';\nimport { cleanProperties, normalizeProductProperties, validateRequiredProperties } from '../utils';\n\n/**\n * Track when a user views price comparisons across multiple merchants\n */\nexport function priceComparisonViewed(properties: {\n product_id: string;\n merchants: {\n merchant_id: string;\n merchant_name: string;\n price: number;\n shipping?: number;\n total_price?: number;\n availability?: string;\n rating?: number;\n }[];\n lowest_price?: number;\n highest_price?: number;\n average_price?: number;\n}): EcommerceEventSpec {\n validateRequiredProperties(properties, ['product_id', 'merchants']);\n\n return {\n name: ECOMMERCE_EVENTS.PRICE_COMPARISON_VIEWED,\n category: 'ecommerce',\n properties: cleanProperties(properties),\n requiredProperties: ['product_id', 'merchants'],\n };\n}\n\n/**\n * Track when a user selects a specific merchant from multiple options\n */\nexport function merchantSelected(\n properties: BaseProductProperties & {\n selected_merchant_id: string;\n selected_merchant_name: string;\n selection_reason?: 'lowest_price' | 'fastest_shipping' | 'best_rating' | 'in_stock' | 'other';\n compared_merchants?: string[];\n },\n): EcommerceEventSpec {\n const normalizedProps = normalizeProductProperties(properties);\n validateRequiredProperties(properties, ['product_id', 'selected_merchant_id']);\n\n return {\n name: ECOMMERCE_EVENTS.MERCHANT_SELECTED,\n category: 'ecommerce',\n properties: cleanProperties({\n ...normalizedProps,\n selected_merchant_id: properties.selected_merchant_id,\n selected_merchant_name: properties.selected_merchant_name,\n compared_merchants: properties.compared_merchants,\n selection_reason: properties.selection_reason,\n }),\n requiredProperties: ['product_id', 'selected_merchant_id'],\n };\n}\n\n/**\n * Track when a user clicks an affiliate link to visit merchant site\n */\nexport function affiliateLinkClicked(\n properties: BaseProductProperties & {\n destination_url: string;\n affiliate_network?: string;\n commission_rate?: number;\n tracking_code?: string;\n deep_link?: boolean;\n },\n): EcommerceEventSpec {\n const normalizedProps = normalizeProductProperties(properties);\n validateRequiredProperties(properties, ['product_id', 'destination_url']);\n\n return {\n name: ECOMMERCE_EVENTS.AFFILIATE_LINK_CLICKED,\n category: 'ecommerce',\n properties: cleanProperties({\n ...normalizedProps,\n destination_url: properties.destination_url,\n deep_link: properties.deep_link,\n tracking_code: properties.tracking_code,\n }),\n requiredProperties: ['product_id', 'destination_url'],\n };\n}\n\n/**\n * Track when an affiliate conversion is confirmed\n * This is typically fired via webhook or after confirmation from affiliate network\n */\nexport function affiliateConversionTracked(properties: {\n product_id: string;\n order_id: string;\n merchant_id: string;\n merchant_name?: string;\n affiliate_network?: string;\n commission_amount?: number;\n commission_rate?: number;\n conversion_value?: number;\n currency?: string;\n conversion_type?: 'sale' | 'lead' | 'click' | 'other';\n tracking_code?: string;\n}): EcommerceEventSpec {\n validateRequiredProperties(properties, ['product_id', 'order_id', 'merchant_id']);\n\n return {\n name: ECOMMERCE_EVENTS.AFFILIATE_CONVERSION_TRACKED,\n category: 'ecommerce',\n properties: cleanProperties(properties),\n requiredProperties: ['product_id', 'order_id', 'merchant_id'],\n };\n}\n","/**\n * @fileoverview Order-related ecommerce events\n * Order-related ecommerce events\n */\n\nimport { trackEcommerce } from '../track-ecommerce';\nimport {\n ECOMMERCE_EVENTS,\n type EcommerceEventSpec,\n type OrderProperties,\n type OrderStatusProperties,\n type ReturnProperties,\n} from '../types';\nimport {\n cleanProperties,\n normalizeProducts,\n validateCurrency,\n validateRequiredProperties,\n} from '../utils';\n\nimport type { EmitterOptions, EmitterTrackPayload } from '../../emitter-types';\n\n/**\n * Track when a user completes an order\n */\nexport function orderCompleted(\n properties: OrderProperties,\n options?: EmitterOptions,\n): EmitterTrackPayload {\n validateRequiredProperties(properties, ['order_id']);\n\n const normalizedProps: OrderProperties = {\n order_id: properties.order_id,\n affiliation: properties.affiliation,\n coupon: properties.coupon,\n currency: validateCurrency(properties.currency),\n discount: properties.discount,\n products: properties.products ? normalizeProducts(properties.products) : undefined,\n revenue: properties.revenue,\n shipping: properties.shipping,\n tax: properties.tax,\n total: properties.total,\n };\n\n const eventSpec: EcommerceEventSpec = {\n name: ECOMMERCE_EVENTS.ORDER_COMPLETED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['order_id'],\n };\n\n return trackEcommerce(eventSpec, options);\n}\n\n/**\n * Track when an order fails (payment declined, validation error, etc.)\n */\nexport function orderFailed(\n properties: OrderProperties & {\n failure_reason?: string;\n error_code?: string;\n },\n): EcommerceEventSpec {\n validateRequiredProperties(properties, ['order_id']);\n\n const { error_code, failure_reason, ...orderProps } = properties;\n const normalizedProps = {\n order_id: orderProps.order_id,\n affiliation: orderProps.affiliation,\n coupon: orderProps.coupon,\n currency: validateCurrency(orderProps.currency),\n discount: orderProps.discount,\n error_code,\n failure_reason,\n products: orderProps.products ? normalizeProducts(orderProps.products) : undefined,\n revenue: orderProps.revenue,\n shipping: orderProps.shipping,\n tax: orderProps.tax,\n total: orderProps.total,\n };\n\n return {\n name: ECOMMERCE_EVENTS.ORDER_FAILED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['order_id'],\n };\n}\n\n/**\n * Track when an order is refunded\n */\nexport function orderRefunded(properties: OrderProperties): EcommerceEventSpec {\n validateRequiredProperties(properties, ['order_id']);\n\n const normalizedProps: OrderProperties = {\n order_id: properties.order_id,\n affiliation: properties.affiliation,\n coupon: properties.coupon,\n currency: validateCurrency(properties.currency),\n discount: properties.discount,\n products: properties.products ? normalizeProducts(properties.products) : undefined,\n revenue: properties.revenue,\n shipping: properties.shipping,\n tax: properties.tax,\n total: properties.total,\n };\n\n return {\n name: ECOMMERCE_EVENTS.ORDER_REFUNDED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['order_id'],\n };\n}\n\n/**\n * Track when an order is cancelled\n */\nexport function orderCancelled(properties: OrderProperties): EcommerceEventSpec {\n validateRequiredProperties(properties, ['order_id']);\n\n const normalizedProps: OrderProperties = {\n order_id: properties.order_id,\n affiliation: properties.affiliation,\n coupon: properties.coupon,\n currency: validateCurrency(properties.currency),\n discount: properties.discount,\n products: properties.products ? normalizeProducts(properties.products) : undefined,\n revenue: properties.revenue,\n shipping: properties.shipping,\n tax: properties.tax,\n total: properties.total,\n };\n\n return {\n name: ECOMMERCE_EVENTS.ORDER_CANCELLED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['order_id'],\n };\n}\n\n/**\n * Track order status changes (shipping, delivery, etc.)\n */\nexport function orderStatusUpdated(properties: OrderStatusProperties): EcommerceEventSpec {\n validateRequiredProperties(properties, ['order_id', 'status']);\n\n return {\n name: ECOMMERCE_EVENTS.ORDER_STATUS_UPDATED,\n category: 'ecommerce',\n properties: cleanProperties(properties),\n requiredProperties: ['order_id', 'status'],\n };\n}\n\n/**\n * Track when a return is requested\n */\nexport function returnRequested(properties: ReturnProperties): EcommerceEventSpec {\n validateRequiredProperties(properties, ['order_id', 'reason']);\n\n const normalizedProps = {\n ...properties,\n products: normalizeProducts(properties.products),\n };\n\n return {\n name: ECOMMERCE_EVENTS.RETURN_REQUESTED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['order_id', 'reason'],\n };\n}\n\n/**\n * Track when a return is completed\n */\nexport function returnCompleted(\n properties: ReturnProperties & {\n completion_date?: string;\n refund_status?: 'pending' | 'completed' | 'failed';\n },\n): EcommerceEventSpec {\n validateRequiredProperties(properties, ['order_id', 'return_id']);\n\n const normalizedProps = {\n ...properties,\n products: normalizeProducts(properties.products),\n };\n\n return {\n name: ECOMMERCE_EVENTS.RETURN_COMPLETED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['order_id', 'return_id'],\n };\n}\n","/**\n * @fileoverview Product-related ecommerce events\n * Product-related ecommerce events\n */\n\nimport { trackEcommerce } from '../track-ecommerce';\nimport {\n type BaseProductProperties,\n ECOMMERCE_EVENTS,\n type EcommerceEventSpec,\n type ProductComparisonProperties,\n type ProductListProperties,\n type RecommendationProperties,\n type SearchResultsProperties,\n} from '../types';\nimport {\n cleanProperties,\n normalizeProductProperties,\n normalizeProducts,\n validateRequiredProperties,\n} from '../utils';\n\nimport type { EmitterOptions, EmitterTrackPayload } from '../../emitter-types';\n\n/**\n * Track when a user searches for products\n */\nexport function productSearched(\n properties: { query: string },\n options?: EmitterOptions,\n): EmitterTrackPayload {\n validateRequiredProperties(properties, ['query']);\n\n const eventSpec: EcommerceEventSpec = {\n name: ECOMMERCE_EVENTS.PRODUCT_SEARCHED,\n category: 'ecommerce',\n properties: cleanProperties(properties),\n requiredProperties: ['query'],\n };\n\n return trackEcommerce(eventSpec, options);\n}\n\n/**\n * Track when search results are displayed\n */\nexport function searchResultsViewed(properties: SearchResultsProperties): EcommerceEventSpec {\n validateRequiredProperties(properties, ['query', 'results_count']);\n\n const normalizedProps = {\n ...properties,\n products: properties.products ? normalizeProducts(properties.products) : undefined,\n };\n\n return {\n name: ECOMMERCE_EVENTS.SEARCH_RESULTS_VIEWED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['query', 'results_count'],\n };\n}\n\n/**\n * Track when a user views a product list or category\n */\nexport function productListViewed(\n properties: ProductListProperties,\n): EcommerceEventSpec<ProductListProperties> {\n const normalizedProps: ProductListProperties = {\n list_id: properties.list_id,\n category: properties.category,\n products: properties.products ? normalizeProducts(properties.products) : undefined,\n };\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_LIST_VIEWED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: [],\n };\n}\n\n/**\n * Track when a user filters a product list\n */\nexport function productListFiltered(\n properties: ProductListProperties & { filters?: Record<string, any> },\n): EcommerceEventSpec {\n const normalizedProps = {\n list_id: properties.list_id,\n category: properties.category,\n filters: properties.filters,\n products: properties.products ? normalizeProducts(properties.products) : undefined,\n };\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_LIST_FILTERED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: [],\n };\n}\n\n/**\n * Track when a user clicks on a product\n */\nexport function productClicked(properties: BaseProductProperties): EcommerceEventSpec {\n const normalizedProps = normalizeProductProperties(properties);\n validateRequiredProperties(normalizedProps, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_CLICKED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['product_id'],\n };\n}\n\n/**\n * Track when a user views a product detail page\n */\nexport function productViewed(\n properties: BaseProductProperties,\n options?: EmitterOptions,\n): EmitterTrackPayload {\n const normalizedProps = normalizeProductProperties(properties);\n validateRequiredProperties(normalizedProps, ['product_id']);\n\n const eventSpec: EcommerceEventSpec = {\n name: ECOMMERCE_EVENTS.PRODUCT_VIEWED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['product_id'],\n };\n\n return trackEcommerce(eventSpec, options);\n}\n\n/**\n * Track when a user compares products\n */\nexport function productCompared(properties: ProductComparisonProperties): EcommerceEventSpec {\n const { action, comparison_list, product } = properties;\n const normalizedProduct = normalizeProductProperties(product);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_COMPARED,\n category: 'ecommerce',\n properties: cleanProperties({\n action,\n ...normalizedProduct,\n comparison_list: comparison_list ? normalizeProducts(comparison_list) : undefined,\n }),\n requiredProperties: ['product_id'],\n };\n}\n\n/**\n * Track when product recommendations are viewed\n */\nexport function productRecommendationViewed(\n properties: RecommendationProperties,\n): EcommerceEventSpec {\n validateRequiredProperties(properties, ['recommendation_type', 'source']);\n\n const normalizedProps = {\n ...properties,\n products: normalizeProducts(properties.products),\n };\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_RECOMMENDATION_VIEWED,\n category: 'ecommerce',\n properties: cleanProperties(normalizedProps),\n requiredProperties: ['recommendation_type', 'source'],\n };\n}\n\n/**\n * Track when a recommended product is clicked\n */\nexport function productRecommendationClicked(\n properties: BaseProductProperties & {\n recommendation_type: string;\n source: string;\n position?: number;\n },\n): EcommerceEventSpec {\n const { recommendation_type, position, source, ...productProps } = properties;\n const normalizedProduct = normalizeProductProperties(productProps);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_RECOMMENDATION_CLICKED,\n category: 'ecommerce',\n properties: cleanProperties({\n ...normalizedProduct,\n recommendation_type,\n position,\n source,\n }),\n requiredProperties: ['product_id'],\n };\n}\n","/**\n * @fileoverview Universal registry events for gift registries, wishlists, and similar features\n * Universal registry events for gift registries, wishlists, and similar features\n * Uses action-based patterns for efficient tracking\n */\n\nimport {\n ECOMMERCE_EVENTS,\n type EcommerceEventSpec,\n type RegistryItemProperties,\n type RegistryProperties,\n} from '../types';\nimport { cleanProperties, normalizeProductProperties, validateRequiredProperties } from '../utils';\n\n/**\n * Track registry management actions (create, update, delete)\n */\nexport function registryManaged(\n properties: RegistryProperties & {\n action: 'created' | 'updated' | 'deleted';\n updated_fields?: string[];\n },\n): EcommerceEventSpec {\n validateRequiredProperties(properties, ['registry_id', 'action']);\n\n return {\n name: ECOMMERCE_EVENTS.REGISTRY_MANAGED,\n category: 'ecommerce',\n properties: cleanProperties(properties),\n requiredProperties: ['registry_id', 'action'],\n };\n}\n\n/**\n * Track when someone views a registry\n */\nexport function registryViewed(\n properties: RegistryProperties & {\n viewer_id?: string;\n viewer_relationship?: 'owner' | 'co_owner' | 'friend' | 'family' | 'other';\n items_count?: number;\n items_fulfilled?: number;\n },\n): EcommerceEventSpec {\n validateRequiredProperties(properties, ['registry_id']);\n\n return {\n name: ECOMMERCE_EVENTS.REGISTRY_VIEWED,\n category: 'ecommerce',\n properties: cleanProperties(properties),\n requiredProperties: ['registry_id'],\n };\n}\n\n/**\n * Track when a registry is shared\n */\nexport function registryShared(\n properties: RegistryProperties & {\n share_method: 'email' | 'social' | 'link' | 'qr_code' | 'other';\n recipients_count?: number;\n message?: string;\n },\n): EcommerceEventSpec {\n validateRequiredProperties(properties, ['registry_id', 'share_method']);\n\n return {\n name: ECOMMERCE_EVENTS.REGISTRY_SHARED,\n category: 'ecommerce',\n properties: cleanProperties(properties),\n requiredProperties: ['registry_id', 'share_method'],\n };\n}\n\n/**\n * Track registry item management (add, remove, update, purchase)\n */\nexport function registryItemManaged(\n properties: RegistryItemProperties & {\n action: 'added' | 'removed' | 'updated' | 'purchased';\n purchaser_id?: string;\n purchaser_name?: string;\n purchase_quantity?: number;\n purchase_message?: string;\n gift_wrap?: boolean;\n anonymous_gift?: boolean;\n updated_fields?: string[];\n },\n): EcommerceEventSpec {\n const {\n purchaser_id,\n registry_id,\n purchaser_name,\n action,\n anonymous_gift,\n gift_wrap,\n purchase_message,\n purchase_quantity,\n updated_fields,\n ...productProps\n } = properties;\n\n const normalizedProduct = normalizeProductProperties(productProps);\n validateRequiredProperties(properties, ['registry_id', 'product_id', 'action']);\n\n return {\n name: ECOMMERCE_EVENTS.REGISTRY_ITEM_MANAGED,\n category: 'ecommerce',\n properties: cleanProperties({\n purchaser_id,\n registry_id,\n purchaser_name,\n action,\n anonymous_gift,\n gift_wrap,\n purchase_message,\n purchase_quantity,\n updated_fields,\n ...normalizedProduct,\n }),\n requiredProperties: ['registry_id', 'product_id', 'action'],\n };\n}\n","/**\n * @fileoverview Wishlist, sharing, and review-related ecommerce events\n * Wishlist, sharing, and review-related ecommerce events\n */\n\nimport {\n type BaseProductProperties,\n type CartProperties,\n ECOMMERCE_EVENTS,\n type EcommerceEventSpec,\n type ReviewProperties,\n type SharingProperties,\n type WishlistProperties,\n} from '../types';\nimport {\n cleanProperties,\n normalizeProductProperties,\n normalizeProducts,\n validateRequiredProperties,\n} from '../utils';\n\n/**\n * Track when a product is added to wishlist\n */\nexport function productAddedToWishlist(properties: WishlistProperties): EcommerceEventSpec {\n const { wishlist_id, wishlist_name, ...productProps } = properties;\n const normalizedProduct = normalizeProductProperties(productProps);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_ADDED_TO_WISHLIST,\n category: 'ecommerce',\n properties: cleanProperties({\n wishlist_id,\n wishlist_name,\n ...normalizedProduct,\n }),\n requiredProperties: ['product_id'],\n };\n}\n\n/**\n * Track when a product is removed from wishlist\n */\nexport function productRemovedFromWishlist(properties: WishlistProperties): EcommerceEventSpec {\n const { wishlist_id, wishlist_name, ...productProps } = properties;\n const normalizedProduct = normalizeProductProperties(productProps);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_REMOVED_FROM_WISHLIST,\n category: 'ecommerce',\n properties: cleanProperties({\n wishlist_id,\n wishlist_name,\n ...normalizedProduct,\n }),\n requiredProperties: ['product_id'],\n };\n}\n\n/**\n * Track when a wishlist product is added to cart\n */\nexport function wishlistProductAddedToCart(\n properties: WishlistProperties & { cart_id?: string },\n): EcommerceEventSpec {\n const { cart_id, wishlist_id, wishlist_name, ...productProps } = properties;\n const normalizedProduct = normalizeProductProperties(productProps);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.WISHLIST_PRODUCT_ADDED_TO_CART,\n category: 'ecommerce',\n properties: cleanProperties({\n cart_id,\n wishlist_id,\n wishlist_name,\n ...normalizedProduct,\n }),\n requiredProperties: ['product_id'],\n };\n}\n\n/**\n * Track when a product is shared\n */\nexport function productShared(\n properties: BaseProductProperties & SharingProperties,\n): EcommerceEventSpec {\n const { recipient, share_message, share_via, ...productProps } = properties;\n const normalizedProduct = normalizeProductProperties(productProps);\n validateRequiredProperties(normalizedProduct, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_SHARED,\n category: 'ecommerce',\n properties: cleanProperties({\n recipient,\n share_message,\n share_via,\n ...normalizedProduct,\n }),\n requiredProperties: ['product_id'],\n };\n}\n\n/**\n * Track when a cart is shared\n */\nexport function cartShared(properties: CartProperties & SharingProperties): EcommerceEventSpec {\n const { cart_id, products, recipient, share_message, share_via } = properties;\n\n return {\n name: ECOMMERCE_EVENTS.CART_SHARED,\n category: 'ecommerce',\n properties: cleanProperties({\n cart_id,\n products: products ? normalizeProducts(products) : undefined,\n recipient,\n share_message,\n share_via,\n }),\n requiredProperties: [],\n };\n}\n\n/**\n * Track when a product is reviewed\n */\nexport function productReviewed(properties: ReviewProperties): EcommerceEventSpec {\n validateRequiredProperties(properties, ['product_id']);\n\n return {\n name: ECOMMERCE_EVENTS.PRODUCT_REVIEWED,\n category: 'ecommerce',\n properties: cleanProperties(properties),\n requiredProperties: ['product_id'],\n };\n}\n","/**\n * @fileoverview Platform-standard ecommerce events\n *\n * This module provides comprehensive ecommerce event tracking following industry\n * best practices (Segment.io ecommerce spec, Google Analytics Enhanced Ecommerce).\n *\n * **Event Categories**:\n * - **Cart & Checkout**: Add to cart, remove from cart, checkout started, checkout completed\n * - **Orders**: Order placed, order updated, order refunded, order cancelled\n * - **Products**: Product viewed, product added, product removed, product shared\n * - **Coupons**: Coupon applied, coupon removed, coupon viewed\n * - **Engagement**: Product list viewed, product list filtered, product searched\n * - **Marketplace**: Seller viewed, seller contacted, review submitted\n * - **Registry**: Registry created, registry item added, registry shared\n * - **Wishlist**: Wishlist item added, wishlist item removed, wishlist shared\n *\n * **Usage**: Import event functions and use with `analytics.emit()`:\n * ```typescript\n * import { ecommerce } from '@od-oneapp/analytics/shared';\n * await analytics.emit(ecommerce.productViewed({ productId: 'prod-123' }));\n * ```\n *\n * @module @od-oneapp/analytics/shared/emitters/ecommerce\n */\n\n// Export all types\nexport * from './types';\n\n// Export utilities\nexport * from './utils';\n\n// Export all event functions\nexport * from './events/cart-checkout';\nexport * from './events/coupon';\nexport * from './events/engagement';\nexport * from './events/marketplace';\nexport * from './events/order';\nexport * from './events/product';\nexport * from './events/registry';\nexport * from './events/wishlist-sharing';\n\n// Export tracking functionality\nexport * from './track-ecommerce';\n\n// Re-export commonly used constants for convenience\nexport { ECOMMERCE_EVENTS } from './types';\n"],"mappings":";;;;AAmOA,MAAa,mBAAmB;CAC9B,iBAAiB;CACjB,kBAAkB;CAClB,uBAAuB;CACvB,qBAAqB;CACrB,gCAAgC;CAChC,+BAA+B;CAE/B,kBAAkB;CAClB,gBAAgB;CAChB,uBAAuB;CAEvB,gBAAgB;CAEhB,cAAc;CACd,aAAa;CAGb,qBAAqB;CAErB,iBAAiB;CAEjB,iBAAiB;CACjB,cAAc;CACd,gBAAg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,SAAS,GAAG;GACnD;GACA;GACA;GACD,CAAC;EACF,oBAAoB,EAAE;EACvB;;;;;AAMH,SAAgB,gBAAgB,YAAkD;AAChF,4BAA2B,YAAY,CAAC,aAAa,CAAC;AAEtD,QAAO;EACL,MAAM,iBAAiB;EACvB,UAAU;EACV,YAAY,gBAAgB,WAAW;EACvC,oBAAoB,CAAC,aAAa;EACnC"}
@@ -0,0 +1,208 @@
1
+ //#region src/shared/emitters/emitters.ts
2
+ /**
3
+ * Identify - who is the customer?
4
+ *
5
+ * Ties a user to their actions and records traits about them. This is the core
6
+ * method for identifying users in your analytics system.
7
+ *
8
+ * **When to call**:
9
+ * - After a user first registers
10
+ * - After a user logs in
11
+ * - When a user updates their info
12
+ *
13
+ * **Reference**: https://segment.com/docs/connections/spec/identify/
14
+ *
15
+ * @param {string} userId - Unique identifier for the user in your database (required unless anonymousId is set)
16
+ * @param {UserTraits} [traits] - Free-form dictionary of traits about the user, like email or name
17
+ * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations
18
+ * @returns {EmitterIdentifyPayload} Identify payload ready to emit
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * await analytics.emit(identify('user-123', {
23
+ * email: 'user@example.com',
24
+ * name: 'John Doe'
25
+ * }));
26
+ * ```
27
+ */
28
+ function identify(userId, traits, options) {
29
+ return {
30
+ type: "identify",
31
+ userId,
32
+ ...traits && { traits },
33
+ ...options?.timestamp && { timestamp: options.timestamp },
34
+ ...options?.context && { context: options.context },
35
+ ...options?.anonymousId && { anonymousId: options.anonymousId },
36
+ ...options?.integrations && { integrations: options.integrations }
37
+ };
38
+ }
39
+ /**
40
+ * Track - what are they doing?
41
+ *
42
+ * Records any actions your users perform, along with properties that describe the action.
43
+ * This is the most common method for tracking user behavior.
44
+ *
45
+ * **Reference**: https://segment.com/docs/connections/spec/track/
46
+ *
47
+ * @param {string} event - Name of the action that a user has performed (required)
48
+ * @param {PropertyObject} [properties] - Free-form dictionary of properties of the event, like revenue
49
+ * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations
50
+ * @returns {EmitterTrackPayload} Track payload ready to emit
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * await analytics.emit(track('Button Clicked', {
55
+ * buttonName: 'Sign Up',
56
+ * location: 'header'
57
+ * }));
58
+ * ```
59
+ */
60
+ function track(event, properties, options) {
61
+ return {
62
+ type: "track",
63
+ event,
64
+ ...properties && { properties },
65
+ ...options?.timestamp && { timestamp: options.timestamp },
66
+ ...options?.context && { context: options.context },
67
+ ...options?.anonymousId && { anonymousId: options.anonymousId },
68
+ ...options?.integrations && { integrations: options.integrations },
69
+ ...options?.anonymousId && { anonymousId: options.anonymousId }
70
+ };
71
+ }
72
+ /**
73
+ * Page - what web page are they on?
74
+ *
75
+ * Records page views on your website, along with optional properties about the page.
76
+ * Automatically merges category into properties if provided.
77
+ *
78
+ * **Reference**: https://segment.com/docs/connections/spec/page/
79
+ *
80
+ * @param {string} [category] - Category of the page (optional)
81
+ * @param {string} [name] - Name of the page (optional)
82
+ * @param {PageProperties} [properties] - Free-form dictionary of properties of the page, like url and referrer
83
+ * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations
84
+ * @returns {EmitterPagePayload} Page payload ready to emit
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * await analytics.emit(page('Home', 'Landing', {
89
+ * url: 'https://example.com',
90
+ * referrer: 'https://google.com'
91
+ * }));
92
+ * ```
93
+ */
94
+ function page(category, name, properties, options) {
95
+ const mergedProperties = {
96
+ ...properties ?? {},
97
+ ...category && { category }
98
+ };
99
+ return {
100
+ type: "page",
101
+ ...name && { name },
102
+ ...Object.keys(mergedProperties).length > 0 && { properties: mergedProperties },
103
+ ...options?.timestamp && { timestamp: options.timestamp },
104
+ ...options?.context && { context: options.context },
105
+ ...options?.anonymousId && { anonymousId: options.anonymousId },
106
+ ...options?.integrations && { integrations: options.integrations }
107
+ };
108
+ }
109
+ /**
110
+ * Screen - what app screen are they on?
111
+ *
112
+ * The mobile equivalent of page, records screen views in your mobile app.
113
+ * Use this for React Native, iOS, and Android applications.
114
+ *
115
+ * **Reference**: https://segment.com/docs/connections/spec/screen/
116
+ *
117
+ * @param {string} [name] - Name of the screen (optional)
118
+ * @param {PropertyObject} [properties] - Free-form dictionary of properties of the screen
119
+ * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations
120
+ * @returns {EmitterScreenPayload} Screen payload ready to emit
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * await analytics.emit(screen('Home Screen', {
125
+ * screenType: 'main',
126
+ * userId: 'user-123'
127
+ * }));
128
+ * ```
129
+ */
130
+ function screen(name, properties, options) {
131
+ return {
132
+ type: "screen",
133
+ ...name && { name },
134
+ ...properties && { properties },
135
+ ...options?.timestamp && { timestamp: options.timestamp },
136
+ ...options?.context && { context: options.context },
137
+ ...options?.anonymousId && { anonymousId: options.anonymousId },
138
+ ...options?.integrations && { integrations: options.integrations }
139
+ };
140
+ }
141
+ /**
142
+ * Group - what account or organization are they part of?
143
+ *
144
+ * Associates an individual user with a group—a company, organization, account, project, or team.
145
+ * Useful for B2B applications where users belong to organizations.
146
+ *
147
+ * **Reference**: https://segment.com/docs/connections/spec/group/
148
+ *
149
+ * @param {string} groupId - Unique identifier for the group in your database (required)
150
+ * @param {GroupTraits} [traits] - Free-form dictionary of traits of the group, like name or industry
151
+ * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations
152
+ * @returns {EmitterGroupPayload} Group payload ready to emit
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * await analytics.emit(group('org-456', {
157
+ * name: 'Acme Corp',
158
+ * industry: 'Technology',
159
+ * plan: 'enterprise'
160
+ * }));
161
+ * ```
162
+ */
163
+ function group(groupId, traits, options) {
164
+ return {
165
+ type: "group",
166
+ groupId,
167
+ ...traits && { traits },
168
+ ...options?.timestamp && { timestamp: options.timestamp },
169
+ ...options?.context && { context: options.context },
170
+ ...options?.anonymousId && { anonymousId: options.anonymousId },
171
+ ...options?.integrations && { integrations: options.integrations }
172
+ };
173
+ }
174
+ /**
175
+ * Alias - what was their past identity?
176
+ *
177
+ * Merges two user identities, effectively connecting two sets of user data in one profile.
178
+ * This is an advanced method that should only be used when required for downstream
179
+ * destination compatibility (e.g., when a user signs up after browsing anonymously).
180
+ *
181
+ * **Reference**: https://segment.com/docs/connections/spec/alias/
182
+ *
183
+ * @param {string} userId - The user's new identity, or an existing identity to merge with previousId (required)
184
+ * @param {string} previousId - The existing ID you've referred to the user by (required)
185
+ * @param {EmitterOptions} [options] - Optional fields like timestamp, context, integrations
186
+ * @returns {EmitterAliasPayload} Alias payload ready to emit
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * // When anonymous user signs up
191
+ * await analytics.emit(alias('user-123', 'anonymous-456'));
192
+ * ```
193
+ */
194
+ function alias(userId, previousId, options) {
195
+ return {
196
+ type: "alias",
197
+ previousId,
198
+ userId,
199
+ ...options?.timestamp && { timestamp: options.timestamp },
200
+ ...options?.context && { context: options.context },
201
+ ...options?.anonymousId && { anonymousId: options.anonymousId },
202
+ ...options?.integrations && { integrations: options.integrations }
203
+ };
204
+ }
205
+
206
+ //#endregion
207
+ export { screen as a, page as i, group as n, track as o, identify as r, alias as t };
208
+ //# sourceMappingURL=emitters-6-nKo8i-.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitters-6-nKo8i-.mjs","names":[],"sources":["../src/shared/emitters/emitters.ts"],"sourcesContent":["/**\n * @fileoverview Core analytics emitter functions following Segment.io specification\n *\n * This module provides type-safe emitter functions that return event payloads following\n * the Segment.io specification. These payloads can be passed to `analytics.emit()` or\n * `analytics.track()` for tracking.\n *\n * **Emitter Functions**:\n * - `identify()`: Identify users with traits\n * - `track()`: Track custom events\n * - `page()`: Track page views\n * - `screen()`: Track screen views (mobile)\n * - `group()`: Associate users with groups\n * - `alias()`: Alias user IDs\n *\n * **Benefits**:\n * - Type-safe event tracking\n * - Consistent with Segment.io spec\n * - Can be composed and batched\n * - Works with all analytics providers\n *\n * **Reference**: https://segment.com/docs/connections/spec/\n *\n * @module @od-oneapp/analytics/shared/emitters\n */\n\nimport type {\n EmitterAliasPayload,\n EmitterGroupPayload,\n EmitterIdentifyPayload,\n EmitterOptions,\n EmitterPagePayload,\n EmitterScreenPayload,\n EmitterTrackPayload,\n} from './emitter-types';\nimport type { GroupTraits, PageProperties, PropertyObject, UserTraits } from '../types/types';\n\n/**\n * Identify - who is the customer?\n *\n * Ties a user to their actions and records traits about them. This is the core\n * method for identifying users in your analytics system.\n *\n * **When to call**:\n * - After a user first registers\n * - After a user logs in\n * - When a user updates their info\n *\n * **Reference**: https://segment.com/docs/connections/spec/identify/\n *\n * @param {string} userId - Unique identifier for the user in your database (required unless anonymousId is set)\n * @param {UserTraits} [traits] - Free-form dictionary of traits about the user, like email or name\n * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations\n * @returns {EmitterIdentifyPayload} Identify payload ready to emit\n *\n * @example\n * ```typescript\n * await analytics.emit(identify('user-123', {\n * email: 'user@example.com',\n * name: 'John Doe'\n * }));\n * ```\n */\nexport function identify(\n userId: string,\n traits?: UserTraits,\n options?: EmitterOptions,\n): EmitterIdentifyPayload {\n const payload: EmitterIdentifyPayload = {\n type: 'identify',\n userId,\n ...(traits && { traits }),\n ...(options?.timestamp && { timestamp: options.timestamp }),\n ...(options?.context && { context: options.context }),\n ...(options?.anonymousId && { anonymousId: options.anonymousId }),\n ...(options?.integrations && { integrations: options.integrations }),\n };\n\n return payload;\n}\n\n/**\n * Track - what are they doing?\n *\n * Records any actions your users perform, along with properties that describe the action.\n * This is the most common method for tracking user behavior.\n *\n * **Reference**: https://segment.com/docs/connections/spec/track/\n *\n * @param {string} event - Name of the action that a user has performed (required)\n * @param {PropertyObject} [properties] - Free-form dictionary of properties of the event, like revenue\n * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations\n * @returns {EmitterTrackPayload} Track payload ready to emit\n *\n * @example\n * ```typescript\n * await analytics.emit(track('Button Clicked', {\n * buttonName: 'Sign Up',\n * location: 'header'\n * }));\n * ```\n */\nexport function track(\n event: string,\n properties?: PropertyObject,\n options?: EmitterOptions,\n): EmitterTrackPayload {\n const payload: EmitterTrackPayload = {\n type: 'track',\n event,\n ...(properties && { properties }),\n ...(options?.timestamp && { timestamp: options.timestamp }),\n ...(options?.context && { context: options.context }),\n ...(options?.anonymousId && { anonymousId: options.anonymousId }),\n ...(options?.integrations && { integrations: options.integrations }),\n ...(options?.anonymousId && { anonymousId: options.anonymousId }),\n };\n\n // userId should be passed through the main function params or via options\n\n return payload;\n}\n\n/**\n * Page - what web page are they on?\n *\n * Records page views on your website, along with optional properties about the page.\n * Automatically merges category into properties if provided.\n *\n * **Reference**: https://segment.com/docs/connections/spec/page/\n *\n * @param {string} [category] - Category of the page (optional)\n * @param {string} [name] - Name of the page (optional)\n * @param {PageProperties} [properties] - Free-form dictionary of properties of the page, like url and referrer\n * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations\n * @returns {EmitterPagePayload} Page payload ready to emit\n *\n * @example\n * ```typescript\n * await analytics.emit(page('Home', 'Landing', {\n * url: 'https://example.com',\n * referrer: 'https://google.com'\n * }));\n * ```\n */\nexport function page(\n category?: string,\n name?: string,\n properties?: PageProperties,\n options?: EmitterOptions,\n): EmitterPagePayload {\n // Merge category into properties if provided\n const mergedProperties = {\n ...(properties ?? {}),\n ...(category && { category }),\n };\n\n const payload: EmitterPagePayload = {\n type: 'page',\n ...(name && { name }),\n ...(Object.keys(mergedProperties).length > 0 && { properties: mergedProperties }),\n ...(options?.timestamp && { timestamp: options.timestamp }),\n ...(options?.context && { context: options.context }),\n ...(options?.anonymousId && { anonymousId: options.anonymousId }),\n ...(options?.integrations && { integrations: options.integrations }),\n };\n\n // userId should be passed through the main function params or via options\n\n return payload;\n}\n\n/**\n * Screen - what app screen are they on?\n *\n * The mobile equivalent of page, records screen views in your mobile app.\n * Use this for React Native, iOS, and Android applications.\n *\n * **Reference**: https://segment.com/docs/connections/spec/screen/\n *\n * @param {string} [name] - Name of the screen (optional)\n * @param {PropertyObject} [properties] - Free-form dictionary of properties of the screen\n * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations\n * @returns {EmitterScreenPayload} Screen payload ready to emit\n *\n * @example\n * ```typescript\n * await analytics.emit(screen('Home Screen', {\n * screenType: 'main',\n * userId: 'user-123'\n * }));\n * ```\n */\nexport function screen(\n name?: string,\n properties?: PropertyObject,\n options?: EmitterOptions,\n): EmitterScreenPayload {\n const payload: EmitterScreenPayload = {\n type: 'screen',\n ...(name && { name }),\n ...(properties && { properties }),\n ...(options?.timestamp && { timestamp: options.timestamp }),\n ...(options?.context && { context: options.context }),\n ...(options?.anonymousId && { anonymousId: options.anonymousId }),\n ...(options?.integrations && { integrations: options.integrations }),\n };\n\n // userId should be passed through the main function params or via options\n\n return payload;\n}\n\n/**\n * Group - what account or organization are they part of?\n *\n * Associates an individual user with a group—a company, organization, account, project, or team.\n * Useful for B2B applications where users belong to organizations.\n *\n * **Reference**: https://segment.com/docs/connections/spec/group/\n *\n * @param {string} groupId - Unique identifier for the group in your database (required)\n * @param {GroupTraits} [traits] - Free-form dictionary of traits of the group, like name or industry\n * @param {EmitterOptions} [options] - Optional fields like timestamp, anonymousId, context, integrations\n * @returns {EmitterGroupPayload} Group payload ready to emit\n *\n * @example\n * ```typescript\n * await analytics.emit(group('org-456', {\n * name: 'Acme Corp',\n * industry: 'Technology',\n * plan: 'enterprise'\n * }));\n * ```\n */\nexport function group(\n groupId: string,\n traits?: GroupTraits,\n options?: EmitterOptions,\n): EmitterGroupPayload {\n const payload: EmitterGroupPayload = {\n type: 'group',\n groupId,\n ...(traits && { traits }),\n ...(options?.timestamp && { timestamp: options.timestamp }),\n ...(options?.context && { context: options.context }),\n ...(options?.anonymousId && { anonymousId: options.anonymousId }),\n ...(options?.integrations && { integrations: options.integrations }),\n };\n\n // userId should be passed through the main function params or via options\n\n return payload;\n}\n\n/**\n * Alias - what was their past identity?\n *\n * Merges two user identities, effectively connecting two sets of user data in one profile.\n * This is an advanced method that should only be used when required for downstream\n * destination compatibility (e.g., when a user signs up after browsing anonymously).\n *\n * **Reference**: https://segment.com/docs/connections/spec/alias/\n *\n * @param {string} userId - The user's new identity, or an existing identity to merge with previousId (required)\n * @param {string} previousId - The existing ID you've referred to the user by (required)\n * @param {EmitterOptions} [options] - Optional fields like timestamp, context, integrations\n * @returns {EmitterAliasPayload} Alias payload ready to emit\n *\n * @example\n * ```typescript\n * // When anonymous user signs up\n * await analytics.emit(alias('user-123', 'anonymous-456'));\n * ```\n */\nexport function alias(\n userId: string,\n previousId: string,\n options?: EmitterOptions,\n): EmitterAliasPayload {\n const payload: EmitterAliasPayload = {\n type: 'alias',\n previousId,\n userId,\n ...(options?.timestamp && { timestamp: options.timestamp }),\n ...(options?.context && { context: options.context }),\n ...(options?.anonymousId && { anonymousId: options.anonymousId }),\n ...(options?.integrations && { integrations: options.integrations }),\n };\n\n return payload;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,SACd,QACA,QACA,SACwB;AAWxB,QAVwC;EACtC,MAAM;EACN;EACA,GAAI,UAAU,EAAE,QAAQ;EACxB,GAAI,SAAS,aAAa,EAAE,WAAW,QAAQ,WAAW;EAC1D,GAAI,SAAS,WAAW,EAAE,SAAS,QAAQ,SAAS;EACpD,GAAI,SAAS,eAAe,EAAE,aAAa,QAAQ,aAAa;EAChE,GAAI,SAAS,gBAAgB,EAAE,cAAc,QAAQ,cAAc;EACpE;;;;;;;;;;;;;;;;;;;;;;;AA0BH,SAAgB,MACd,OACA,YACA,SACqB;AAcrB,QAbqC;EACnC,MAAM;EACN;EACA,GAAI,cAAc,EAAE,YAAY;EAChC,GAAI,SAAS,aAAa,EAAE,WAAW,QAAQ,WAAW;EAC1D,GAAI,SAAS,WAAW,EAAE,SAAS,QAAQ,SAAS;EACpD,GAAI,SAAS,e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,QAAQ,aAAa;EAChE,GAAI,SAAS,gBAAgB,EAAE,cAAc,QAAQ,cAAc;EACpE;;;;;;;;;;;;;;;;;;;;;;AA2BH,SAAgB,MACd,QACA,YACA,SACqB;AAWrB,QAVqC;EACnC,MAAM;EACN;EACA;EACA,GAAI,SAAS,aAAa,EAAE,WAAW,QAAQ,WAAW;EAC1D,GAAI,SAAS,WAAW,EAAE,SAAS,QAAQ,SAAS;EACpD,GAAI,SAAS,eAAe,EAAE,aAAa,QAAQ,aAAa;EAChE,GAAI,SAAS,gBAAgB,EAAE,cAAc,QAAQ,cAAc;EACpE"}
@@ -0,0 +1,12 @@
1
+ import { A as GroupTraits, C as EmitterPagePayload, D as EmitterTrackPayload, E as EmitterScreenPayload, F as UserTraits, N as PropertyObject, S as EmitterOptions, b as EmitterIdentifyPayload, j as PageProperties, p as EmitterAliasPayload, v as EmitterGroupPayload } from "./types-BxBnNQ0V.mjs";
2
+
3
+ //#region src/shared/emitters/emitters.d.ts
4
+ declare function identify(userId: string, traits?: UserTraits, options?: EmitterOptions): EmitterIdentifyPayload;
5
+ declare function track(event: string, properties?: PropertyObject, options?: EmitterOptions): EmitterTrackPayload;
6
+ declare function page(category?: string, name?: string, properties?: PageProperties, options?: EmitterOptions): EmitterPagePayload;
7
+ declare function screen(name?: string, properties?: PropertyObject, options?: EmitterOptions): EmitterScreenPayload;
8
+ declare function group(groupId: string, traits?: GroupTraits, options?: EmitterOptions): EmitterGroupPayload;
9
+ declare function alias(userId: string, previousId: string, options?: EmitterOptions): EmitterAliasPayload;
10
+ //#endregion
11
+ export { screen as a, page as i, group as n, track as o, identify as r, alias as t };
12
+ //# sourceMappingURL=emitters-DldkVSPp.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitters-DldkVSPp.d.mts","names":[],"sources":["../src/shared/emitters/emitters.ts"],"mappings":";;;iBA+DgB,QAAA,CACd,MAAA,UACA,MAAA,GAAS,UAAA,EACT,OAAA,GAAU,cAAA,GACT,sBAAA;AAAA,iBAmCa,KAAA,CACd,KAAA,UACA,UAAA,GAAa,cAAA,EACb,OAAA,GAAU,cAAA,GACT,mBAAA;AAAA,iBAuCa,IAAA,CACd,QAAA,WACA,IAAA,WACA,UAAA,GAAa,cAAA,EACb,OAAA,GAAU,cAAA,GACT,kBAAA;AAAA,iBA2Ca,MAAA,CACd,IAAA,WACA,UAAA,GAAa,cAAA,EACb,OAAA,GAAU,cAAA,GACT,oBAAA;AAAA,iBAsCa,KAAA,CACd,OAAA,UACA,MAAA,GAAS,WAAA,EACT,OAAA,GAAU,cAAA,GACT,mBAAA;AAAA,iBAoCa,KAAA,CACd,MAAA,UACA,UAAA,UACA,OAAA,GAAU,cAAA,GACT,mBAAA"}