getu-attribution-v2-sdk 0.2.1 → 0.2.2
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 +180 -1
- package/dist/core/AttributionSDK.d.ts +22 -0
- package/dist/core/AttributionSDK.d.ts.map +1 -1
- package/dist/core/AttributionSDK.js +86 -3
- package/dist/getuai-attribution.min.js +1 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +321 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +321 -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 +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,24 @@ declare function trackSignup(tracking_user_id: string, signupData?: Record<strin
|
|
|
11
11
|
declare function trackFormSubmit(tracking_user_id?: string, formData?: Record<string, any>): Promise<void>;
|
|
12
12
|
declare function trackVideoPlay(tracking_user_id?: string, videoData?: Record<string, any>): Promise<void>;
|
|
13
13
|
declare function trackEmailVerification(tracking_user_id: string, verificationData?: Record<string, any>): Promise<void>;
|
|
14
|
+
declare function trackPurchaseAuto(options: {
|
|
15
|
+
revenue: number;
|
|
16
|
+
currency?: Currency;
|
|
17
|
+
purchaseData?: Record<string, any>;
|
|
18
|
+
tracking_user_id?: string;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
declare function trackLoginAuto(options: {
|
|
21
|
+
loginData?: Record<string, any>;
|
|
22
|
+
tracking_user_id?: string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
declare function trackSignupAuto(options: {
|
|
25
|
+
signupData?: Record<string, any>;
|
|
26
|
+
tracking_user_id?: string;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
declare function trackEmailVerificationAuto(options: {
|
|
29
|
+
verificationData?: Record<string, any>;
|
|
30
|
+
tracking_user_id?: string;
|
|
31
|
+
}): Promise<void>;
|
|
14
32
|
declare function trackProductView(tracking_user_id?: string, productData?: Record<string, any>): Promise<void>;
|
|
15
33
|
declare function trackAddToCart(tracking_user_id?: string, cartData?: Record<string, any>): Promise<void>;
|
|
16
34
|
declare function trackPageClick(tracking_user_id?: string, clickData?: Record<string, any>): Promise<void>;
|
|
@@ -32,6 +50,9 @@ declare function getStatus(): {
|
|
|
32
50
|
} | null;
|
|
33
51
|
declare function addUTMToURL(url: string): string;
|
|
34
52
|
declare function getCurrentUTMParams(): Record<string, string>;
|
|
53
|
+
declare function setUserId(userId: string): void;
|
|
54
|
+
declare function getUserId(): string | null;
|
|
55
|
+
declare function removeUserId(): void;
|
|
35
56
|
declare function destroy(): void;
|
|
36
57
|
declare class AttributionSDKStatic extends AttributionSDK {
|
|
37
58
|
static init(config: SDKConfig): Promise<AttributionSDK>;
|
|
@@ -43,6 +64,24 @@ declare class AttributionSDKStatic extends AttributionSDK {
|
|
|
43
64
|
static trackFormSubmit(tracking_user_id?: string, formData?: Record<string, any>): Promise<void>;
|
|
44
65
|
static trackVideoPlay(tracking_user_id?: string, videoData?: Record<string, any>): Promise<void>;
|
|
45
66
|
static trackEmailVerification(tracking_user_id: string, verificationData?: Record<string, any>): Promise<void>;
|
|
67
|
+
static trackPurchaseAuto(options: {
|
|
68
|
+
revenue: number;
|
|
69
|
+
currency?: Currency;
|
|
70
|
+
purchaseData?: Record<string, any>;
|
|
71
|
+
tracking_user_id?: string;
|
|
72
|
+
}): Promise<void>;
|
|
73
|
+
static trackLoginAuto(options: {
|
|
74
|
+
loginData?: Record<string, any>;
|
|
75
|
+
tracking_user_id?: string;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
static trackSignupAuto(options: {
|
|
78
|
+
signupData?: Record<string, any>;
|
|
79
|
+
tracking_user_id?: string;
|
|
80
|
+
}): Promise<void>;
|
|
81
|
+
static trackEmailVerificationAuto(options: {
|
|
82
|
+
verificationData?: Record<string, any>;
|
|
83
|
+
tracking_user_id?: string;
|
|
84
|
+
}): Promise<void>;
|
|
46
85
|
static trackProductView(tracking_user_id?: string, productData?: Record<string, any>): Promise<void>;
|
|
47
86
|
static trackAddToCart(tracking_user_id?: string, cartData?: Record<string, any>): Promise<void>;
|
|
48
87
|
static trackPageClick(tracking_user_id?: string, clickData?: Record<string, any>): Promise<void>;
|
|
@@ -64,12 +103,15 @@ declare class AttributionSDKStatic extends AttributionSDK {
|
|
|
64
103
|
} | null;
|
|
65
104
|
static addUTMToURL(url: string): string;
|
|
66
105
|
static getCurrentUTMParams(): Record<string, string>;
|
|
106
|
+
static setUserId(userId: string): void;
|
|
107
|
+
static getUserId(): string | null;
|
|
108
|
+
static removeUserId(): void;
|
|
67
109
|
static destroy(): void;
|
|
68
110
|
static getSDK(): AttributionSDK | null;
|
|
69
111
|
static waitForSDK(): Promise<AttributionSDK>;
|
|
70
112
|
}
|
|
71
113
|
export { EventType, Currency, type SDKConfig, type EventData, type AttributionData, };
|
|
72
|
-
export { init, getSDK, waitForSDK, trackEvent, trackPageView, trackPageClick, trackPurchase, trackLogin, trackSignup, trackFormSubmit, trackVideoPlay, trackEmailVerification, trackProductView, trackAddToCart, getAttributionData, flush, getStatus, addUTMToURL, getCurrentUTMParams, destroy, };
|
|
114
|
+
export { init, getSDK, waitForSDK, trackEvent, trackPageView, trackPageClick, trackPurchase, trackLogin, trackSignup, trackFormSubmit, trackVideoPlay, trackEmailVerification, trackProductView, trackAddToCart, trackPurchaseAuto, trackLoginAuto, trackSignupAuto, trackEmailVerificationAuto, getAttributionData, flush, getStatus, addUTMToURL, getCurrentUTMParams, setUserId, getUserId, removeUserId, destroy, };
|
|
73
115
|
export { AttributionSDKStatic as AttributionSDK };
|
|
74
116
|
declare const _default: {
|
|
75
117
|
init: typeof init;
|
|
@@ -86,11 +128,18 @@ declare const _default: {
|
|
|
86
128
|
trackEmailVerification: typeof trackEmailVerification;
|
|
87
129
|
trackProductView: typeof trackProductView;
|
|
88
130
|
trackAddToCart: typeof trackAddToCart;
|
|
131
|
+
trackPurchaseAuto: typeof trackPurchaseAuto;
|
|
132
|
+
trackLoginAuto: typeof trackLoginAuto;
|
|
133
|
+
trackSignupAuto: typeof trackSignupAuto;
|
|
134
|
+
trackEmailVerificationAuto: typeof trackEmailVerificationAuto;
|
|
89
135
|
getAttributionData: typeof getAttributionData;
|
|
90
136
|
flush: typeof flush;
|
|
91
137
|
getStatus: typeof getStatus;
|
|
92
138
|
addUTMToURL: typeof addUTMToURL;
|
|
93
139
|
getCurrentUTMParams: typeof getCurrentUTMParams;
|
|
140
|
+
setUserId: typeof setUserId;
|
|
141
|
+
getUserId: typeof getUserId;
|
|
142
|
+
removeUserId: typeof removeUserId;
|
|
94
143
|
destroy: typeof destroy;
|
|
95
144
|
EventType: typeof EventType;
|
|
96
145
|
Currency: typeof Currency;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACR,SAAS,EACT,eAAe,EAEhB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACR,SAAS,EACT,eAAe,EAEhB,MAAM,SAAS,CAAC;AAkDjB,iBAAe,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAuC9D;AAGD,iBAAS,MAAM,IAAI,cAAc,GAAG,IAAI,CAEvC;AAGD,iBAAS,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC,CAgD7C;AAGD,iBAAe,UAAU,CACvB,SAAS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,EACL,IAAI,EACJ,MAAM,EACN,UAAU,EACV,UAAU,EACV,aAAa,EACb,cAAc,EACd,aAAa,EACb,UAAU,EACV,WAAW,EACX,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,0BAA0B,EAC1B,kBAAkB,EAClB,KAAK,EACL,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,SAAS,EACT,SAAS,EACT,YAAY,EACZ,OAAO,GACR,CAAC;AAGF,OAAO,EAAE,oBAAoB,IAAI,cAAc,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2ElD,wBA+BE"}
|
package/dist/index.esm.js
CHANGED
|
@@ -550,10 +550,131 @@ class AttributionStorageManager {
|
|
|
550
550
|
constructor(logger) {
|
|
551
551
|
this.UTM_STORAGE_KEY = "attribution_utm_data";
|
|
552
552
|
this.SESSION_STORAGE_KEY = "attribution_session";
|
|
553
|
+
this.USER_ID_KEY = "getuai_user_id";
|
|
554
|
+
this.USER_ID_COOKIE_EXPIRES = 365; // days
|
|
553
555
|
this.logger = logger;
|
|
554
556
|
this.localStorage = new LocalStorageManager(logger);
|
|
555
557
|
this.indexedDB = new IndexedDBManager(logger);
|
|
556
558
|
}
|
|
559
|
+
// User ID management - stores in both cookie and localStorage
|
|
560
|
+
setUserId(userId) {
|
|
561
|
+
if (!userId || userId.trim() === "") {
|
|
562
|
+
this.logger.warn("Cannot set empty user ID");
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const trimmedUserId = userId.trim();
|
|
566
|
+
// Store in cookie
|
|
567
|
+
try {
|
|
568
|
+
this.setCookie(this.USER_ID_KEY, trimmedUserId, this.USER_ID_COOKIE_EXPIRES);
|
|
569
|
+
this.logger.debug(`👤 User ID stored in cookie: ${trimmedUserId}`);
|
|
570
|
+
}
|
|
571
|
+
catch (error) {
|
|
572
|
+
this.logger.error("Failed to store user ID in cookie:", error);
|
|
573
|
+
}
|
|
574
|
+
// Store in localStorage
|
|
575
|
+
try {
|
|
576
|
+
if (typeof localStorage !== "undefined") {
|
|
577
|
+
localStorage.setItem(this.USER_ID_KEY, trimmedUserId);
|
|
578
|
+
this.logger.debug(`👤 User ID stored in localStorage: ${trimmedUserId}`);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
catch (error) {
|
|
582
|
+
this.logger.error("Failed to store user ID in localStorage:", error);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
getUserId() {
|
|
586
|
+
// Try localStorage first
|
|
587
|
+
try {
|
|
588
|
+
if (typeof localStorage !== "undefined") {
|
|
589
|
+
const userId = localStorage.getItem(this.USER_ID_KEY);
|
|
590
|
+
if (userId) {
|
|
591
|
+
return userId;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
this.logger.debug("Failed to get user ID from localStorage:", error);
|
|
597
|
+
}
|
|
598
|
+
// Fallback to cookie
|
|
599
|
+
try {
|
|
600
|
+
const userId = this.getCookie(this.USER_ID_KEY);
|
|
601
|
+
if (userId) {
|
|
602
|
+
// Sync back to localStorage if cookie exists but localStorage doesn't
|
|
603
|
+
try {
|
|
604
|
+
if (typeof localStorage !== "undefined") {
|
|
605
|
+
localStorage.setItem(this.USER_ID_KEY, userId);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
catch (error) {
|
|
609
|
+
// Ignore sync errors
|
|
610
|
+
}
|
|
611
|
+
return userId;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
catch (error) {
|
|
615
|
+
this.logger.debug("Failed to get user ID from cookie:", error);
|
|
616
|
+
}
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
removeUserId() {
|
|
620
|
+
// Remove from cookie
|
|
621
|
+
try {
|
|
622
|
+
this.deleteCookie(this.USER_ID_KEY);
|
|
623
|
+
this.logger.debug("👤 User ID removed from cookie");
|
|
624
|
+
}
|
|
625
|
+
catch (error) {
|
|
626
|
+
this.logger.error("Failed to remove user ID from cookie:", error);
|
|
627
|
+
}
|
|
628
|
+
// Remove from localStorage
|
|
629
|
+
try {
|
|
630
|
+
if (typeof localStorage !== "undefined") {
|
|
631
|
+
localStorage.removeItem(this.USER_ID_KEY);
|
|
632
|
+
this.logger.debug("👤 User ID removed from localStorage");
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
catch (error) {
|
|
636
|
+
this.logger.error("Failed to remove user ID from localStorage:", error);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
// Cookie helper methods
|
|
640
|
+
setCookie(name, value, days) {
|
|
641
|
+
try {
|
|
642
|
+
const expires = new Date();
|
|
643
|
+
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
|
644
|
+
const cookieValue = `${name}=${encodeURIComponent(value)};expires=${expires.toUTCString()};path=/;SameSite=Lax`;
|
|
645
|
+
document.cookie = cookieValue;
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
this.logger.error("Failed to set cookie:", error);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
getCookie(name) {
|
|
652
|
+
try {
|
|
653
|
+
const nameEQ = name + "=";
|
|
654
|
+
const ca = document.cookie.split(";");
|
|
655
|
+
for (let i = 0; i < ca.length; i++) {
|
|
656
|
+
let c = ca[i];
|
|
657
|
+
while (c.charAt(0) === " ")
|
|
658
|
+
c = c.substring(1, c.length);
|
|
659
|
+
if (c.indexOf(nameEQ) === 0) {
|
|
660
|
+
return decodeURIComponent(c.substring(nameEQ.length, c.length));
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return null;
|
|
664
|
+
}
|
|
665
|
+
catch (error) {
|
|
666
|
+
this.logger.error("Failed to get cookie:", error);
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
deleteCookie(name) {
|
|
671
|
+
try {
|
|
672
|
+
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;`;
|
|
673
|
+
}
|
|
674
|
+
catch (error) {
|
|
675
|
+
this.logger.error("Failed to delete cookie:", error);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
557
678
|
async init() {
|
|
558
679
|
await this.indexedDB.init();
|
|
559
680
|
}
|
|
@@ -872,8 +993,17 @@ class AttributionSDK {
|
|
|
872
993
|
}
|
|
873
994
|
try {
|
|
874
995
|
this.logger.info("Initializing GetuAI Attribution SDK");
|
|
875
|
-
// Initialize storage
|
|
876
|
-
|
|
996
|
+
// Initialize storage (IndexedDB failure should not block SDK initialization)
|
|
997
|
+
try {
|
|
998
|
+
await this.storage.init();
|
|
999
|
+
}
|
|
1000
|
+
catch (storageError) {
|
|
1001
|
+
this.logger.warn("Storage initialization failed (IndexedDB may be unavailable), continuing with basic features:", storageError);
|
|
1002
|
+
// Continue initialization even if IndexedDB fails
|
|
1003
|
+
// User ID and other features using cookie/localStorage will still work
|
|
1004
|
+
}
|
|
1005
|
+
// Initialize user ID (from config or existing storage)
|
|
1006
|
+
this.initializeUserId();
|
|
877
1007
|
// Initialize session
|
|
878
1008
|
this.initializeSession();
|
|
879
1009
|
// Extract and store UTM data from current URL
|
|
@@ -946,10 +1076,12 @@ class AttributionSDK {
|
|
|
946
1076
|
last_activity: this.session?.lastActivity,
|
|
947
1077
|
page_views: this.session?.pageViews,
|
|
948
1078
|
};
|
|
1079
|
+
// Use provided tracking_user_id or fallback to stored user ID
|
|
1080
|
+
const finalUserId = tracking_user_id || this.getUserId();
|
|
949
1081
|
const event = {
|
|
950
1082
|
event_id: generateId(),
|
|
951
1083
|
event_type: eventType,
|
|
952
|
-
tracking_user_id:
|
|
1084
|
+
tracking_user_id: finalUserId || undefined,
|
|
953
1085
|
timestamp: getTimestamp(),
|
|
954
1086
|
event_data: eventData,
|
|
955
1087
|
context: { page: pageContext, session: sessionContext },
|
|
@@ -1046,6 +1178,42 @@ class AttributionSDK {
|
|
|
1046
1178
|
async trackEmailVerification(tracking_user_id, verificationData) {
|
|
1047
1179
|
await this.trackEvent(EventType.EMAIL_VERIFICATION, verificationData, tracking_user_id);
|
|
1048
1180
|
}
|
|
1181
|
+
// Track purchase with auto user ID (object parameter format)
|
|
1182
|
+
async trackPurchaseAuto(options) {
|
|
1183
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
1184
|
+
if (!userId) {
|
|
1185
|
+
this.logger.error("❌ trackPurchaseAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
await this.trackEvent(EventType.PURCHASE, options.purchaseData, userId, options.revenue, options.currency || Currency.USD);
|
|
1189
|
+
}
|
|
1190
|
+
// Track login with auto user ID (object parameter format)
|
|
1191
|
+
async trackLoginAuto(options) {
|
|
1192
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
1193
|
+
if (!userId) {
|
|
1194
|
+
this.logger.error("❌ trackLoginAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
await this.trackEvent(EventType.LOGIN, options.loginData, userId);
|
|
1198
|
+
}
|
|
1199
|
+
// Track signup with auto user ID (object parameter format)
|
|
1200
|
+
async trackSignupAuto(options) {
|
|
1201
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
1202
|
+
if (!userId) {
|
|
1203
|
+
this.logger.error("❌ trackSignupAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
await this.trackEvent(EventType.SIGNUP, options.signupData, userId);
|
|
1207
|
+
}
|
|
1208
|
+
// Track email verification with auto user ID (object parameter format)
|
|
1209
|
+
async trackEmailVerificationAuto(options) {
|
|
1210
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
1211
|
+
if (!userId) {
|
|
1212
|
+
this.logger.error("❌ trackEmailVerificationAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
await this.trackEvent(EventType.EMAIL_VERIFICATION, options.verificationData, userId);
|
|
1216
|
+
}
|
|
1049
1217
|
// Track product view
|
|
1050
1218
|
async trackProductView(tracking_user_id, productData) {
|
|
1051
1219
|
await this.trackEvent(EventType.PRODUCT_VIEW, productData, tracking_user_id);
|
|
@@ -1131,6 +1299,42 @@ class AttributionSDK {
|
|
|
1131
1299
|
this.logger.debug("UTM params for event:", filteredParams);
|
|
1132
1300
|
return filteredParams;
|
|
1133
1301
|
}
|
|
1302
|
+
// Initialize user ID
|
|
1303
|
+
initializeUserId() {
|
|
1304
|
+
// If userId is provided in config, set it (will override existing)
|
|
1305
|
+
if (this.config.userId) {
|
|
1306
|
+
this.setUserId(this.config.userId);
|
|
1307
|
+
this.logger.info(`👤 User ID initialized from config: ${this.config.userId}`);
|
|
1308
|
+
}
|
|
1309
|
+
else {
|
|
1310
|
+
// Check if user ID already exists in storage
|
|
1311
|
+
const existingUserId = this.getUserId();
|
|
1312
|
+
if (existingUserId) {
|
|
1313
|
+
this.logger.debug(`👤 Existing user ID found: ${existingUserId}`);
|
|
1314
|
+
}
|
|
1315
|
+
else {
|
|
1316
|
+
this.logger.debug("👤 No user ID found, will be set when user identifies");
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
// Set user ID
|
|
1321
|
+
setUserId(userId) {
|
|
1322
|
+
if (!userId || userId.trim() === "") {
|
|
1323
|
+
this.logger.warn("Cannot set empty user ID");
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
this.storage.setUserId(userId);
|
|
1327
|
+
this.logger.info(`👤 User ID set: ${userId}`);
|
|
1328
|
+
}
|
|
1329
|
+
// Get user ID
|
|
1330
|
+
getUserId() {
|
|
1331
|
+
return this.storage.getUserId();
|
|
1332
|
+
}
|
|
1333
|
+
// Remove user ID
|
|
1334
|
+
removeUserId() {
|
|
1335
|
+
this.storage.removeUserId();
|
|
1336
|
+
this.logger.info("👤 User ID removed");
|
|
1337
|
+
}
|
|
1134
1338
|
// Initialize user session
|
|
1135
1339
|
initializeSession() {
|
|
1136
1340
|
const existingSession = this.storage.getSession();
|
|
@@ -1580,6 +1784,7 @@ function autoInit() {
|
|
|
1580
1784
|
autoCleanUTM: script.getAttribute("data-auto-clean-utm") !== "false",
|
|
1581
1785
|
batchSize: parseInt(script.getAttribute("data-batch-size") || "100"),
|
|
1582
1786
|
batchInterval: parseInt(script.getAttribute("data-batch-interval") || "2000"),
|
|
1787
|
+
userId: script.getAttribute("data-user-id") || undefined,
|
|
1583
1788
|
};
|
|
1584
1789
|
// Initialize SDK
|
|
1585
1790
|
init(config);
|
|
@@ -1723,6 +1928,42 @@ async function trackEmailVerification(tracking_user_id, verificationData) {
|
|
|
1723
1928
|
}
|
|
1724
1929
|
await sdk.trackEmailVerification(tracking_user_id, verificationData);
|
|
1725
1930
|
}
|
|
1931
|
+
// Track purchase with auto user ID (object parameter format)
|
|
1932
|
+
async function trackPurchaseAuto(options) {
|
|
1933
|
+
const sdk = getSDK();
|
|
1934
|
+
if (!sdk) {
|
|
1935
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
await sdk.trackPurchaseAuto(options);
|
|
1939
|
+
}
|
|
1940
|
+
// Track login with auto user ID (object parameter format)
|
|
1941
|
+
async function trackLoginAuto(options) {
|
|
1942
|
+
const sdk = getSDK();
|
|
1943
|
+
if (!sdk) {
|
|
1944
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
await sdk.trackLoginAuto(options);
|
|
1948
|
+
}
|
|
1949
|
+
// Track signup with auto user ID (object parameter format)
|
|
1950
|
+
async function trackSignupAuto(options) {
|
|
1951
|
+
const sdk = getSDK();
|
|
1952
|
+
if (!sdk) {
|
|
1953
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
await sdk.trackSignupAuto(options);
|
|
1957
|
+
}
|
|
1958
|
+
// Track email verification with auto user ID (object parameter format)
|
|
1959
|
+
async function trackEmailVerificationAuto(options) {
|
|
1960
|
+
const sdk = getSDK();
|
|
1961
|
+
if (!sdk) {
|
|
1962
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
await sdk.trackEmailVerificationAuto(options);
|
|
1966
|
+
}
|
|
1726
1967
|
// Track product view
|
|
1727
1968
|
async function trackProductView(tracking_user_id, productData) {
|
|
1728
1969
|
const sdk = getSDK();
|
|
@@ -1792,6 +2033,33 @@ function getCurrentUTMParams() {
|
|
|
1792
2033
|
}
|
|
1793
2034
|
return sdk.getCurrentUTMParams();
|
|
1794
2035
|
}
|
|
2036
|
+
// Set user ID
|
|
2037
|
+
function setUserId(userId) {
|
|
2038
|
+
const sdk = getSDK();
|
|
2039
|
+
if (!sdk) {
|
|
2040
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
sdk.setUserId(userId);
|
|
2044
|
+
}
|
|
2045
|
+
// Get user ID
|
|
2046
|
+
function getUserId() {
|
|
2047
|
+
const sdk = getSDK();
|
|
2048
|
+
if (!sdk) {
|
|
2049
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2050
|
+
return null;
|
|
2051
|
+
}
|
|
2052
|
+
return sdk.getUserId();
|
|
2053
|
+
}
|
|
2054
|
+
// Remove user ID
|
|
2055
|
+
function removeUserId() {
|
|
2056
|
+
const sdk = getSDK();
|
|
2057
|
+
if (!sdk) {
|
|
2058
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
sdk.removeUserId();
|
|
2062
|
+
}
|
|
1795
2063
|
// Destroy SDK
|
|
1796
2064
|
function destroy() {
|
|
1797
2065
|
if (globalSDK) {
|
|
@@ -1838,6 +2106,22 @@ class AttributionSDKStatic extends AttributionSDK {
|
|
|
1838
2106
|
static async trackEmailVerification(tracking_user_id, verificationData) {
|
|
1839
2107
|
return await trackEmailVerification(tracking_user_id, verificationData);
|
|
1840
2108
|
}
|
|
2109
|
+
// Static method to track purchase with auto user ID
|
|
2110
|
+
static async trackPurchaseAuto(options) {
|
|
2111
|
+
return await trackPurchaseAuto(options);
|
|
2112
|
+
}
|
|
2113
|
+
// Static method to track login with auto user ID
|
|
2114
|
+
static async trackLoginAuto(options) {
|
|
2115
|
+
return await trackLoginAuto(options);
|
|
2116
|
+
}
|
|
2117
|
+
// Static method to track signup with auto user ID
|
|
2118
|
+
static async trackSignupAuto(options) {
|
|
2119
|
+
return await trackSignupAuto(options);
|
|
2120
|
+
}
|
|
2121
|
+
// Static method to track email verification with auto user ID
|
|
2122
|
+
static async trackEmailVerificationAuto(options) {
|
|
2123
|
+
return await trackEmailVerificationAuto(options);
|
|
2124
|
+
}
|
|
1841
2125
|
// Static method to track product view
|
|
1842
2126
|
static async trackProductView(tracking_user_id, productData) {
|
|
1843
2127
|
return await trackProductView(tracking_user_id, productData);
|
|
@@ -1870,6 +2154,18 @@ class AttributionSDKStatic extends AttributionSDK {
|
|
|
1870
2154
|
static getCurrentUTMParams() {
|
|
1871
2155
|
return getCurrentUTMParams();
|
|
1872
2156
|
}
|
|
2157
|
+
// Static method to set user ID
|
|
2158
|
+
static setUserId(userId) {
|
|
2159
|
+
setUserId(userId);
|
|
2160
|
+
}
|
|
2161
|
+
// Static method to get user ID
|
|
2162
|
+
static getUserId() {
|
|
2163
|
+
return getUserId();
|
|
2164
|
+
}
|
|
2165
|
+
// Static method to remove user ID
|
|
2166
|
+
static removeUserId() {
|
|
2167
|
+
removeUserId();
|
|
2168
|
+
}
|
|
1873
2169
|
// Static method to destroy SDK
|
|
1874
2170
|
static destroy() {
|
|
1875
2171
|
destroy();
|
|
@@ -1906,11 +2202,18 @@ if (typeof window !== "undefined") {
|
|
|
1906
2202
|
trackEmailVerification,
|
|
1907
2203
|
trackProductView,
|
|
1908
2204
|
trackAddToCart,
|
|
2205
|
+
trackPurchaseAuto,
|
|
2206
|
+
trackLoginAuto,
|
|
2207
|
+
trackSignupAuto,
|
|
2208
|
+
trackEmailVerificationAuto,
|
|
1909
2209
|
getAttributionData,
|
|
1910
2210
|
flush,
|
|
1911
2211
|
getStatus,
|
|
1912
2212
|
addUTMToURL,
|
|
1913
2213
|
getCurrentUTMParams,
|
|
2214
|
+
setUserId,
|
|
2215
|
+
getUserId,
|
|
2216
|
+
removeUserId,
|
|
1914
2217
|
destroy,
|
|
1915
2218
|
EventType,
|
|
1916
2219
|
Currency,
|
|
@@ -1930,11 +2233,18 @@ if (typeof window !== "undefined") {
|
|
|
1930
2233
|
window.trackEmailVerification = trackEmailVerification;
|
|
1931
2234
|
window.trackProductView = trackProductView;
|
|
1932
2235
|
window.trackAddToCart = trackAddToCart;
|
|
2236
|
+
window.trackPurchaseAuto = trackPurchaseAuto;
|
|
2237
|
+
window.trackLoginAuto = trackLoginAuto;
|
|
2238
|
+
window.trackSignupAuto = trackSignupAuto;
|
|
2239
|
+
window.trackEmailVerificationAuto = trackEmailVerificationAuto;
|
|
1933
2240
|
window.getAttributionData = getAttributionData;
|
|
1934
2241
|
window.flush = flush;
|
|
1935
2242
|
window.getStatus = getStatus;
|
|
1936
2243
|
window.addUTMToURL = addUTMToURL;
|
|
1937
2244
|
window.getCurrentUTMParams = getCurrentUTMParams;
|
|
2245
|
+
window.setUserId = setUserId;
|
|
2246
|
+
window.getUserId = getUserId;
|
|
2247
|
+
window.removeUserId = removeUserId;
|
|
1938
2248
|
window.destroy = destroy;
|
|
1939
2249
|
window.AttributionSDK = AttributionSDKStatic; // 直接暴露带静态方法的AttributionSDK类
|
|
1940
2250
|
}
|
|
@@ -1954,16 +2264,23 @@ var index = {
|
|
|
1954
2264
|
trackEmailVerification,
|
|
1955
2265
|
trackProductView,
|
|
1956
2266
|
trackAddToCart,
|
|
2267
|
+
trackPurchaseAuto,
|
|
2268
|
+
trackLoginAuto,
|
|
2269
|
+
trackSignupAuto,
|
|
2270
|
+
trackEmailVerificationAuto,
|
|
1957
2271
|
getAttributionData,
|
|
1958
2272
|
flush,
|
|
1959
2273
|
getStatus,
|
|
1960
2274
|
addUTMToURL,
|
|
1961
2275
|
getCurrentUTMParams,
|
|
2276
|
+
setUserId,
|
|
2277
|
+
getUserId,
|
|
2278
|
+
removeUserId,
|
|
1962
2279
|
destroy,
|
|
1963
2280
|
EventType,
|
|
1964
2281
|
Currency,
|
|
1965
2282
|
AttributionSDK: AttributionSDKStatic, // 包含带静态方法的AttributionSDK类
|
|
1966
2283
|
};
|
|
1967
2284
|
|
|
1968
|
-
export { AttributionSDKStatic as AttributionSDK, Currency, EventType, addUTMToURL, index as default, destroy, flush, getAttributionData, getCurrentUTMParams, getSDK, getStatus, init, trackAddToCart, trackEmailVerification, trackEvent, trackFormSubmit, trackLogin, trackPageClick, trackPageView, trackProductView, trackPurchase, trackSignup, trackVideoPlay, waitForSDK };
|
|
2285
|
+
export { AttributionSDKStatic as AttributionSDK, Currency, EventType, addUTMToURL, index as default, destroy, flush, getAttributionData, getCurrentUTMParams, getSDK, getStatus, getUserId, init, removeUserId, setUserId, trackAddToCart, trackEmailVerification, trackEmailVerificationAuto, trackEvent, trackFormSubmit, trackLogin, trackLoginAuto, trackPageClick, trackPageView, trackProductView, trackPurchase, trackPurchaseAuto, trackSignup, trackSignupAuto, trackVideoPlay, waitForSDK };
|
|
1969
2286
|
//# sourceMappingURL=index.esm.js.map
|