aurea-tracking-sdk 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -2,6 +2,13 @@
2
2
  * Aurea Tracking SDK
3
3
  * Standalone tracking SDK for external funnels
4
4
  */
5
+ type EventCategory = 'viewing' | 'engagement' | 'intent' | 'conversion' | 'custom' | string;
6
+ interface EventCategoryConfig {
7
+ category: EventCategory;
8
+ advanceTo?: string;
9
+ value?: number;
10
+ description?: string;
11
+ }
5
12
  interface AureaConfig {
6
13
  apiKey: string;
7
14
  funnelId: string;
@@ -17,6 +24,51 @@ interface AureaConfig {
17
24
  anonymizeIp?: boolean;
18
25
  batchSize?: number;
19
26
  batchInterval?: number;
27
+ eventCategories?: {
28
+ [eventName: string]: EventCategoryConfig;
29
+ };
30
+ autoAdvanceStages?: boolean;
31
+ customStages?: string[];
32
+ }
33
+ interface TrackingEvent {
34
+ eventId: string;
35
+ eventName: string;
36
+ properties?: Record<string, any>;
37
+ context: {
38
+ page?: {
39
+ url: string;
40
+ path: string;
41
+ title?: string;
42
+ referrer?: string;
43
+ };
44
+ utm?: {
45
+ source?: string;
46
+ medium?: string;
47
+ campaign?: string;
48
+ term?: string;
49
+ content?: string;
50
+ };
51
+ user?: {
52
+ userId?: string;
53
+ anonymousId?: string;
54
+ };
55
+ session: {
56
+ sessionId: string;
57
+ };
58
+ device?: {
59
+ userAgent?: string;
60
+ deviceType?: string;
61
+ browserName?: string;
62
+ browserVersion?: string;
63
+ osName?: string;
64
+ osVersion?: string;
65
+ screenWidth?: number;
66
+ screenHeight?: number;
67
+ language?: string;
68
+ timezone?: string;
69
+ };
70
+ };
71
+ timestamp: number;
20
72
  }
21
73
  interface ConversionData {
22
74
  type: string;
@@ -25,6 +77,38 @@ interface ConversionData {
25
77
  orderId?: string;
26
78
  properties?: Record<string, any>;
27
79
  }
80
+ type FunnelStage = 'awareness' | 'interest' | 'desire' | 'checkout' | 'purchase' | 'abandoned' | string;
81
+ interface CheckoutProduct {
82
+ productId: string;
83
+ productName?: string;
84
+ price: number;
85
+ currency?: string;
86
+ quantity?: number;
87
+ variant?: string;
88
+ }
89
+ interface CheckoutCompletedData {
90
+ orderId: string;
91
+ revenue: number;
92
+ currency?: string;
93
+ products?: CheckoutProduct[];
94
+ paymentMethod?: string;
95
+ }
96
+ interface MicroConversion {
97
+ type: string;
98
+ value: number;
99
+ properties?: Record<string, any>;
100
+ }
101
+ interface CheckoutContext {
102
+ originalSessionId: string;
103
+ anonymousId: string;
104
+ checkoutStartedAt: number;
105
+ product: CheckoutProduct;
106
+ currentStage: FunnelStage;
107
+ priorStages: FunnelStage[];
108
+ utmSource?: string;
109
+ utmCampaign?: string;
110
+ utmMedium?: string;
111
+ }
28
112
  declare class AureaSDK {
29
113
  private config;
30
114
  private sessionId;
@@ -39,6 +123,12 @@ declare class AureaSDK {
39
123
  private lastActiveTimestamp;
40
124
  private isPageVisible;
41
125
  private webVitalsCollected;
126
+ private currentStage;
127
+ private stageHistory;
128
+ private microConversions;
129
+ private isInCheckout;
130
+ private checkoutStartedAt?;
131
+ private eventCategoryStats;
42
132
  constructor(config: AureaConfig);
43
133
  /**
44
134
  * Initialize the SDK
@@ -60,6 +150,120 @@ declare class AureaSDK {
60
150
  * Track a conversion event
61
151
  */
62
152
  conversion(data: ConversionData): void;
153
+ /**
154
+ * Register custom event categories
155
+ * Allows users to define their own event categorization and auto-stage progression
156
+ *
157
+ * @example
158
+ * aurea.registerEventCategories({
159
+ * 'video_started': {
160
+ * category: 'engagement',
161
+ * advanceTo: 'interest',
162
+ * value: 30,
163
+ * description: 'User started watching sales video'
164
+ * },
165
+ * 'pricing_viewed': {
166
+ * category: 'intent',
167
+ * advanceTo: 'desire',
168
+ * value: 60
169
+ * },
170
+ * 'buy_button_clicked': {
171
+ * category: 'conversion',
172
+ * value: 90
173
+ * }
174
+ * })
175
+ */
176
+ registerEventCategories(categories: {
177
+ [eventName: string]: EventCategoryConfig;
178
+ }): void;
179
+ /**
180
+ * Track a categorized event with automatic stage progression
181
+ * This is the recommended way to track events - user defines their own event names
182
+ *
183
+ * @param eventName - User-defined event name (e.g., 'video_started', 'pricing_clicked')
184
+ * @param properties - Additional event properties
185
+ * @param options - Override category/value/stage for this specific event
186
+ *
187
+ * @example
188
+ * // Using pre-registered category
189
+ * aurea.trackEvent('video_started', { duration: 120 })
190
+ *
191
+ * // One-off event with inline category
192
+ * aurea.trackEvent('custom_action', { foo: 'bar' }, {
193
+ * category: 'engagement',
194
+ * value: 40,
195
+ * advanceTo: 'interest'
196
+ * })
197
+ */
198
+ trackEvent(eventName: string, properties?: Record<string, any>, options?: {
199
+ category?: EventCategory;
200
+ value?: number;
201
+ advanceTo?: FunnelStage;
202
+ description?: string;
203
+ }): void;
204
+ /**
205
+ * Get current event category statistics
206
+ */
207
+ getCategoryStats(): Record<EventCategory, number>;
208
+ /**
209
+ * Get current funnel stage
210
+ */
211
+ getCurrentStage(): FunnelStage;
212
+ /**
213
+ * Get stage history
214
+ */
215
+ getStageHistory(): Array<{
216
+ stage: FunnelStage;
217
+ enteredAt: number;
218
+ durationMs?: number;
219
+ }>;
220
+ /**
221
+ * Enter a new funnel stage
222
+ */
223
+ enterStage(stage: FunnelStage): void;
224
+ /**
225
+ * Track micro-conversion (engagement signals)
226
+ *
227
+ * @deprecated Use trackEvent() instead for more flexibility
228
+ * This method is kept for backward compatibility
229
+ *
230
+ * @param type - Type of micro-conversion (e.g., 'video_played', 'faq_opened')
231
+ * @param value - Impact score 0-100 (how strong this signal is)
232
+ * @param properties - Additional metadata
233
+ * @param autoAdvanceStage - Whether to automatically advance funnel stage (default: true)
234
+ */
235
+ trackMicroConversion(type: string, value?: number, properties?: Record<string, any>, autoAdvanceStage?: boolean): void;
236
+ /**
237
+ * Determine suggested funnel stage based on micro-conversion type
238
+ * This uses common patterns to automatically progress users through the funnel
239
+ */
240
+ private getSuggestedStageFromMicroConversion;
241
+ /**
242
+ * Get funnel stage order for comparison
243
+ */
244
+ private getFunnelStageOrder;
245
+ /**
246
+ * Track checkout started (user clicked buy button)
247
+ * This DOES NOT end the session - preserves context for when user returns
248
+ */
249
+ checkoutStarted(product: CheckoutProduct): void;
250
+ /**
251
+ * Track checkout completed (purchase successful)
252
+ * Links back to original session if user returned from external checkout
253
+ */
254
+ checkoutCompleted(data: CheckoutCompletedData): void;
255
+ /**
256
+ * Track checkout abandoned (user left without completing)
257
+ */
258
+ checkoutAbandoned(reason?: string): void;
259
+ /**
260
+ * Get time spent in a specific stage (in seconds)
261
+ */
262
+ private getTimeInCurrentStage;
263
+ /**
264
+ * Get UTM parameter from current URL
265
+ */
266
+ private getUTMParam;
63
267
  /**
64
268
  * Get or create session ID
65
269
  */
@@ -125,6 +329,11 @@ declare class AureaSDK {
125
329
  * Track session timing (active time, duration)
126
330
  */
127
331
  private trackSessionTiming;
332
+ /**
333
+ * Initialize funnel tracking
334
+ * Checks for returning checkout users and sets initial stage
335
+ */
336
+ private initializeFunnelTracking;
128
337
  /**
129
338
  * Generate unique ID
130
339
  */
@@ -159,4 +368,4 @@ declare function trackConversion(data: ConversionData): void;
159
368
  */
160
369
  declare function trackPage(name?: string, properties?: Record<string, any>): void;
161
370
 
162
- export { getAurea, identifyUser, initAurea, trackConversion, trackEvent, trackPage };
371
+ export { type AureaConfig, AureaSDK, type CheckoutCompletedData, type CheckoutContext, type CheckoutProduct, type ConversionData, type EventCategory, type EventCategoryConfig, type FunnelStage, type MicroConversion, type TrackingEvent, getAurea, identifyUser, initAurea, trackConversion, trackEvent, trackPage };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,13 @@
2
2
  * Aurea Tracking SDK
3
3
  * Standalone tracking SDK for external funnels
4
4
  */
5
+ type EventCategory = 'viewing' | 'engagement' | 'intent' | 'conversion' | 'custom' | string;
6
+ interface EventCategoryConfig {
7
+ category: EventCategory;
8
+ advanceTo?: string;
9
+ value?: number;
10
+ description?: string;
11
+ }
5
12
  interface AureaConfig {
6
13
  apiKey: string;
7
14
  funnelId: string;
@@ -17,6 +24,51 @@ interface AureaConfig {
17
24
  anonymizeIp?: boolean;
18
25
  batchSize?: number;
19
26
  batchInterval?: number;
27
+ eventCategories?: {
28
+ [eventName: string]: EventCategoryConfig;
29
+ };
30
+ autoAdvanceStages?: boolean;
31
+ customStages?: string[];
32
+ }
33
+ interface TrackingEvent {
34
+ eventId: string;
35
+ eventName: string;
36
+ properties?: Record<string, any>;
37
+ context: {
38
+ page?: {
39
+ url: string;
40
+ path: string;
41
+ title?: string;
42
+ referrer?: string;
43
+ };
44
+ utm?: {
45
+ source?: string;
46
+ medium?: string;
47
+ campaign?: string;
48
+ term?: string;
49
+ content?: string;
50
+ };
51
+ user?: {
52
+ userId?: string;
53
+ anonymousId?: string;
54
+ };
55
+ session: {
56
+ sessionId: string;
57
+ };
58
+ device?: {
59
+ userAgent?: string;
60
+ deviceType?: string;
61
+ browserName?: string;
62
+ browserVersion?: string;
63
+ osName?: string;
64
+ osVersion?: string;
65
+ screenWidth?: number;
66
+ screenHeight?: number;
67
+ language?: string;
68
+ timezone?: string;
69
+ };
70
+ };
71
+ timestamp: number;
20
72
  }
21
73
  interface ConversionData {
22
74
  type: string;
@@ -25,6 +77,38 @@ interface ConversionData {
25
77
  orderId?: string;
26
78
  properties?: Record<string, any>;
27
79
  }
80
+ type FunnelStage = 'awareness' | 'interest' | 'desire' | 'checkout' | 'purchase' | 'abandoned' | string;
81
+ interface CheckoutProduct {
82
+ productId: string;
83
+ productName?: string;
84
+ price: number;
85
+ currency?: string;
86
+ quantity?: number;
87
+ variant?: string;
88
+ }
89
+ interface CheckoutCompletedData {
90
+ orderId: string;
91
+ revenue: number;
92
+ currency?: string;
93
+ products?: CheckoutProduct[];
94
+ paymentMethod?: string;
95
+ }
96
+ interface MicroConversion {
97
+ type: string;
98
+ value: number;
99
+ properties?: Record<string, any>;
100
+ }
101
+ interface CheckoutContext {
102
+ originalSessionId: string;
103
+ anonymousId: string;
104
+ checkoutStartedAt: number;
105
+ product: CheckoutProduct;
106
+ currentStage: FunnelStage;
107
+ priorStages: FunnelStage[];
108
+ utmSource?: string;
109
+ utmCampaign?: string;
110
+ utmMedium?: string;
111
+ }
28
112
  declare class AureaSDK {
29
113
  private config;
30
114
  private sessionId;
@@ -39,6 +123,12 @@ declare class AureaSDK {
39
123
  private lastActiveTimestamp;
40
124
  private isPageVisible;
41
125
  private webVitalsCollected;
126
+ private currentStage;
127
+ private stageHistory;
128
+ private microConversions;
129
+ private isInCheckout;
130
+ private checkoutStartedAt?;
131
+ private eventCategoryStats;
42
132
  constructor(config: AureaConfig);
43
133
  /**
44
134
  * Initialize the SDK
@@ -60,6 +150,120 @@ declare class AureaSDK {
60
150
  * Track a conversion event
61
151
  */
62
152
  conversion(data: ConversionData): void;
153
+ /**
154
+ * Register custom event categories
155
+ * Allows users to define their own event categorization and auto-stage progression
156
+ *
157
+ * @example
158
+ * aurea.registerEventCategories({
159
+ * 'video_started': {
160
+ * category: 'engagement',
161
+ * advanceTo: 'interest',
162
+ * value: 30,
163
+ * description: 'User started watching sales video'
164
+ * },
165
+ * 'pricing_viewed': {
166
+ * category: 'intent',
167
+ * advanceTo: 'desire',
168
+ * value: 60
169
+ * },
170
+ * 'buy_button_clicked': {
171
+ * category: 'conversion',
172
+ * value: 90
173
+ * }
174
+ * })
175
+ */
176
+ registerEventCategories(categories: {
177
+ [eventName: string]: EventCategoryConfig;
178
+ }): void;
179
+ /**
180
+ * Track a categorized event with automatic stage progression
181
+ * This is the recommended way to track events - user defines their own event names
182
+ *
183
+ * @param eventName - User-defined event name (e.g., 'video_started', 'pricing_clicked')
184
+ * @param properties - Additional event properties
185
+ * @param options - Override category/value/stage for this specific event
186
+ *
187
+ * @example
188
+ * // Using pre-registered category
189
+ * aurea.trackEvent('video_started', { duration: 120 })
190
+ *
191
+ * // One-off event with inline category
192
+ * aurea.trackEvent('custom_action', { foo: 'bar' }, {
193
+ * category: 'engagement',
194
+ * value: 40,
195
+ * advanceTo: 'interest'
196
+ * })
197
+ */
198
+ trackEvent(eventName: string, properties?: Record<string, any>, options?: {
199
+ category?: EventCategory;
200
+ value?: number;
201
+ advanceTo?: FunnelStage;
202
+ description?: string;
203
+ }): void;
204
+ /**
205
+ * Get current event category statistics
206
+ */
207
+ getCategoryStats(): Record<EventCategory, number>;
208
+ /**
209
+ * Get current funnel stage
210
+ */
211
+ getCurrentStage(): FunnelStage;
212
+ /**
213
+ * Get stage history
214
+ */
215
+ getStageHistory(): Array<{
216
+ stage: FunnelStage;
217
+ enteredAt: number;
218
+ durationMs?: number;
219
+ }>;
220
+ /**
221
+ * Enter a new funnel stage
222
+ */
223
+ enterStage(stage: FunnelStage): void;
224
+ /**
225
+ * Track micro-conversion (engagement signals)
226
+ *
227
+ * @deprecated Use trackEvent() instead for more flexibility
228
+ * This method is kept for backward compatibility
229
+ *
230
+ * @param type - Type of micro-conversion (e.g., 'video_played', 'faq_opened')
231
+ * @param value - Impact score 0-100 (how strong this signal is)
232
+ * @param properties - Additional metadata
233
+ * @param autoAdvanceStage - Whether to automatically advance funnel stage (default: true)
234
+ */
235
+ trackMicroConversion(type: string, value?: number, properties?: Record<string, any>, autoAdvanceStage?: boolean): void;
236
+ /**
237
+ * Determine suggested funnel stage based on micro-conversion type
238
+ * This uses common patterns to automatically progress users through the funnel
239
+ */
240
+ private getSuggestedStageFromMicroConversion;
241
+ /**
242
+ * Get funnel stage order for comparison
243
+ */
244
+ private getFunnelStageOrder;
245
+ /**
246
+ * Track checkout started (user clicked buy button)
247
+ * This DOES NOT end the session - preserves context for when user returns
248
+ */
249
+ checkoutStarted(product: CheckoutProduct): void;
250
+ /**
251
+ * Track checkout completed (purchase successful)
252
+ * Links back to original session if user returned from external checkout
253
+ */
254
+ checkoutCompleted(data: CheckoutCompletedData): void;
255
+ /**
256
+ * Track checkout abandoned (user left without completing)
257
+ */
258
+ checkoutAbandoned(reason?: string): void;
259
+ /**
260
+ * Get time spent in a specific stage (in seconds)
261
+ */
262
+ private getTimeInCurrentStage;
263
+ /**
264
+ * Get UTM parameter from current URL
265
+ */
266
+ private getUTMParam;
63
267
  /**
64
268
  * Get or create session ID
65
269
  */
@@ -125,6 +329,11 @@ declare class AureaSDK {
125
329
  * Track session timing (active time, duration)
126
330
  */
127
331
  private trackSessionTiming;
332
+ /**
333
+ * Initialize funnel tracking
334
+ * Checks for returning checkout users and sets initial stage
335
+ */
336
+ private initializeFunnelTracking;
128
337
  /**
129
338
  * Generate unique ID
130
339
  */
@@ -159,4 +368,4 @@ declare function trackConversion(data: ConversionData): void;
159
368
  */
160
369
  declare function trackPage(name?: string, properties?: Record<string, any>): void;
161
370
 
162
- export { getAurea, identifyUser, initAurea, trackConversion, trackEvent, trackPage };
371
+ export { type AureaConfig, AureaSDK, type CheckoutCompletedData, type CheckoutContext, type CheckoutProduct, type ConversionData, type EventCategory, type EventCategoryConfig, type FunnelStage, type MicroConversion, type TrackingEvent, getAurea, identifyUser, initAurea, trackConversion, trackEvent, trackPage };