alphana-sdk 1.1.1 → 1.5.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
@@ -84,12 +84,32 @@ interface GeoLocation {
84
84
  latitude?: number;
85
85
  longitude?: number;
86
86
  }
87
+ interface UtmParams {
88
+ source?: string;
89
+ medium?: string;
90
+ campaign?: string;
91
+ term?: string;
92
+ content?: string;
93
+ }
94
+ interface AttributionContext {
95
+ landingPage: string;
96
+ referrer?: string;
97
+ referrerHost?: string;
98
+ utm?: UtmParams;
99
+ clickIds?: Record<string, string>;
100
+ capturedAt: number;
101
+ }
87
102
  interface PageView {
88
103
  path: string;
89
104
  title: string;
90
105
  timestamp: number;
91
106
  sessionId: string;
92
107
  referrer?: string;
108
+ utm?: UtmParams;
109
+ attribution?: {
110
+ firstTouch?: AttributionContext;
111
+ lastTouch?: AttributionContext;
112
+ };
93
113
  }
94
114
  interface TimeSpent {
95
115
  path: string;
@@ -136,6 +156,67 @@ interface UTurn {
136
156
  timestamp: number;
137
157
  sessionId: string;
138
158
  }
159
+ type UserProperties = Record<string, string>;
160
+ interface IdentifyEvent {
161
+ properties: UserProperties;
162
+ visitorId: string;
163
+ timestamp: number;
164
+ }
165
+ type RevenueEventStatus = "pending" | "paid" | "refunded" | "cancelled" | "failed";
166
+ interface RevenueLineItem {
167
+ id?: string;
168
+ name?: string;
169
+ category?: string;
170
+ quantity?: number;
171
+ price?: number;
172
+ }
173
+ interface RevenueEventPayload {
174
+ eventName?: "purchase" | "subscription" | "renewal" | "upgrade" | "refund" | string;
175
+ amount: number;
176
+ currency: string;
177
+ transactionId?: string;
178
+ orderId?: string;
179
+ productId?: string;
180
+ planId?: string;
181
+ coupon?: string;
182
+ status?: RevenueEventStatus;
183
+ items?: RevenueLineItem[];
184
+ metadata?: Record<string, string | number | boolean | null>;
185
+ }
186
+ interface RevenueEvent extends RevenueEventPayload {
187
+ sessionId: string;
188
+ visitorId: string;
189
+ timestamp: number;
190
+ attribution?: {
191
+ firstTouch?: AttributionContext;
192
+ lastTouch?: AttributionContext;
193
+ };
194
+ }
195
+ interface GoalEventPayload {
196
+ key: string;
197
+ name?: string;
198
+ value?: number;
199
+ currency?: string;
200
+ metadata?: Record<string, string | number | boolean | null>;
201
+ }
202
+ interface GoalEvent extends GoalEventPayload {
203
+ sessionId: string;
204
+ visitorId: string;
205
+ path: string;
206
+ timestamp: number;
207
+ }
208
+ interface JourneyStepEventPayload {
209
+ key: string;
210
+ label?: string;
211
+ path?: string;
212
+ metadata?: Record<string, string | number | boolean | null>;
213
+ }
214
+ interface JourneyStepEvent extends JourneyStepEventPayload {
215
+ sessionId: string;
216
+ visitorId: string;
217
+ path: string;
218
+ timestamp: number;
219
+ }
139
220
  /**
140
221
  * One-time (or rare) snapshot of the client environment for a session.
141
222
  * Lets the backend align device / OS / browser with what the browser reports
@@ -181,6 +262,18 @@ type TrackerEvent = {
181
262
  } | {
182
263
  type: "uturn";
183
264
  data: UTurn;
265
+ } | {
266
+ type: "identify";
267
+ data: IdentifyEvent;
268
+ } | {
269
+ type: "revenue";
270
+ data: RevenueEvent;
271
+ } | {
272
+ type: "goal";
273
+ data: GoalEvent;
274
+ } | {
275
+ type: "journey_step";
276
+ data: JourneyStepEvent;
184
277
  } | {
185
278
  type: "client_context";
186
279
  data: ClientContext;
@@ -198,6 +291,13 @@ interface SessionData {
198
291
  timeSpent: Record<string, number>;
199
292
  /** Collected points per path */
200
293
  heatmap: Record<string, HeatmapPoint[]>;
294
+ /** Latest properties supplied through identify(). */
295
+ userProperties: UserProperties;
296
+ /** First and latest marketing touchpoints captured for this visitor. */
297
+ attribution?: {
298
+ firstTouch?: AttributionContext;
299
+ lastTouch?: AttributionContext;
300
+ };
201
301
  /** Approximate visitor location resolved from IP (filled asynchronously) */
202
302
  location?: GeoLocation;
203
303
  }
@@ -288,6 +388,8 @@ declare class UserTracker {
288
388
  private abVariants;
289
389
  private readonly abTestSubscribers;
290
390
  constructor(config?: TrackerConfig);
391
+ private updateAttributionForPageView;
392
+ private currentAttribution;
291
393
  /**
292
394
  * Attach event listeners and start tracking.
293
395
  * Safe to call during SSR — returns `this` immediately if `window` is
@@ -332,6 +434,16 @@ declare class UserTracker {
332
434
  * ```
333
435
  */
334
436
  trackPageView(path?: string): void;
437
+ /**
438
+ * Track a monetary conversion such as a purchase, subscription, renewal,
439
+ * upgrade, or refund. Revenue events include the current attribution context
440
+ * so the backend can credit campaigns without recomputing browser state.
441
+ */
442
+ trackRevenue(payload: RevenueEventPayload): void;
443
+ /** Track a business goal such as signup, trial_start, lead, or checkout_start. */
444
+ trackGoal(payload: GoalEventPayload): void;
445
+ /** Track a named product journey milestone beyond automatic pageviews. */
446
+ trackJourneyStep(payload: JourneyStepEventPayload): void;
335
447
  /**
336
448
  * Identify the current user with a set of properties.
337
449
  * Properties are merged with any previously set ones and used for feature
@@ -430,4 +542,4 @@ declare const ALPHANA_SDK_VERSION = "1.0.2";
430
542
  */
431
543
  declare function normalizeTrackerPath(path: string): string;
432
544
 
433
- export { ALPHANA_SDK_VERSION, type AbVariantsMap, type ClientContext, DEFAULT_ENDPOINT, type GeoLocation, type HeatmapPoint, type HeatmapRenderOptions, LogCapture, type LogEntry, type LogLevel, type PageView, type RageClick, type SessionData, type TimeSpent, type TrackerConfig, type TrackerEvent, type UTurn, UserTracker, normalizeTrackerPath };
545
+ export { ALPHANA_SDK_VERSION, type AbVariantsMap, type AttributionContext, type ClientContext, DEFAULT_ENDPOINT, type GeoLocation, type GoalEvent, type GoalEventPayload, type HeatmapPoint, type HeatmapRenderOptions, type JourneyStepEvent, type JourneyStepEventPayload, LogCapture, type LogEntry, type LogLevel, type PageView, type RageClick, type RevenueEvent, type RevenueEventPayload, type RevenueEventStatus, type RevenueLineItem, type SessionData, type TimeSpent, type TrackerConfig, type TrackerEvent, type UTurn, UserTracker, type UtmParams, normalizeTrackerPath };
package/dist/index.d.ts CHANGED
@@ -84,12 +84,32 @@ interface GeoLocation {
84
84
  latitude?: number;
85
85
  longitude?: number;
86
86
  }
87
+ interface UtmParams {
88
+ source?: string;
89
+ medium?: string;
90
+ campaign?: string;
91
+ term?: string;
92
+ content?: string;
93
+ }
94
+ interface AttributionContext {
95
+ landingPage: string;
96
+ referrer?: string;
97
+ referrerHost?: string;
98
+ utm?: UtmParams;
99
+ clickIds?: Record<string, string>;
100
+ capturedAt: number;
101
+ }
87
102
  interface PageView {
88
103
  path: string;
89
104
  title: string;
90
105
  timestamp: number;
91
106
  sessionId: string;
92
107
  referrer?: string;
108
+ utm?: UtmParams;
109
+ attribution?: {
110
+ firstTouch?: AttributionContext;
111
+ lastTouch?: AttributionContext;
112
+ };
93
113
  }
94
114
  interface TimeSpent {
95
115
  path: string;
@@ -136,6 +156,67 @@ interface UTurn {
136
156
  timestamp: number;
137
157
  sessionId: string;
138
158
  }
159
+ type UserProperties = Record<string, string>;
160
+ interface IdentifyEvent {
161
+ properties: UserProperties;
162
+ visitorId: string;
163
+ timestamp: number;
164
+ }
165
+ type RevenueEventStatus = "pending" | "paid" | "refunded" | "cancelled" | "failed";
166
+ interface RevenueLineItem {
167
+ id?: string;
168
+ name?: string;
169
+ category?: string;
170
+ quantity?: number;
171
+ price?: number;
172
+ }
173
+ interface RevenueEventPayload {
174
+ eventName?: "purchase" | "subscription" | "renewal" | "upgrade" | "refund" | string;
175
+ amount: number;
176
+ currency: string;
177
+ transactionId?: string;
178
+ orderId?: string;
179
+ productId?: string;
180
+ planId?: string;
181
+ coupon?: string;
182
+ status?: RevenueEventStatus;
183
+ items?: RevenueLineItem[];
184
+ metadata?: Record<string, string | number | boolean | null>;
185
+ }
186
+ interface RevenueEvent extends RevenueEventPayload {
187
+ sessionId: string;
188
+ visitorId: string;
189
+ timestamp: number;
190
+ attribution?: {
191
+ firstTouch?: AttributionContext;
192
+ lastTouch?: AttributionContext;
193
+ };
194
+ }
195
+ interface GoalEventPayload {
196
+ key: string;
197
+ name?: string;
198
+ value?: number;
199
+ currency?: string;
200
+ metadata?: Record<string, string | number | boolean | null>;
201
+ }
202
+ interface GoalEvent extends GoalEventPayload {
203
+ sessionId: string;
204
+ visitorId: string;
205
+ path: string;
206
+ timestamp: number;
207
+ }
208
+ interface JourneyStepEventPayload {
209
+ key: string;
210
+ label?: string;
211
+ path?: string;
212
+ metadata?: Record<string, string | number | boolean | null>;
213
+ }
214
+ interface JourneyStepEvent extends JourneyStepEventPayload {
215
+ sessionId: string;
216
+ visitorId: string;
217
+ path: string;
218
+ timestamp: number;
219
+ }
139
220
  /**
140
221
  * One-time (or rare) snapshot of the client environment for a session.
141
222
  * Lets the backend align device / OS / browser with what the browser reports
@@ -181,6 +262,18 @@ type TrackerEvent = {
181
262
  } | {
182
263
  type: "uturn";
183
264
  data: UTurn;
265
+ } | {
266
+ type: "identify";
267
+ data: IdentifyEvent;
268
+ } | {
269
+ type: "revenue";
270
+ data: RevenueEvent;
271
+ } | {
272
+ type: "goal";
273
+ data: GoalEvent;
274
+ } | {
275
+ type: "journey_step";
276
+ data: JourneyStepEvent;
184
277
  } | {
185
278
  type: "client_context";
186
279
  data: ClientContext;
@@ -198,6 +291,13 @@ interface SessionData {
198
291
  timeSpent: Record<string, number>;
199
292
  /** Collected points per path */
200
293
  heatmap: Record<string, HeatmapPoint[]>;
294
+ /** Latest properties supplied through identify(). */
295
+ userProperties: UserProperties;
296
+ /** First and latest marketing touchpoints captured for this visitor. */
297
+ attribution?: {
298
+ firstTouch?: AttributionContext;
299
+ lastTouch?: AttributionContext;
300
+ };
201
301
  /** Approximate visitor location resolved from IP (filled asynchronously) */
202
302
  location?: GeoLocation;
203
303
  }
@@ -288,6 +388,8 @@ declare class UserTracker {
288
388
  private abVariants;
289
389
  private readonly abTestSubscribers;
290
390
  constructor(config?: TrackerConfig);
391
+ private updateAttributionForPageView;
392
+ private currentAttribution;
291
393
  /**
292
394
  * Attach event listeners and start tracking.
293
395
  * Safe to call during SSR — returns `this` immediately if `window` is
@@ -332,6 +434,16 @@ declare class UserTracker {
332
434
  * ```
333
435
  */
334
436
  trackPageView(path?: string): void;
437
+ /**
438
+ * Track a monetary conversion such as a purchase, subscription, renewal,
439
+ * upgrade, or refund. Revenue events include the current attribution context
440
+ * so the backend can credit campaigns without recomputing browser state.
441
+ */
442
+ trackRevenue(payload: RevenueEventPayload): void;
443
+ /** Track a business goal such as signup, trial_start, lead, or checkout_start. */
444
+ trackGoal(payload: GoalEventPayload): void;
445
+ /** Track a named product journey milestone beyond automatic pageviews. */
446
+ trackJourneyStep(payload: JourneyStepEventPayload): void;
335
447
  /**
336
448
  * Identify the current user with a set of properties.
337
449
  * Properties are merged with any previously set ones and used for feature
@@ -430,4 +542,4 @@ declare const ALPHANA_SDK_VERSION = "1.0.2";
430
542
  */
431
543
  declare function normalizeTrackerPath(path: string): string;
432
544
 
433
- export { ALPHANA_SDK_VERSION, type AbVariantsMap, type ClientContext, DEFAULT_ENDPOINT, type GeoLocation, type HeatmapPoint, type HeatmapRenderOptions, LogCapture, type LogEntry, type LogLevel, type PageView, type RageClick, type SessionData, type TimeSpent, type TrackerConfig, type TrackerEvent, type UTurn, UserTracker, normalizeTrackerPath };
545
+ export { ALPHANA_SDK_VERSION, type AbVariantsMap, type AttributionContext, type ClientContext, DEFAULT_ENDPOINT, type GeoLocation, type GoalEvent, type GoalEventPayload, type HeatmapPoint, type HeatmapRenderOptions, type JourneyStepEvent, type JourneyStepEventPayload, LogCapture, type LogEntry, type LogLevel, type PageView, type RageClick, type RevenueEvent, type RevenueEventPayload, type RevenueEventStatus, type RevenueLineItem, type SessionData, type TimeSpent, type TrackerConfig, type TrackerEvent, type UTurn, UserTracker, type UtmParams, normalizeTrackerPath };