getu-attribution-v2-sdk 0.1.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 +196 -1
- 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 +53 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +352 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +354 -5
- package/dist/queue/index.d.ts.map +1 -1
- package/dist/queue/index.js +5 -1
- 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 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
39
39
|
"default": () => (/* binding */ src)
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
// UNUSED EXPORTS: AttributionSDK, Currency, EventType, addUTMToURL, destroy, flush, getAttributionData, getCurrentUTMParams, getSDK, getStatus, init, trackAddToCart, trackEmailVerification, trackEvent, trackFormSubmit, trackLogin, trackPageView, trackProductView, trackPurchase, trackSignup, trackVideoPlay, waitForSDK
|
|
42
|
+
// UNUSED EXPORTS: AttributionSDK, Currency, EventType, addUTMToURL, 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
|
|
43
43
|
|
|
44
44
|
;// ./src/types/index.ts
|
|
45
45
|
// Event types matching server-side enum exactly
|
|
@@ -47,6 +47,7 @@ var EventType;
|
|
|
47
47
|
(function (EventType) {
|
|
48
48
|
// Pre-conversion signals
|
|
49
49
|
EventType["PAGE_VIEW"] = "page_view";
|
|
50
|
+
EventType["PAGE_CLICK"] = "page_click";
|
|
50
51
|
EventType["VIDEO_PLAY"] = "video_play";
|
|
51
52
|
// Registration funnel
|
|
52
53
|
EventType["FORM_SUBMIT"] = "form_submit";
|
|
@@ -651,10 +652,131 @@ class AttributionStorageManager {
|
|
|
651
652
|
constructor(logger) {
|
|
652
653
|
this.UTM_STORAGE_KEY = "attribution_utm_data";
|
|
653
654
|
this.SESSION_STORAGE_KEY = "attribution_session";
|
|
655
|
+
this.USER_ID_KEY = "getuai_user_id";
|
|
656
|
+
this.USER_ID_COOKIE_EXPIRES = 365; // days
|
|
654
657
|
this.logger = logger;
|
|
655
658
|
this.localStorage = new LocalStorageManager(logger);
|
|
656
659
|
this.indexedDB = new IndexedDBManager(logger);
|
|
657
660
|
}
|
|
661
|
+
// User ID management - stores in both cookie and localStorage
|
|
662
|
+
setUserId(userId) {
|
|
663
|
+
if (!userId || userId.trim() === "") {
|
|
664
|
+
this.logger.warn("Cannot set empty user ID");
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const trimmedUserId = userId.trim();
|
|
668
|
+
// Store in cookie
|
|
669
|
+
try {
|
|
670
|
+
this.setCookie(this.USER_ID_KEY, trimmedUserId, this.USER_ID_COOKIE_EXPIRES);
|
|
671
|
+
this.logger.debug(`👤 User ID stored in cookie: ${trimmedUserId}`);
|
|
672
|
+
}
|
|
673
|
+
catch (error) {
|
|
674
|
+
this.logger.error("Failed to store user ID in cookie:", error);
|
|
675
|
+
}
|
|
676
|
+
// Store in localStorage
|
|
677
|
+
try {
|
|
678
|
+
if (typeof localStorage !== "undefined") {
|
|
679
|
+
localStorage.setItem(this.USER_ID_KEY, trimmedUserId);
|
|
680
|
+
this.logger.debug(`👤 User ID stored in localStorage: ${trimmedUserId}`);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
catch (error) {
|
|
684
|
+
this.logger.error("Failed to store user ID in localStorage:", error);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
getUserId() {
|
|
688
|
+
// Try localStorage first
|
|
689
|
+
try {
|
|
690
|
+
if (typeof localStorage !== "undefined") {
|
|
691
|
+
const userId = localStorage.getItem(this.USER_ID_KEY);
|
|
692
|
+
if (userId) {
|
|
693
|
+
return userId;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
catch (error) {
|
|
698
|
+
this.logger.debug("Failed to get user ID from localStorage:", error);
|
|
699
|
+
}
|
|
700
|
+
// Fallback to cookie
|
|
701
|
+
try {
|
|
702
|
+
const userId = this.getCookie(this.USER_ID_KEY);
|
|
703
|
+
if (userId) {
|
|
704
|
+
// Sync back to localStorage if cookie exists but localStorage doesn't
|
|
705
|
+
try {
|
|
706
|
+
if (typeof localStorage !== "undefined") {
|
|
707
|
+
localStorage.setItem(this.USER_ID_KEY, userId);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
catch (error) {
|
|
711
|
+
// Ignore sync errors
|
|
712
|
+
}
|
|
713
|
+
return userId;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
catch (error) {
|
|
717
|
+
this.logger.debug("Failed to get user ID from cookie:", error);
|
|
718
|
+
}
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
removeUserId() {
|
|
722
|
+
// Remove from cookie
|
|
723
|
+
try {
|
|
724
|
+
this.deleteCookie(this.USER_ID_KEY);
|
|
725
|
+
this.logger.debug("👤 User ID removed from cookie");
|
|
726
|
+
}
|
|
727
|
+
catch (error) {
|
|
728
|
+
this.logger.error("Failed to remove user ID from cookie:", error);
|
|
729
|
+
}
|
|
730
|
+
// Remove from localStorage
|
|
731
|
+
try {
|
|
732
|
+
if (typeof localStorage !== "undefined") {
|
|
733
|
+
localStorage.removeItem(this.USER_ID_KEY);
|
|
734
|
+
this.logger.debug("👤 User ID removed from localStorage");
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
catch (error) {
|
|
738
|
+
this.logger.error("Failed to remove user ID from localStorage:", error);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
// Cookie helper methods
|
|
742
|
+
setCookie(name, value, days) {
|
|
743
|
+
try {
|
|
744
|
+
const expires = new Date();
|
|
745
|
+
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
|
746
|
+
const cookieValue = `${name}=${encodeURIComponent(value)};expires=${expires.toUTCString()};path=/;SameSite=Lax`;
|
|
747
|
+
document.cookie = cookieValue;
|
|
748
|
+
}
|
|
749
|
+
catch (error) {
|
|
750
|
+
this.logger.error("Failed to set cookie:", error);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
getCookie(name) {
|
|
754
|
+
try {
|
|
755
|
+
const nameEQ = name + "=";
|
|
756
|
+
const ca = document.cookie.split(";");
|
|
757
|
+
for (let i = 0; i < ca.length; i++) {
|
|
758
|
+
let c = ca[i];
|
|
759
|
+
while (c.charAt(0) === " ")
|
|
760
|
+
c = c.substring(1, c.length);
|
|
761
|
+
if (c.indexOf(nameEQ) === 0) {
|
|
762
|
+
return decodeURIComponent(c.substring(nameEQ.length, c.length));
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
catch (error) {
|
|
768
|
+
this.logger.error("Failed to get cookie:", error);
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
deleteCookie(name) {
|
|
773
|
+
try {
|
|
774
|
+
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;`;
|
|
775
|
+
}
|
|
776
|
+
catch (error) {
|
|
777
|
+
this.logger.error("Failed to delete cookie:", error);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
658
780
|
async init() {
|
|
659
781
|
await this.indexedDB.init();
|
|
660
782
|
}
|
|
@@ -739,9 +861,17 @@ class AttributionStorageManager {
|
|
|
739
861
|
}
|
|
740
862
|
}
|
|
741
863
|
|
|
864
|
+
;// ./src/version.ts
|
|
865
|
+
/**
|
|
866
|
+
* SDK Version
|
|
867
|
+
* This version should match the version in package.json
|
|
868
|
+
*/
|
|
869
|
+
const SDK_VERSION = "2.0.0";
|
|
870
|
+
|
|
742
871
|
;// ./src/queue/index.ts
|
|
743
872
|
|
|
744
873
|
|
|
874
|
+
|
|
745
875
|
class EventQueueManager {
|
|
746
876
|
constructor(logger, apiKey, apiEndpoint, batchSize = 100, batchInterval = 2000, maxRetries = 3, retryDelay = 1000, sendEvents) {
|
|
747
877
|
this.queue = [];
|
|
@@ -879,7 +1009,10 @@ class EventHttpClient {
|
|
|
879
1009
|
context: event.context || null,
|
|
880
1010
|
timestamp: event.timestamp || getTimestamp(), // Convert to seconds
|
|
881
1011
|
}));
|
|
882
|
-
const batchRequest = {
|
|
1012
|
+
const batchRequest = {
|
|
1013
|
+
events: transformedEvents,
|
|
1014
|
+
sdk_version: SDK_VERSION,
|
|
1015
|
+
};
|
|
883
1016
|
await retry(async () => {
|
|
884
1017
|
const response = await fetch(`${this.apiEndpoint}/attribution/events`, {
|
|
885
1018
|
method: "POST",
|
|
@@ -1008,8 +1141,17 @@ class AttributionSDK {
|
|
|
1008
1141
|
}
|
|
1009
1142
|
try {
|
|
1010
1143
|
this.logger.info("Initializing GetuAI Attribution SDK");
|
|
1011
|
-
// Initialize storage
|
|
1012
|
-
|
|
1144
|
+
// Initialize storage (IndexedDB failure should not block SDK initialization)
|
|
1145
|
+
try {
|
|
1146
|
+
await this.storage.init();
|
|
1147
|
+
}
|
|
1148
|
+
catch (storageError) {
|
|
1149
|
+
this.logger.warn("Storage initialization failed (IndexedDB may be unavailable), continuing with basic features:", storageError);
|
|
1150
|
+
// Continue initialization even if IndexedDB fails
|
|
1151
|
+
// User ID and other features using cookie/localStorage will still work
|
|
1152
|
+
}
|
|
1153
|
+
// Initialize user ID (from config or existing storage)
|
|
1154
|
+
this.initializeUserId();
|
|
1013
1155
|
// Initialize session
|
|
1014
1156
|
this.initializeSession();
|
|
1015
1157
|
// Extract and store UTM data from current URL
|
|
@@ -1082,10 +1224,12 @@ class AttributionSDK {
|
|
|
1082
1224
|
last_activity: this.session?.lastActivity,
|
|
1083
1225
|
page_views: this.session?.pageViews,
|
|
1084
1226
|
};
|
|
1227
|
+
// Use provided tracking_user_id or fallback to stored user ID
|
|
1228
|
+
const finalUserId = tracking_user_id || this.getUserId();
|
|
1085
1229
|
const event = {
|
|
1086
1230
|
event_id: generateId(),
|
|
1087
1231
|
event_type: eventType,
|
|
1088
|
-
tracking_user_id:
|
|
1232
|
+
tracking_user_id: finalUserId || undefined,
|
|
1089
1233
|
timestamp: getTimestamp(),
|
|
1090
1234
|
event_data: eventData,
|
|
1091
1235
|
context: { page: pageContext, session: sessionContext },
|
|
@@ -1182,6 +1326,42 @@ class AttributionSDK {
|
|
|
1182
1326
|
async trackEmailVerification(tracking_user_id, verificationData) {
|
|
1183
1327
|
await this.trackEvent(EventType.EMAIL_VERIFICATION, verificationData, tracking_user_id);
|
|
1184
1328
|
}
|
|
1329
|
+
// Track purchase with auto user ID (object parameter format)
|
|
1330
|
+
async trackPurchaseAuto(options) {
|
|
1331
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
1332
|
+
if (!userId) {
|
|
1333
|
+
this.logger.error("❌ trackPurchaseAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
await this.trackEvent(EventType.PURCHASE, options.purchaseData, userId, options.revenue, options.currency || Currency.USD);
|
|
1337
|
+
}
|
|
1338
|
+
// Track login with auto user ID (object parameter format)
|
|
1339
|
+
async trackLoginAuto(options) {
|
|
1340
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
1341
|
+
if (!userId) {
|
|
1342
|
+
this.logger.error("❌ trackLoginAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
await this.trackEvent(EventType.LOGIN, options.loginData, userId);
|
|
1346
|
+
}
|
|
1347
|
+
// Track signup with auto user ID (object parameter format)
|
|
1348
|
+
async trackSignupAuto(options) {
|
|
1349
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
1350
|
+
if (!userId) {
|
|
1351
|
+
this.logger.error("❌ trackSignupAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
await this.trackEvent(EventType.SIGNUP, options.signupData, userId);
|
|
1355
|
+
}
|
|
1356
|
+
// Track email verification with auto user ID (object parameter format)
|
|
1357
|
+
async trackEmailVerificationAuto(options) {
|
|
1358
|
+
const userId = options.tracking_user_id || this.getUserId();
|
|
1359
|
+
if (!userId) {
|
|
1360
|
+
this.logger.error("❌ trackEmailVerificationAuto requires tracking_user_id. Please set user ID using setUserId() or pass it in options.tracking_user_id.");
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
await this.trackEvent(EventType.EMAIL_VERIFICATION, options.verificationData, userId);
|
|
1364
|
+
}
|
|
1185
1365
|
// Track product view
|
|
1186
1366
|
async trackProductView(tracking_user_id, productData) {
|
|
1187
1367
|
await this.trackEvent(EventType.PRODUCT_VIEW, productData, tracking_user_id);
|
|
@@ -1190,6 +1370,10 @@ class AttributionSDK {
|
|
|
1190
1370
|
async trackAddToCart(tracking_user_id, cartData) {
|
|
1191
1371
|
await this.trackEvent(EventType.ADD_TO_CART, cartData, tracking_user_id);
|
|
1192
1372
|
}
|
|
1373
|
+
// Track page click for user click journey
|
|
1374
|
+
async trackPageClick(tracking_user_id, clickData) {
|
|
1375
|
+
await this.trackEvent(EventType.PAGE_CLICK, clickData, tracking_user_id);
|
|
1376
|
+
}
|
|
1193
1377
|
// Get attribution data
|
|
1194
1378
|
getAttributionData() {
|
|
1195
1379
|
return this.storage.getUTMData();
|
|
@@ -1263,6 +1447,42 @@ class AttributionSDK {
|
|
|
1263
1447
|
this.logger.debug("UTM params for event:", filteredParams);
|
|
1264
1448
|
return filteredParams;
|
|
1265
1449
|
}
|
|
1450
|
+
// Initialize user ID
|
|
1451
|
+
initializeUserId() {
|
|
1452
|
+
// If userId is provided in config, set it (will override existing)
|
|
1453
|
+
if (this.config.userId) {
|
|
1454
|
+
this.setUserId(this.config.userId);
|
|
1455
|
+
this.logger.info(`👤 User ID initialized from config: ${this.config.userId}`);
|
|
1456
|
+
}
|
|
1457
|
+
else {
|
|
1458
|
+
// Check if user ID already exists in storage
|
|
1459
|
+
const existingUserId = this.getUserId();
|
|
1460
|
+
if (existingUserId) {
|
|
1461
|
+
this.logger.debug(`👤 Existing user ID found: ${existingUserId}`);
|
|
1462
|
+
}
|
|
1463
|
+
else {
|
|
1464
|
+
this.logger.debug("👤 No user ID found, will be set when user identifies");
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
// Set user ID
|
|
1469
|
+
setUserId(userId) {
|
|
1470
|
+
if (!userId || userId.trim() === "") {
|
|
1471
|
+
this.logger.warn("Cannot set empty user ID");
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
this.storage.setUserId(userId);
|
|
1475
|
+
this.logger.info(`👤 User ID set: ${userId}`);
|
|
1476
|
+
}
|
|
1477
|
+
// Get user ID
|
|
1478
|
+
getUserId() {
|
|
1479
|
+
return this.storage.getUserId();
|
|
1480
|
+
}
|
|
1481
|
+
// Remove user ID
|
|
1482
|
+
removeUserId() {
|
|
1483
|
+
this.storage.removeUserId();
|
|
1484
|
+
this.logger.info("👤 User ID removed");
|
|
1485
|
+
}
|
|
1266
1486
|
// Initialize user session
|
|
1267
1487
|
initializeSession() {
|
|
1268
1488
|
const existingSession = this.storage.getSession();
|
|
@@ -1715,6 +1935,7 @@ function autoInit() {
|
|
|
1715
1935
|
autoCleanUTM: script.getAttribute("data-auto-clean-utm") !== "false",
|
|
1716
1936
|
batchSize: parseInt(script.getAttribute("data-batch-size") || "100"),
|
|
1717
1937
|
batchInterval: parseInt(script.getAttribute("data-batch-interval") || "2000"),
|
|
1938
|
+
userId: script.getAttribute("data-user-id") || undefined,
|
|
1718
1939
|
};
|
|
1719
1940
|
// Initialize SDK
|
|
1720
1941
|
init(config);
|
|
@@ -1858,6 +2079,42 @@ async function trackEmailVerification(tracking_user_id, verificationData) {
|
|
|
1858
2079
|
}
|
|
1859
2080
|
await sdk.trackEmailVerification(tracking_user_id, verificationData);
|
|
1860
2081
|
}
|
|
2082
|
+
// Track purchase with auto user ID (object parameter format)
|
|
2083
|
+
async function trackPurchaseAuto(options) {
|
|
2084
|
+
const sdk = getSDK();
|
|
2085
|
+
if (!sdk) {
|
|
2086
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2087
|
+
return;
|
|
2088
|
+
}
|
|
2089
|
+
await sdk.trackPurchaseAuto(options);
|
|
2090
|
+
}
|
|
2091
|
+
// Track login with auto user ID (object parameter format)
|
|
2092
|
+
async function trackLoginAuto(options) {
|
|
2093
|
+
const sdk = getSDK();
|
|
2094
|
+
if (!sdk) {
|
|
2095
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2096
|
+
return;
|
|
2097
|
+
}
|
|
2098
|
+
await sdk.trackLoginAuto(options);
|
|
2099
|
+
}
|
|
2100
|
+
// Track signup with auto user ID (object parameter format)
|
|
2101
|
+
async function trackSignupAuto(options) {
|
|
2102
|
+
const sdk = getSDK();
|
|
2103
|
+
if (!sdk) {
|
|
2104
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2105
|
+
return;
|
|
2106
|
+
}
|
|
2107
|
+
await sdk.trackSignupAuto(options);
|
|
2108
|
+
}
|
|
2109
|
+
// Track email verification with auto user ID (object parameter format)
|
|
2110
|
+
async function trackEmailVerificationAuto(options) {
|
|
2111
|
+
const sdk = getSDK();
|
|
2112
|
+
if (!sdk) {
|
|
2113
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
await sdk.trackEmailVerificationAuto(options);
|
|
2117
|
+
}
|
|
1861
2118
|
// Track product view
|
|
1862
2119
|
async function trackProductView(tracking_user_id, productData) {
|
|
1863
2120
|
const sdk = getSDK();
|
|
@@ -1876,6 +2133,15 @@ async function trackAddToCart(tracking_user_id, cartData) {
|
|
|
1876
2133
|
}
|
|
1877
2134
|
await sdk.trackAddToCart(tracking_user_id, cartData);
|
|
1878
2135
|
}
|
|
2136
|
+
// Track page click for user click journey
|
|
2137
|
+
async function trackPageClick(tracking_user_id, clickData) {
|
|
2138
|
+
const sdk = getSDK();
|
|
2139
|
+
if (!sdk) {
|
|
2140
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
await sdk.trackPageClick(tracking_user_id, clickData);
|
|
2144
|
+
}
|
|
1879
2145
|
// Get attribution data
|
|
1880
2146
|
function getAttributionData() {
|
|
1881
2147
|
const sdk = getSDK();
|
|
@@ -1918,6 +2184,33 @@ function getCurrentUTMParams() {
|
|
|
1918
2184
|
}
|
|
1919
2185
|
return sdk.getCurrentUTMParams();
|
|
1920
2186
|
}
|
|
2187
|
+
// Set user ID
|
|
2188
|
+
function setUserId(userId) {
|
|
2189
|
+
const sdk = getSDK();
|
|
2190
|
+
if (!sdk) {
|
|
2191
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
sdk.setUserId(userId);
|
|
2195
|
+
}
|
|
2196
|
+
// Get user ID
|
|
2197
|
+
function getUserId() {
|
|
2198
|
+
const sdk = getSDK();
|
|
2199
|
+
if (!sdk) {
|
|
2200
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2201
|
+
return null;
|
|
2202
|
+
}
|
|
2203
|
+
return sdk.getUserId();
|
|
2204
|
+
}
|
|
2205
|
+
// Remove user ID
|
|
2206
|
+
function removeUserId() {
|
|
2207
|
+
const sdk = getSDK();
|
|
2208
|
+
if (!sdk) {
|
|
2209
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
sdk.removeUserId();
|
|
2213
|
+
}
|
|
1921
2214
|
// Destroy SDK
|
|
1922
2215
|
function destroy() {
|
|
1923
2216
|
if (globalSDK) {
|
|
@@ -1964,6 +2257,22 @@ class AttributionSDKStatic extends AttributionSDK {
|
|
|
1964
2257
|
static async trackEmailVerification(tracking_user_id, verificationData) {
|
|
1965
2258
|
return await trackEmailVerification(tracking_user_id, verificationData);
|
|
1966
2259
|
}
|
|
2260
|
+
// Static method to track purchase with auto user ID
|
|
2261
|
+
static async trackPurchaseAuto(options) {
|
|
2262
|
+
return await trackPurchaseAuto(options);
|
|
2263
|
+
}
|
|
2264
|
+
// Static method to track login with auto user ID
|
|
2265
|
+
static async trackLoginAuto(options) {
|
|
2266
|
+
return await trackLoginAuto(options);
|
|
2267
|
+
}
|
|
2268
|
+
// Static method to track signup with auto user ID
|
|
2269
|
+
static async trackSignupAuto(options) {
|
|
2270
|
+
return await trackSignupAuto(options);
|
|
2271
|
+
}
|
|
2272
|
+
// Static method to track email verification with auto user ID
|
|
2273
|
+
static async trackEmailVerificationAuto(options) {
|
|
2274
|
+
return await trackEmailVerificationAuto(options);
|
|
2275
|
+
}
|
|
1967
2276
|
// Static method to track product view
|
|
1968
2277
|
static async trackProductView(tracking_user_id, productData) {
|
|
1969
2278
|
return await trackProductView(tracking_user_id, productData);
|
|
@@ -1972,6 +2281,10 @@ class AttributionSDKStatic extends AttributionSDK {
|
|
|
1972
2281
|
static async trackAddToCart(tracking_user_id, cartData) {
|
|
1973
2282
|
return await trackAddToCart(tracking_user_id, cartData);
|
|
1974
2283
|
}
|
|
2284
|
+
// Static method to track page click
|
|
2285
|
+
static async trackPageClick(tracking_user_id, clickData) {
|
|
2286
|
+
return await trackPageClick(tracking_user_id, clickData);
|
|
2287
|
+
}
|
|
1975
2288
|
// Static method to get attribution data
|
|
1976
2289
|
static getAttributionData() {
|
|
1977
2290
|
return getAttributionData();
|
|
@@ -1992,6 +2305,18 @@ class AttributionSDKStatic extends AttributionSDK {
|
|
|
1992
2305
|
static getCurrentUTMParams() {
|
|
1993
2306
|
return getCurrentUTMParams();
|
|
1994
2307
|
}
|
|
2308
|
+
// Static method to set user ID
|
|
2309
|
+
static setUserId(userId) {
|
|
2310
|
+
setUserId(userId);
|
|
2311
|
+
}
|
|
2312
|
+
// Static method to get user ID
|
|
2313
|
+
static getUserId() {
|
|
2314
|
+
return getUserId();
|
|
2315
|
+
}
|
|
2316
|
+
// Static method to remove user ID
|
|
2317
|
+
static removeUserId() {
|
|
2318
|
+
removeUserId();
|
|
2319
|
+
}
|
|
1995
2320
|
// Static method to destroy SDK
|
|
1996
2321
|
static destroy() {
|
|
1997
2322
|
destroy();
|
|
@@ -2025,6 +2350,7 @@ if (typeof window !== "undefined") {
|
|
|
2025
2350
|
waitForSDK,
|
|
2026
2351
|
trackEvent,
|
|
2027
2352
|
trackPageView,
|
|
2353
|
+
trackPageClick,
|
|
2028
2354
|
trackPurchase,
|
|
2029
2355
|
trackLogin,
|
|
2030
2356
|
trackSignup,
|
|
@@ -2033,11 +2359,18 @@ if (typeof window !== "undefined") {
|
|
|
2033
2359
|
trackEmailVerification,
|
|
2034
2360
|
trackProductView,
|
|
2035
2361
|
trackAddToCart,
|
|
2362
|
+
trackPurchaseAuto,
|
|
2363
|
+
trackLoginAuto,
|
|
2364
|
+
trackSignupAuto,
|
|
2365
|
+
trackEmailVerificationAuto,
|
|
2036
2366
|
getAttributionData,
|
|
2037
2367
|
flush,
|
|
2038
2368
|
getStatus,
|
|
2039
2369
|
addUTMToURL: src_addUTMToURL,
|
|
2040
2370
|
getCurrentUTMParams,
|
|
2371
|
+
setUserId,
|
|
2372
|
+
getUserId,
|
|
2373
|
+
removeUserId,
|
|
2041
2374
|
destroy,
|
|
2042
2375
|
EventType: EventType,
|
|
2043
2376
|
Currency: Currency,
|
|
@@ -2048,6 +2381,7 @@ if (typeof window !== "undefined") {
|
|
|
2048
2381
|
window.waitForSDK = waitForSDK;
|
|
2049
2382
|
window.trackEvent = trackEvent;
|
|
2050
2383
|
window.trackPageView = trackPageView;
|
|
2384
|
+
window.trackPageClick = trackPageClick;
|
|
2051
2385
|
window.trackPurchase = trackPurchase;
|
|
2052
2386
|
window.trackLogin = trackLogin;
|
|
2053
2387
|
window.trackSignup = trackSignup;
|
|
@@ -2056,11 +2390,18 @@ if (typeof window !== "undefined") {
|
|
|
2056
2390
|
window.trackEmailVerification = trackEmailVerification;
|
|
2057
2391
|
window.trackProductView = trackProductView;
|
|
2058
2392
|
window.trackAddToCart = trackAddToCart;
|
|
2393
|
+
window.trackPurchaseAuto = trackPurchaseAuto;
|
|
2394
|
+
window.trackLoginAuto = trackLoginAuto;
|
|
2395
|
+
window.trackSignupAuto = trackSignupAuto;
|
|
2396
|
+
window.trackEmailVerificationAuto = trackEmailVerificationAuto;
|
|
2059
2397
|
window.getAttributionData = getAttributionData;
|
|
2060
2398
|
window.flush = flush;
|
|
2061
2399
|
window.getStatus = getStatus;
|
|
2062
2400
|
window.addUTMToURL = src_addUTMToURL;
|
|
2063
2401
|
window.getCurrentUTMParams = getCurrentUTMParams;
|
|
2402
|
+
window.setUserId = setUserId;
|
|
2403
|
+
window.getUserId = getUserId;
|
|
2404
|
+
window.removeUserId = removeUserId;
|
|
2064
2405
|
window.destroy = destroy;
|
|
2065
2406
|
window.AttributionSDK = AttributionSDKStatic; // 直接暴露带静态方法的AttributionSDK类
|
|
2066
2407
|
}
|
|
@@ -2071,6 +2412,7 @@ if (typeof window !== "undefined") {
|
|
|
2071
2412
|
waitForSDK,
|
|
2072
2413
|
trackEvent,
|
|
2073
2414
|
trackPageView,
|
|
2415
|
+
trackPageClick,
|
|
2074
2416
|
trackPurchase,
|
|
2075
2417
|
trackLogin,
|
|
2076
2418
|
trackSignup,
|
|
@@ -2079,11 +2421,18 @@ if (typeof window !== "undefined") {
|
|
|
2079
2421
|
trackEmailVerification,
|
|
2080
2422
|
trackProductView,
|
|
2081
2423
|
trackAddToCart,
|
|
2424
|
+
trackPurchaseAuto,
|
|
2425
|
+
trackLoginAuto,
|
|
2426
|
+
trackSignupAuto,
|
|
2427
|
+
trackEmailVerificationAuto,
|
|
2082
2428
|
getAttributionData,
|
|
2083
2429
|
flush,
|
|
2084
2430
|
getStatus,
|
|
2085
2431
|
addUTMToURL: src_addUTMToURL,
|
|
2086
2432
|
getCurrentUTMParams,
|
|
2433
|
+
setUserId,
|
|
2434
|
+
getUserId,
|
|
2435
|
+
removeUserId,
|
|
2087
2436
|
destroy,
|
|
2088
2437
|
EventType: EventType,
|
|
2089
2438
|
Currency: Currency,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EAET,eAAe,EAEhB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EAET,eAAe,EAEhB,MAAM,UAAU,CAAC;AAIlB,qBAAa,iBAAkB,YAAW,cAAc;IACtD,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,aAAa,CA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AAmB,YAAW,cAAc;IACvD,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAkB;gBAEpB,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,MAAa;IAK3D,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAUrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B,KAAK,IAAI,IAAI;IAKb,IAAI,IAAI,MAAM;IAKd,YAAY,IAAI,SAAS,EAAE;IAK3B,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;CAKvC"}
|
package/dist/queue/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IMMEDIATE_EVENTS, } from "../types";
|
|
2
2
|
import { retry, debounce, getTimestamp } from "../utils";
|
|
3
|
+
import { SDK_VERSION } from "../version";
|
|
3
4
|
export class EventQueueManager {
|
|
4
5
|
constructor(logger, apiKey, apiEndpoint, batchSize = 100, batchInterval = 2000, maxRetries = 3, retryDelay = 1000, sendEvents) {
|
|
5
6
|
this.queue = [];
|
|
@@ -137,7 +138,10 @@ export class EventHttpClient {
|
|
|
137
138
|
context: event.context || null,
|
|
138
139
|
timestamp: event.timestamp || getTimestamp(), // Convert to seconds
|
|
139
140
|
}));
|
|
140
|
-
const batchRequest = {
|
|
141
|
+
const batchRequest = {
|
|
142
|
+
events: transformedEvents,
|
|
143
|
+
sdk_version: SDK_VERSION,
|
|
144
|
+
};
|
|
141
145
|
await retry(async () => {
|
|
142
146
|
const response = await fetch(`${this.apiEndpoint}/attribution/events`, {
|
|
143
147
|
method: "POST",
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -29,7 +29,15 @@ export declare class AttributionStorageManager {
|
|
|
29
29
|
private logger;
|
|
30
30
|
private readonly UTM_STORAGE_KEY;
|
|
31
31
|
private readonly SESSION_STORAGE_KEY;
|
|
32
|
+
private readonly USER_ID_KEY;
|
|
33
|
+
private readonly USER_ID_COOKIE_EXPIRES;
|
|
32
34
|
constructor(logger: LoggerInterface);
|
|
35
|
+
setUserId(userId: string): void;
|
|
36
|
+
getUserId(): string | null;
|
|
37
|
+
removeUserId(): void;
|
|
38
|
+
private setCookie;
|
|
39
|
+
private getCookie;
|
|
40
|
+
private deleteCookie;
|
|
33
41
|
init(): Promise<void>;
|
|
34
42
|
storeUTMData(utmData: Partial<AttributionData>): void;
|
|
35
43
|
getUTMData(): AttributionData | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,eAAe,EAEhB,MAAM,UAAU,CAAC;AASlB,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,OAAO,CAAC,MAAM,CAAkB;gBAEpB,MAAM,EAAE,eAAe;IAInC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IAmBrB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAelC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAUzB,KAAK,IAAI,IAAI;IAUb,OAAO,CAAC,mBAAmB;CA4B5B;AAGD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAgC;IAC9C,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,EAAE,CAA4B;gBAE1B,MAAM,EAAE,eAAe;IAI7B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAoCrB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BzC,eAAe,CAAC,KAAK,GAAE,MAAY,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IA2B1D,gBAAgB,CAAC,QAAQ,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