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