@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,144 @@
1
+ /**
2
+ * @fileoverview Client-side Next.js analytics exports
3
+ * Client-side Next.js analytics exports
4
+ * Complete Next.js 15 integration for client components and browser environments
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import {
9
+ * createNextJSClientAnalytics,
10
+ * usePageTracking,
11
+ * useTrackEvent,
12
+ * track
13
+ * } from '@od-oneapp/analytics/client/next';
14
+ *
15
+ * // Create Next.js optimized analytics
16
+ * const analytics = createNextJSClientAnalytics({
17
+ * providers: { segment: { writeKey: 'xxx' } },
18
+ * nextjs: { strategy: 'afterInteractive', bufferEvents: true }
19
+ * });
20
+ *
21
+ * // Use in client components
22
+ * function MyComponent() {
23
+ * const trackEvent = useTrackEvent();
24
+ * usePageTracking(); // Auto page tracking
25
+ *
26
+ * return <button onClick={() => trackEvent('Button Clicked', { color: 'blue' })}>
27
+ * Click me
28
+ * </button>;
29
+ * }
30
+ * ```
31
+ */
32
+
33
+ // ============================================================================
34
+ // CORE CLIENT ANALYTICS (re-export everything from client)
35
+ // ============================================================================
36
+
37
+ // Re-export everything from client for convenience
38
+ export * from '.';
39
+
40
+ // ============================================================================
41
+ // NEXT.JS CLIENT COMPONENTS & HOOKS
42
+ // ============================================================================
43
+
44
+ export {
45
+ // Context providers
46
+ AnalyticsProvider,
47
+ // Tracked components
48
+ TrackedButton,
49
+ TrackedLink,
50
+ useAnalytics,
51
+ // React hooks for client components
52
+ usePageTracking,
53
+ useTrackEvent,
54
+ } from '../next/app-router';
55
+
56
+ // Note: Export types only if they exist in the app-router module
57
+ // Many of these types may not be implemented yet
58
+
59
+ // ============================================================================
60
+ // NEXT.JS CLIENT ANALYTICS MANAGER
61
+ // ============================================================================
62
+
63
+ export {
64
+ // Next.js client analytics manager
65
+ NextJSClientAnalyticsManager,
66
+ createNextJSClientAnalytics,
67
+ // PostHog bootstrap helpers
68
+ createPostHogConfigWithBootstrap,
69
+
70
+ // Script integration helpers
71
+ getAnalyticsScriptProps,
72
+ } from '../next/client';
73
+
74
+ export type { NextJSClientAnalyticsConfig } from '../next/client';
75
+
76
+ // ============================================================================
77
+ // NEXT.JS TYPES
78
+ // ============================================================================
79
+
80
+ // Note: Next.js types exports have been moved to avoid non-existent type errors
81
+ // Import the actual types from their respective modules as needed
82
+
83
+ // ============================================================================
84
+ // USAGE EXAMPLES & PATTERNS
85
+ // ============================================================================
86
+
87
+ /**
88
+ * Example usage patterns for client-side Next.js analytics
89
+ *
90
+ * @example Basic setup in layout.tsx
91
+ * ```typescript
92
+ * 'use client';
93
+ * import { AnalyticsProvider, usePageTracking } from '@od-oneapp/analytics/client/next';
94
+ *
95
+ * function RootLayoutContent({ children }) {
96
+ * usePageTracking(); // Auto page tracking
97
+ * return <>{children}</>;
98
+ * }
99
+ *
100
+ * export default function RootLayout({ children }) {
101
+ * return (
102
+ * <AnalyticsProvider config={{
103
+ * providers: {
104
+ * segment: { writeKey: process.env.NEXT_PUBLIC_SEGMENT_WRITE_KEY }
105
+ * }
106
+ * }}>
107
+ * <RootLayoutContent>{children}</RootLayoutContent>
108
+ * </AnalyticsProvider>
109
+ * );
110
+ * }
111
+ * ```
112
+ *
113
+ * @example Event tracking in components
114
+ * ```typescript
115
+ * 'use client';
116
+ * import { useTrackEvent, track } from '@od-oneapp/analytics/client/next';
117
+ *
118
+ * function MyComponent() {
119
+ * const trackEvent = useTrackEvent();
120
+ *
121
+ * const handleClick = () => {
122
+ * trackEvent('Button Clicked', { location: 'hero' });
123
+ * };
124
+ *
125
+ * return <button onClick={handleClick}>Click me</button>;
126
+ * }
127
+ * ```
128
+ *
129
+ * @example Feature flags
130
+ * ```typescript
131
+ * 'use client';
132
+ * import { useFeatureFlag } from '@od-oneapp/analytics/client/next';
133
+ *
134
+ * function FeatureComponent() {
135
+ * const showNewFeature = useFeatureFlag('new-feature');
136
+ *
137
+ * return (
138
+ * <div>
139
+ * {showNewFeature ? <NewFeature /> : <OldFeature />}
140
+ * </div>
141
+ * );
142
+ * }
143
+ * ```
144
+ */
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @fileoverview Next.js client exports
3
+ *
4
+ * This module provides Next.js-specific client-side analytics functionality.
5
+ * It exports:
6
+ *
7
+ * - **Analytics Managers**: `createNextJSClientAnalytics()`, `createNextJSClientAnalyticsUninitialized()`
8
+ * - **React Hooks**: `useAnalytics()`, `usePageTracking()`, `useTrackEvent()`, `useIdentifyUser()`
9
+ * - **React Components**: `AnalyticsProvider`, `TrackedButton`, `TrackedLink`, `withViewTracking()`
10
+ * - **Emitters**: Type-safe event tracking functions
11
+ * - **Ecommerce Emitters**: Comprehensive ecommerce event tracking
12
+ * - **AI Emitters**: AI product analytics tracking
13
+ * - **Configuration**: Client-safe configuration utilities
14
+ * - **PostHog Utilities**: Bootstrap data and cookie utilities
15
+ *
16
+ * **Usage**: Import from `@od-oneapp/analytics/client/next` for Next.js client components.
17
+ *
18
+ * @module @od-oneapp/analytics/client/next
19
+ */
20
+
21
+ 'use client';
22
+
23
+ // Export Next.js specific analytics manager
24
+ export {
25
+ createNextJSClientAnalytics,
26
+ createNextJSClientAnalyticsUninitialized,
27
+ } from './client/next/manager';
28
+
29
+ // Export Next.js hooks
30
+ export {
31
+ resetAnalytics,
32
+ useAnalytics,
33
+ useIdentifyUser,
34
+ usePageTracking,
35
+ useTrackEvent,
36
+ } from './client/next/hooks';
37
+
38
+ // Export Next.js components
39
+ export {
40
+ AnalyticsProvider,
41
+ TrackedButton,
42
+ TrackedLink,
43
+ withViewTracking,
44
+ } from './client/next/components';
45
+
46
+ // Export all emitters - these are the preferred way to track events
47
+ export {
48
+ // Emitter utilities
49
+ ContextBuilder,
50
+ EventBatch,
51
+ PayloadBuilder,
52
+ alias,
53
+ createAnonymousSession,
54
+ createUserSession,
55
+ // Ecommerce emitters namespace
56
+ ecommerce,
57
+ group,
58
+ // Core Segment.io spec emitters
59
+ identify,
60
+ isAliasPayload,
61
+ isGroupPayload,
62
+ isIdentifyPayload,
63
+ isPagePayload,
64
+ // Type guards
65
+ isTrackPayload,
66
+ page,
67
+ screen,
68
+ track,
69
+ withMetadata,
70
+ withUTM,
71
+ } from './shared/emitters';
72
+
73
+ // Export adapter utilities
74
+ export {
75
+ createEmitterProcessor,
76
+ // Emitter processing utilities
77
+ processEmitterPayload,
78
+ trackEcommerceEvent,
79
+ } from './shared/utils/emitter-adapter';
80
+
81
+ // Export client-safe configuration utilities
82
+ export {
83
+ PROVIDER_REQUIREMENTS,
84
+ createConfigBuilder,
85
+ getAnalyticsConfig,
86
+ validateConfig,
87
+ } from './shared/utils/config-client';
88
+
89
+ // Validation utilities removed - validation should happen on the server side only
90
+ // This follows the four-file export pattern to avoid importing server-only dependencies
91
+
92
+ // Export PostHog utilities
93
+ export {
94
+ createBootstrapData,
95
+ createMinimalBootstrapData,
96
+ generateDistinctId,
97
+ getDistinctIdFromCookies,
98
+ } from './shared/utils/posthog-bootstrap';
99
+
100
+ // Export types
101
+ export type * from './types';
package/src/client.ts ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @fileoverview Client exports for browser environments (non-Next.js)
3
+ *
4
+ * This module provides client-side analytics functionality for non-Next.js browser
5
+ * environments. It exports:
6
+ *
7
+ * - **Analytics Managers**: `createClientAnalytics()`, `createClientAnalyticsUninitialized()`
8
+ * - **Emitters**: Type-safe event tracking functions (track, identify, page, screen, group, alias)
9
+ * - **Ecommerce Emitters**: Comprehensive ecommerce event tracking
10
+ * - **AI Emitters**: AI product analytics tracking
11
+ * - **Emitter Utilities**: ContextBuilder, EventBatch, PayloadBuilder
12
+ * - **Adapter Utilities**: Emitter processing and ecommerce event tracking
13
+ * - **Configuration**: Client-safe configuration utilities
14
+ * - **Validation**: Client-safe validation utilities
15
+ * - **PostHog Utilities**: Bootstrap data and distinct ID generation
16
+ *
17
+ * **Usage**: Import from `@od-oneapp/analytics/client` for browser-only applications.
18
+ * For Next.js applications, use `@od-oneapp/analytics/client/next` instead.
19
+ *
20
+ * @module @od-oneapp/analytics/client
21
+ */
22
+
23
+ // Export core client functions
24
+ export { createClientAnalytics, createClientAnalyticsUninitialized } from './client/manager';
25
+
26
+ // Export all emitters - these are the preferred way to track events
27
+ export {
28
+ // Emitter utilities
29
+ ContextBuilder,
30
+ EventBatch,
31
+ PayloadBuilder,
32
+ // AI emitters namespace
33
+ aiSdk as ai,
34
+ alias,
35
+ createAnonymousSession,
36
+ createUserSession,
37
+ // Ecommerce emitters namespace
38
+ ecommerce,
39
+ group,
40
+ // Core Segment.io spec emitters
41
+ identify,
42
+ isAliasPayload,
43
+ isGroupPayload,
44
+ isIdentifyPayload,
45
+ isPagePayload,
46
+ // Type guards
47
+ isTrackPayload,
48
+ page,
49
+ screen,
50
+ track,
51
+ withMetadata,
52
+ withUTM,
53
+ } from './shared/emitters';
54
+
55
+ // Export adapter utilities
56
+ export {
57
+ createEmitterProcessor,
58
+ // Emitter processing utilities
59
+ processEmitterPayload,
60
+ trackEcommerceEvent,
61
+ } from './shared/utils/emitter-adapter';
62
+
63
+ // Export client-safe configuration utilities
64
+ export {
65
+ PROVIDER_REQUIREMENTS,
66
+ createConfigBuilder,
67
+ getAnalyticsConfig,
68
+ validateConfig,
69
+ } from './shared/utils/config-client';
70
+
71
+ // Export client-safe validation utilities
72
+ export { validateAnalyticsConfig, validateProvider } from './shared/utils/validation-client';
73
+
74
+ // Export manager utilities
75
+ export {
76
+ AnalyticsManager as AnalyticsManagerClass,
77
+ createAnalyticsManager,
78
+ } from './shared/utils/manager';
79
+
80
+ // Export PostHog utilities
81
+ export {
82
+ createBootstrapData,
83
+ createMinimalBootstrapData,
84
+ generateDistinctId,
85
+ getDistinctIdFromCookies,
86
+ } from './shared/utils/posthog-bootstrap';
87
+
88
+ // Export types
89
+ export type * from './types';