getu-attribution-v2-sdk 0.2.1 โ 0.2.3
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/README.md +209 -13
- package/dist/core/AttributionSDK.d.ts +23 -0
- package/dist/core/AttributionSDK.d.ts.map +1 -1
- package/dist/core/AttributionSDK.js +90 -3
- package/dist/getuai-attribution.min.js +1 -1
- package/dist/index.d.ts +51 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +338 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +338 -4
- package/dist/storage/index.d.ts +8 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +121 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ A JavaScript SDK for tracking user attribution and conversion events in web appl
|
|
|
8
8
|
- [Installation](#installation)
|
|
9
9
|
- [Quick Start](#quick-start)
|
|
10
10
|
- [Configuration](#configuration)
|
|
11
|
+
- [User ID Management](#user-id-management)
|
|
11
12
|
- [Event Tracking](#event-tracking)
|
|
12
13
|
- [Auto-Tracking](#auto-tracking)
|
|
13
14
|
- [SPA Support](#spa-support)
|
|
@@ -23,18 +24,18 @@ A JavaScript SDK for tracking user attribution and conversion events in web appl
|
|
|
23
24
|
|
|
24
25
|
## Features
|
|
25
26
|
|
|
26
|
-
| Feature | Description
|
|
27
|
-
| ------------------------- |
|
|
28
|
-
| ๐ฏ **UTM Tracking** | Automatic capture and storage of UTM parameters from URLs
|
|
29
|
-
| ๐ **Cross-Domain UTM** | Automatic UTM parameter passing to external links
|
|
30
|
-
| ๐ฆ **Event Batching** | Efficient batch processing of events with configurable intervals
|
|
31
|
-
| ๐ด **Offline Support** | Queue events locally when offline, sync when connection restores
|
|
32
|
-
| ๐ **SPA Support** | Automatic page view tracking for Single Page Applications
|
|
33
|
-
| โก **Immediate Events** | Critical events (purchase, login, signup) sent immediately
|
|
34
|
-
| ๐ **Session Management** | Tracks user sessions with configurable timeout
|
|
35
|
-
| ๐งน **Auto Clean UTM** | Removes UTM parameters from URL after capture
|
|
36
|
-
| ๐ **Page View Debounce** | Prevents duplicate page view events within configurable interval
|
|
37
|
-
| ๐ **TypeScript** | Full TypeScript support with type definitions
|
|
27
|
+
| Feature | Description |
|
|
28
|
+
| ------------------------- | -------------------------------------------------------------------------- |
|
|
29
|
+
| ๐ฏ **UTM Tracking** | Automatic capture and storage of UTM parameters from URLs |
|
|
30
|
+
| ๐ **Cross-Domain UTM** | Automatic UTM parameter passing to external links |
|
|
31
|
+
| ๐ฆ **Event Batching** | Efficient batch processing of events with configurable intervals |
|
|
32
|
+
| ๐ด **Offline Support** | Queue events locally when offline, sync when connection restores |
|
|
33
|
+
| ๐ **SPA Support** | Automatic page view tracking for Single Page Applications |
|
|
34
|
+
| โก **Immediate Events** | Critical events (purchase, login, signup, audit approved) sent immediately |
|
|
35
|
+
| ๐ **Session Management** | Tracks user sessions with configurable timeout |
|
|
36
|
+
| ๐งน **Auto Clean UTM** | Removes UTM parameters from URL after capture |
|
|
37
|
+
| ๐ **Page View Debounce** | Prevents duplicate page view events within configurable interval |
|
|
38
|
+
| ๐ **TypeScript** | Full TypeScript support with type definitions |
|
|
38
39
|
|
|
39
40
|
---
|
|
40
41
|
|
|
@@ -104,6 +105,7 @@ await trackPageView({ category: "homepage" });
|
|
|
104
105
|
| `data-batch-size` | number | `100` | Number of events per batch |
|
|
105
106
|
| `data-batch-interval` | number | `2000` | Batch interval in milliseconds |
|
|
106
107
|
| `data-auto-clean-utm` | boolean | `true` | Remove UTM params from URL after capture |
|
|
108
|
+
| `data-user-id` | string | - | Initial user ID |
|
|
107
109
|
|
|
108
110
|
### Configuration Object
|
|
109
111
|
|
|
@@ -139,6 +141,9 @@ interface SDKConfig {
|
|
|
139
141
|
// Page View
|
|
140
142
|
pageViewDebounceInterval?: number; // Default: 5000 (ms) - Debounce interval for same page
|
|
141
143
|
|
|
144
|
+
// User ID
|
|
145
|
+
userId?: string; // Initial user ID to set on initialization
|
|
146
|
+
|
|
142
147
|
// Debug
|
|
143
148
|
enableDebug?: boolean; // Default: false
|
|
144
149
|
}
|
|
@@ -162,12 +167,83 @@ await init({
|
|
|
162
167
|
excludeDomains: ["google.com", "facebook.com"],
|
|
163
168
|
autoCleanUTM: true,
|
|
164
169
|
pageViewDebounceInterval: 3000,
|
|
170
|
+
userId: "user_123", // Optional: Set initial user ID
|
|
165
171
|
enableDebug: true,
|
|
166
172
|
});
|
|
167
173
|
```
|
|
168
174
|
|
|
169
175
|
---
|
|
170
176
|
|
|
177
|
+
## User ID Management
|
|
178
|
+
|
|
179
|
+
The SDK automatically manages user IDs and includes them in all tracked events.
|
|
180
|
+
|
|
181
|
+
### Setting User ID
|
|
182
|
+
|
|
183
|
+
#### During Initialization
|
|
184
|
+
|
|
185
|
+
You can set the user ID when initializing the SDK:
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
// Via script tag
|
|
189
|
+
<script
|
|
190
|
+
src="https://unpkg.com/getu-attribution-v2-sdk/dist/getuai-attribution.min.js"
|
|
191
|
+
data-api-key="your_api_key_here"
|
|
192
|
+
data-user-id="user_123"
|
|
193
|
+
></script>;
|
|
194
|
+
|
|
195
|
+
// Via configuration object
|
|
196
|
+
await init({
|
|
197
|
+
apiKey: "your_api_key_here",
|
|
198
|
+
userId: "user_123",
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### Programmatically Set User ID
|
|
203
|
+
|
|
204
|
+
You can set or update the user ID at any time:
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
import { setUserId } from "getu-attribution-v2-sdk";
|
|
208
|
+
|
|
209
|
+
// Set user ID (e.g., after user login)
|
|
210
|
+
setUserId("user_123");
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Getting User ID
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
import { getUserId } from "getu-attribution-v2-sdk";
|
|
217
|
+
|
|
218
|
+
const userId = getUserId();
|
|
219
|
+
console.log("Current user ID:", userId); // "user_123" or null
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Removing User ID
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
import { removeUserId } from "getu-attribution-v2-sdk";
|
|
226
|
+
|
|
227
|
+
// Remove user ID (e.g., after user logout)
|
|
228
|
+
removeUserId();
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Automatic Inclusion in Events
|
|
232
|
+
|
|
233
|
+
Once a user ID is set, it will **automatically be included** in all tracked events, even if you don't explicitly pass it:
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
// User ID is already set via setUserId("user_123")
|
|
237
|
+
|
|
238
|
+
// This will automatically include user_123 in the event
|
|
239
|
+
await trackPageView({ category: "homepage" });
|
|
240
|
+
|
|
241
|
+
// Explicit user ID parameter will override the stored one
|
|
242
|
+
await trackPageView({ category: "homepage" }, "different_user_456");
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
171
247
|
## Event Tracking
|
|
172
248
|
|
|
173
249
|
### Event Types
|
|
@@ -193,6 +269,9 @@ enum EventType {
|
|
|
193
269
|
PRODUCT_VIEW = "product_view",
|
|
194
270
|
ADD_TO_CART = "add_to_cart",
|
|
195
271
|
PURCHASE = "purchase",
|
|
272
|
+
|
|
273
|
+
// Post-conversion / back-office conversion
|
|
274
|
+
AUDIT_APPROVED = "audit_approved",
|
|
196
275
|
}
|
|
197
276
|
```
|
|
198
277
|
|
|
@@ -205,6 +284,7 @@ These events are sent immediately (not batched):
|
|
|
205
284
|
- `SIGNUP`
|
|
206
285
|
- `FORM_SUBMIT`
|
|
207
286
|
- `EMAIL_VERIFICATION`
|
|
287
|
+
- `AUDIT_APPROVED`
|
|
208
288
|
|
|
209
289
|
### Track Page View
|
|
210
290
|
|
|
@@ -239,9 +319,11 @@ await trackPageClick("user_123", {
|
|
|
239
319
|
|
|
240
320
|
### Track Purchase
|
|
241
321
|
|
|
322
|
+
**Method 1: Traditional format (user_id required)**
|
|
323
|
+
|
|
242
324
|
```javascript
|
|
243
325
|
await trackPurchase(
|
|
244
|
-
"user_123", // tracking_user_id
|
|
326
|
+
"user_123", // tracking_user_id (required)
|
|
245
327
|
99.99, // revenue
|
|
246
328
|
Currency.USD, // currency (optional, default: USD)
|
|
247
329
|
{
|
|
@@ -253,8 +335,33 @@ await trackPurchase(
|
|
|
253
335
|
);
|
|
254
336
|
```
|
|
255
337
|
|
|
338
|
+
**Method 2: Auto user ID format (object parameter, user_id optional)**
|
|
339
|
+
|
|
340
|
+
```javascript
|
|
341
|
+
// Auto-use stored user ID
|
|
342
|
+
await trackPurchaseAuto({
|
|
343
|
+
revenue: 99.99,
|
|
344
|
+
currency: Currency.USD, // optional
|
|
345
|
+
purchaseData: {
|
|
346
|
+
product_id: "prod_123",
|
|
347
|
+
product_name: "Premium Plan",
|
|
348
|
+
quantity: 1,
|
|
349
|
+
},
|
|
350
|
+
// tracking_user_id is optional - will use stored user ID if not provided
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// Or explicitly provide user ID
|
|
354
|
+
await trackPurchaseAuto({
|
|
355
|
+
revenue: 99.99,
|
|
356
|
+
tracking_user_id: "user_123", // optional, will use stored if not provided
|
|
357
|
+
purchaseData: { product_id: "prod_123" },
|
|
358
|
+
});
|
|
359
|
+
```
|
|
360
|
+
|
|
256
361
|
### Track Login
|
|
257
362
|
|
|
363
|
+
**Method 1: Traditional format (user_id required)**
|
|
364
|
+
|
|
258
365
|
```javascript
|
|
259
366
|
await trackLogin("user_123", {
|
|
260
367
|
method: "email",
|
|
@@ -262,8 +369,29 @@ await trackLogin("user_123", {
|
|
|
262
369
|
});
|
|
263
370
|
```
|
|
264
371
|
|
|
372
|
+
**Method 2: Auto user ID format (object parameter, user_id optional)**
|
|
373
|
+
|
|
374
|
+
```javascript
|
|
375
|
+
// Auto-use stored user ID
|
|
376
|
+
await trackLoginAuto({
|
|
377
|
+
loginData: {
|
|
378
|
+
method: "email",
|
|
379
|
+
provider: "google",
|
|
380
|
+
},
|
|
381
|
+
// tracking_user_id is optional - will use stored user ID if not provided
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// Or explicitly provide user ID
|
|
385
|
+
await trackLoginAuto({
|
|
386
|
+
tracking_user_id: "user_123", // optional
|
|
387
|
+
loginData: { method: "email" },
|
|
388
|
+
});
|
|
389
|
+
```
|
|
390
|
+
|
|
265
391
|
### Track Signup
|
|
266
392
|
|
|
393
|
+
**Method 1: Traditional format (user_id required)**
|
|
394
|
+
|
|
267
395
|
```javascript
|
|
268
396
|
await trackSignup("user_123", {
|
|
269
397
|
method: "email",
|
|
@@ -271,6 +399,25 @@ await trackSignup("user_123", {
|
|
|
271
399
|
});
|
|
272
400
|
```
|
|
273
401
|
|
|
402
|
+
**Method 2: Auto user ID format (object parameter, user_id optional)**
|
|
403
|
+
|
|
404
|
+
```javascript
|
|
405
|
+
// Auto-use stored user ID
|
|
406
|
+
await trackSignupAuto({
|
|
407
|
+
signupData: {
|
|
408
|
+
method: "email",
|
|
409
|
+
referral_code: "REF123",
|
|
410
|
+
},
|
|
411
|
+
// tracking_user_id is optional - will use stored user ID if not provided
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// Or explicitly provide user ID
|
|
415
|
+
await trackSignupAuto({
|
|
416
|
+
tracking_user_id: "user_123", // optional
|
|
417
|
+
signupData: { method: "email" },
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
274
421
|
### Track Form Submit
|
|
275
422
|
|
|
276
423
|
```javascript
|
|
@@ -300,6 +447,8 @@ await trackVideoPlay("user_123", {
|
|
|
300
447
|
|
|
301
448
|
### Track Email Verification
|
|
302
449
|
|
|
450
|
+
**Method 1: Traditional format (user_id required)**
|
|
451
|
+
|
|
303
452
|
```javascript
|
|
304
453
|
await trackEmailVerification("user_123", {
|
|
305
454
|
email: "user@example.com",
|
|
@@ -307,6 +456,53 @@ await trackEmailVerification("user_123", {
|
|
|
307
456
|
});
|
|
308
457
|
```
|
|
309
458
|
|
|
459
|
+
**Method 2: Auto user ID format (object parameter, user_id optional)**
|
|
460
|
+
|
|
461
|
+
```javascript
|
|
462
|
+
// Auto-use stored user ID
|
|
463
|
+
await trackEmailVerificationAuto({
|
|
464
|
+
verificationData: {
|
|
465
|
+
email: "user@example.com",
|
|
466
|
+
verification_method: "email_link",
|
|
467
|
+
},
|
|
468
|
+
// tracking_user_id is optional - will use stored user ID if not provided
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// Or explicitly provide user ID
|
|
472
|
+
await trackEmailVerificationAuto({
|
|
473
|
+
tracking_user_id: "user_123", // optional
|
|
474
|
+
verificationData: { email: "user@example.com" },
|
|
475
|
+
});
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### Track Audit Approved
|
|
479
|
+
|
|
480
|
+
Track an audit approval conversion event. **Sent immediately.**
|
|
481
|
+
|
|
482
|
+
```javascript
|
|
483
|
+
import { trackAuditApproved } from "getu-attribution-v2-sdk";
|
|
484
|
+
|
|
485
|
+
await trackAuditApproved("user_123", {
|
|
486
|
+
audit_id: "audit_987",
|
|
487
|
+
reviewer: "ops_team",
|
|
488
|
+
});
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### Auto User ID Functions Summary
|
|
492
|
+
|
|
493
|
+
The following functions support auto user ID with object parameter format:
|
|
494
|
+
|
|
495
|
+
- `trackPurchaseAuto(options)` - Purchase tracking with optional user ID
|
|
496
|
+
- `trackLoginAuto(options)` - Login tracking with optional user ID
|
|
497
|
+
- `trackSignupAuto(options)` - Signup tracking with optional user ID
|
|
498
|
+
- `trackEmailVerificationAuto(options)` - Email verification tracking with optional user ID
|
|
499
|
+
|
|
500
|
+
**Important Notes:**
|
|
501
|
+
|
|
502
|
+
- If `tracking_user_id` is not provided in options and no user ID is stored, these functions will log an error and return without tracking the event
|
|
503
|
+
- Always set user ID using `setUserId()` before calling these functions, or provide `tracking_user_id` in the options
|
|
504
|
+
- The traditional functions (`trackPurchase`, `trackLogin`, etc.) still require `tracking_user_id` as the first parameter
|
|
505
|
+
|
|
310
506
|
### Track Product View
|
|
311
507
|
|
|
312
508
|
```javascript
|
|
@@ -26,6 +26,25 @@ export declare class AttributionSDK {
|
|
|
26
26
|
trackFormSubmit(tracking_user_id?: string, formData?: Record<string, any>): Promise<void>;
|
|
27
27
|
trackVideoPlay(tracking_user_id?: string, videoData?: Record<string, any>): Promise<void>;
|
|
28
28
|
trackEmailVerification(tracking_user_id: string, verificationData?: Record<string, any>): Promise<void>;
|
|
29
|
+
trackAuditApproved(tracking_user_id: string, auditData?: Record<string, any>): Promise<void>;
|
|
30
|
+
trackPurchaseAuto(options: {
|
|
31
|
+
revenue: number;
|
|
32
|
+
currency?: Currency;
|
|
33
|
+
purchaseData?: Record<string, any>;
|
|
34
|
+
tracking_user_id?: string;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
trackLoginAuto(options: {
|
|
37
|
+
loginData?: Record<string, any>;
|
|
38
|
+
tracking_user_id?: string;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
trackSignupAuto(options: {
|
|
41
|
+
signupData?: Record<string, any>;
|
|
42
|
+
tracking_user_id?: string;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
trackEmailVerificationAuto(options: {
|
|
45
|
+
verificationData?: Record<string, any>;
|
|
46
|
+
tracking_user_id?: string;
|
|
47
|
+
}): Promise<void>;
|
|
29
48
|
trackProductView(tracking_user_id?: string, productData?: Record<string, any>): Promise<void>;
|
|
30
49
|
trackAddToCart(tracking_user_id?: string, cartData?: Record<string, any>): Promise<void>;
|
|
31
50
|
trackPageClick(tracking_user_id?: string, clickData?: Record<string, any>): Promise<void>;
|
|
@@ -33,6 +52,10 @@ export declare class AttributionSDK {
|
|
|
33
52
|
addUTMToURL(url: string): string;
|
|
34
53
|
getCurrentUTMParams(): Record<string, string>;
|
|
35
54
|
private getUTMParams;
|
|
55
|
+
private initializeUserId;
|
|
56
|
+
setUserId(userId: string): void;
|
|
57
|
+
getUserId(): string | null;
|
|
58
|
+
removeUserId(): void;
|
|
36
59
|
private initializeSession;
|
|
37
60
|
private extractAndStoreUTMData;
|
|
38
61
|
private setupAutoTracking;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttributionSDK.d.ts","sourceRoot":"","sources":["../../src/core/AttributionSDK.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,SAAS,EACT,eAAe,EAEf,QAAQ,EACR,WAAW,EAGZ,MAAM,UAAU,CAAC;AAuBlB,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,kBAAkB,CAAkC;IAE5D,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,iBAAiB,CAAyC;IAClE,OAAO,CAAC,oBAAoB,CAA4C;IACxE,OAAO,CAAC,eAAe,CAAiD;gBAE5D,MAAM,EAAE,SAAS;IA+CvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"AttributionSDK.d.ts","sourceRoot":"","sources":["../../src/core/AttributionSDK.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,SAAS,EACT,eAAe,EAEf,QAAQ,EACR,WAAW,EAGZ,MAAM,UAAU,CAAC;AAuBlB,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MA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C,gBAAgB;IA+ExB,OAAO,CAAC,kBAAkB;IAwB1B,OAAO,CAAC,qBAAqB;IAQvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B,SAAS,IAAI;QACX,WAAW,EAAE,OAAO,CAAC;QACrB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;QAC5B,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,OAAO,CAAC;QAChB,cAAc,EAAE;YACd,OAAO,EAAE,OAAO,CAAC;YACjB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACvC,CAAC;QACF,WAAW,EAAE;YACX,OAAO,EAAE,OAAO,CAAC;YACjB,WAAW,EAAE,MAAM,CAAC;SACrB,CAAC;KACH;IAkBD,OAAO,IAAI,IAAI;CAOhB"}
|
|
@@ -49,8 +49,17 @@ export class AttributionSDK {
|
|
|
49
49
|
}
|
|
50
50
|
try {
|
|
51
51
|
this.logger.info("Initializing GetuAI Attribution SDK");
|
|
52
|
-
// Initialize storage
|
|
53
|
-
|
|
52
|
+
// Initialize storage (IndexedDB failure should not block SDK initialization)
|
|
53
|
+
try {
|
|
54
|
+
await this.storage.init();
|
|
55
|
+
}
|
|
56
|
+
catch (storageError) {
|
|
57
|
+
this.logger.warn("Storage initialization failed (IndexedDB may be unavailable), continuing with basic features:", storageError);
|
|
58
|
+
// Continue initialization even if IndexedDB fails
|
|
59
|
+
// User ID and other features using cookie/localStorage will still work
|
|
60
|
+
}
|
|
61
|
+
// Initialize user ID (from config or existing storage)
|
|
62
|
+
this.initializeUserId();
|
|
54
63
|
// Initialize session
|
|
55
64
|
this.initializeSession();
|
|
56
65
|
// Extract and store UTM data from current URL
|
|
@@ -123,10 +132,12 @@ export class AttributionSDK {
|
|
|
123
132
|
last_activity: this.session?.lastActivity,
|
|
124
133
|
page_views: this.session?.pageViews,
|
|
125
134
|
};
|
|
135
|
+
// Use provided tracking_user_id or fallback to stored user ID
|
|
136
|
+
const finalUserId = tracking_user_id || this.getUserId();
|
|
126
137
|
const event = {
|
|
127
138
|
event_id: generateId(),
|
|
128
139
|
event_type: eventType,
|
|
129
|
-
tracking_user_id:
|
|
140
|
+
tracking_user_id: finalUserId || undefined,
|
|
130
141
|
timestamp: getTimestamp(),
|
|
131
142
|
event_data: eventData,
|
|
132
143
|
context: { page: pageContext, session: sessionContext },
|
|
@@ -223,6 +234,46 @@ export class AttributionSDK {
|
|
|
223
234
|
async trackEmailVerification(tracking_user_id, verificationData) {
|
|
224
235
|
await this.trackEvent(EventType.EMAIL_VERIFICATION, verificationData, tracking_user_id);
|
|
225
236
|
}
|
|
237
|
+
// Track audit approved (conversion)
|
|
238
|
+
async trackAuditApproved(tracking_user_id, auditData) {
|
|
239
|
+
await this.trackEvent(EventType.AUDIT_APPROVED, auditData, tracking_user_id);
|
|
240
|
+
}
|
|
241
|
+
// Track purchase with auto user ID (object parameter format)
|
|
242
|
+
async trackPurchaseAuto(options) {
|
|
243
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
244
|
+
if (!userId) {
|
|
245
|
+
this.logger.error("โ trackPurchaseAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
await this.trackEvent(EventType.PURCHASE, options.purchaseData, userId, options.revenue, options.currency || Currency.USD);
|
|
249
|
+
}
|
|
250
|
+
// Track login with auto user ID (object parameter format)
|
|
251
|
+
async trackLoginAuto(options) {
|
|
252
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
253
|
+
if (!userId) {
|
|
254
|
+
this.logger.error("โ trackLoginAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
await this.trackEvent(EventType.LOGIN, options.loginData, userId);
|
|
258
|
+
}
|
|
259
|
+
// Track signup with auto user ID (object parameter format)
|
|
260
|
+
async trackSignupAuto(options) {
|
|
261
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
262
|
+
if (!userId) {
|
|
263
|
+
this.logger.error("โ trackSignupAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
await this.trackEvent(EventType.SIGNUP, options.signupData, userId);
|
|
267
|
+
}
|
|
268
|
+
// Track email verification with auto user ID (object parameter format)
|
|
269
|
+
async trackEmailVerificationAuto(options) {
|
|
270
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
271
|
+
if (!userId) {
|
|
272
|
+
this.logger.error("โ trackEmailVerificationAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
await this.trackEvent(EventType.EMAIL_VERIFICATION, options.verificationData, userId);
|
|
276
|
+
}
|
|
226
277
|
// Track product view
|
|
227
278
|
async trackProductView(tracking_user_id, productData) {
|
|
228
279
|
await this.trackEvent(EventType.PRODUCT_VIEW, productData, tracking_user_id);
|
|
@@ -308,6 +359,42 @@ export class AttributionSDK {
|
|
|
308
359
|
this.logger.debug("UTM params for event:", filteredParams);
|
|
309
360
|
return filteredParams;
|
|
310
361
|
}
|
|
362
|
+
// Initialize user ID
|
|
363
|
+
initializeUserId() {
|
|
364
|
+
// If userId is provided in config, set it (will override existing)
|
|
365
|
+
if (this.config.userId) {
|
|
366
|
+
this.setUserId(this.config.userId);
|
|
367
|
+
this.logger.info(`๐ค User ID initialized from config: ${this.config.userId}`);
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
// Check if user ID already exists in storage
|
|
371
|
+
const existingUserId = this.getUserId();
|
|
372
|
+
if (existingUserId) {
|
|
373
|
+
this.logger.debug(`๐ค Existing user ID found: ${existingUserId}`);
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
this.logger.debug("๐ค No user ID found, will be set when user identifies");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
// Set user ID
|
|
381
|
+
setUserId(userId) {
|
|
382
|
+
if (!userId || userId.trim() === "") {
|
|
383
|
+
this.logger.warn("Cannot set empty user ID");
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
this.storage.setUserId(userId);
|
|
387
|
+
this.logger.info(`๐ค User ID set: ${userId}`);
|
|
388
|
+
}
|
|
389
|
+
// Get user ID
|
|
390
|
+
getUserId() {
|
|
391
|
+
return this.storage.getUserId();
|
|
392
|
+
}
|
|
393
|
+
// Remove user ID
|
|
394
|
+
removeUserId() {
|
|
395
|
+
this.storage.removeUserId();
|
|
396
|
+
this.logger.info("๐ค User ID removed");
|
|
397
|
+
}
|
|
311
398
|
// Initialize user session
|
|
312
399
|
initializeSession() {
|
|
313
400
|
const existingSession = this.storage.getSession();
|