getu-attribution-v2-sdk 0.1.0 → 0.2.1
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 +129 -2
- package/dist/core/AttributionSDK.d.ts +5 -0
- package/dist/core/AttributionSDK.d.ts.map +1 -1
- package/dist/core/AttributionSDK.js +21 -1
- package/dist/getuai-attribution.min.js +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +115 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +117 -5
- package/dist/queue/index.d.ts.map +1 -1
- package/dist/queue/index.js +6 -2
- package/dist/types/index.d.ts +2 -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 +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -3,6 +3,7 @@ var EventType;
|
|
|
3
3
|
(function (EventType) {
|
|
4
4
|
// Pre-conversion signals
|
|
5
5
|
EventType["PAGE_VIEW"] = "page_view";
|
|
6
|
+
EventType["PAGE_CLICK"] = "page_click";
|
|
6
7
|
EventType["VIDEO_PLAY"] = "video_play";
|
|
7
8
|
// Registration funnel
|
|
8
9
|
EventType["FORM_SUBMIT"] = "form_submit";
|
|
@@ -637,8 +638,14 @@ class AttributionStorageManager {
|
|
|
637
638
|
}
|
|
638
639
|
}
|
|
639
640
|
|
|
641
|
+
/**
|
|
642
|
+
* SDK Version
|
|
643
|
+
* This version should match the version in package.json
|
|
644
|
+
*/
|
|
645
|
+
const SDK_VERSION = "2.0.0";
|
|
646
|
+
|
|
640
647
|
class EventQueueManager {
|
|
641
|
-
constructor(logger, apiKey, apiEndpoint, batchSize = 100, batchInterval =
|
|
648
|
+
constructor(logger, apiKey, apiEndpoint, batchSize = 100, batchInterval = 2000, maxRetries = 3, retryDelay = 1000, sendEvents) {
|
|
642
649
|
this.queue = [];
|
|
643
650
|
this.processing = false;
|
|
644
651
|
this.batchTimer = null;
|
|
@@ -774,7 +781,10 @@ class EventHttpClient {
|
|
|
774
781
|
context: event.context || null,
|
|
775
782
|
timestamp: event.timestamp || getTimestamp(), // Convert to seconds
|
|
776
783
|
}));
|
|
777
|
-
const batchRequest = {
|
|
784
|
+
const batchRequest = {
|
|
785
|
+
events: transformedEvents,
|
|
786
|
+
sdk_version: SDK_VERSION,
|
|
787
|
+
};
|
|
778
788
|
await retry(async () => {
|
|
779
789
|
const response = await fetch(`${this.apiEndpoint}/attribution/events`, {
|
|
780
790
|
method: "POST",
|
|
@@ -830,7 +840,7 @@ class AttributionSDK {
|
|
|
830
840
|
this.config = {
|
|
831
841
|
apiEndpoint: defaultEndpoint,
|
|
832
842
|
batchSize: 100,
|
|
833
|
-
batchInterval:
|
|
843
|
+
batchInterval: 2000,
|
|
834
844
|
maxRetries: 3,
|
|
835
845
|
retryDelay: 1000,
|
|
836
846
|
enableDebug: false,
|
|
@@ -1028,6 +1038,26 @@ class AttributionSDK {
|
|
|
1028
1038
|
async trackFormSubmit(tracking_user_id, formData) {
|
|
1029
1039
|
await this.trackEvent(EventType.FORM_SUBMIT, formData, tracking_user_id);
|
|
1030
1040
|
}
|
|
1041
|
+
// Track video play
|
|
1042
|
+
async trackVideoPlay(tracking_user_id, videoData) {
|
|
1043
|
+
await this.trackEvent(EventType.VIDEO_PLAY, videoData, tracking_user_id);
|
|
1044
|
+
}
|
|
1045
|
+
// Track email verification
|
|
1046
|
+
async trackEmailVerification(tracking_user_id, verificationData) {
|
|
1047
|
+
await this.trackEvent(EventType.EMAIL_VERIFICATION, verificationData, tracking_user_id);
|
|
1048
|
+
}
|
|
1049
|
+
// Track product view
|
|
1050
|
+
async trackProductView(tracking_user_id, productData) {
|
|
1051
|
+
await this.trackEvent(EventType.PRODUCT_VIEW, productData, tracking_user_id);
|
|
1052
|
+
}
|
|
1053
|
+
// Track add to cart
|
|
1054
|
+
async trackAddToCart(tracking_user_id, cartData) {
|
|
1055
|
+
await this.trackEvent(EventType.ADD_TO_CART, cartData, tracking_user_id);
|
|
1056
|
+
}
|
|
1057
|
+
// Track page click for user click journey
|
|
1058
|
+
async trackPageClick(tracking_user_id, clickData) {
|
|
1059
|
+
await this.trackEvent(EventType.PAGE_CLICK, clickData, tracking_user_id);
|
|
1060
|
+
}
|
|
1031
1061
|
// Get attribution data
|
|
1032
1062
|
getAttributionData() {
|
|
1033
1063
|
return this.storage.getUTMData();
|
|
@@ -1549,7 +1579,7 @@ function autoInit() {
|
|
|
1549
1579
|
autoTrackPageView: script.getAttribute("data-auto-track-page-view") === "true",
|
|
1550
1580
|
autoCleanUTM: script.getAttribute("data-auto-clean-utm") !== "false",
|
|
1551
1581
|
batchSize: parseInt(script.getAttribute("data-batch-size") || "100"),
|
|
1552
|
-
batchInterval: parseInt(script.getAttribute("data-batch-interval") || "
|
|
1582
|
+
batchInterval: parseInt(script.getAttribute("data-batch-interval") || "2000"),
|
|
1553
1583
|
};
|
|
1554
1584
|
// Initialize SDK
|
|
1555
1585
|
init(config);
|
|
@@ -1675,6 +1705,51 @@ async function trackFormSubmit(tracking_user_id, formData) {
|
|
|
1675
1705
|
}
|
|
1676
1706
|
await sdk.trackFormSubmit(tracking_user_id, formData);
|
|
1677
1707
|
}
|
|
1708
|
+
// Track video play
|
|
1709
|
+
async function trackVideoPlay(tracking_user_id, videoData) {
|
|
1710
|
+
const sdk = getSDK();
|
|
1711
|
+
if (!sdk) {
|
|
1712
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
await sdk.trackVideoPlay(tracking_user_id, videoData);
|
|
1716
|
+
}
|
|
1717
|
+
// Track email verification
|
|
1718
|
+
async function trackEmailVerification(tracking_user_id, verificationData) {
|
|
1719
|
+
const sdk = getSDK();
|
|
1720
|
+
if (!sdk) {
|
|
1721
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1724
|
+
await sdk.trackEmailVerification(tracking_user_id, verificationData);
|
|
1725
|
+
}
|
|
1726
|
+
// Track product view
|
|
1727
|
+
async function trackProductView(tracking_user_id, productData) {
|
|
1728
|
+
const sdk = getSDK();
|
|
1729
|
+
if (!sdk) {
|
|
1730
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1733
|
+
await sdk.trackProductView(tracking_user_id, productData);
|
|
1734
|
+
}
|
|
1735
|
+
// Track add to cart
|
|
1736
|
+
async function trackAddToCart(tracking_user_id, cartData) {
|
|
1737
|
+
const sdk = getSDK();
|
|
1738
|
+
if (!sdk) {
|
|
1739
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
await sdk.trackAddToCart(tracking_user_id, cartData);
|
|
1743
|
+
}
|
|
1744
|
+
// Track page click for user click journey
|
|
1745
|
+
async function trackPageClick(tracking_user_id, clickData) {
|
|
1746
|
+
const sdk = getSDK();
|
|
1747
|
+
if (!sdk) {
|
|
1748
|
+
console.warn("GetuAI SDK: Not initialized. Call init() first.");
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
await sdk.trackPageClick(tracking_user_id, clickData);
|
|
1752
|
+
}
|
|
1678
1753
|
// Get attribution data
|
|
1679
1754
|
function getAttributionData() {
|
|
1680
1755
|
const sdk = getSDK();
|
|
@@ -1755,6 +1830,26 @@ class AttributionSDKStatic extends AttributionSDK {
|
|
|
1755
1830
|
static async trackFormSubmit(tracking_user_id, formData) {
|
|
1756
1831
|
return await trackFormSubmit(tracking_user_id, formData);
|
|
1757
1832
|
}
|
|
1833
|
+
// Static method to track video play
|
|
1834
|
+
static async trackVideoPlay(tracking_user_id, videoData) {
|
|
1835
|
+
return await trackVideoPlay(tracking_user_id, videoData);
|
|
1836
|
+
}
|
|
1837
|
+
// Static method to track email verification
|
|
1838
|
+
static async trackEmailVerification(tracking_user_id, verificationData) {
|
|
1839
|
+
return await trackEmailVerification(tracking_user_id, verificationData);
|
|
1840
|
+
}
|
|
1841
|
+
// Static method to track product view
|
|
1842
|
+
static async trackProductView(tracking_user_id, productData) {
|
|
1843
|
+
return await trackProductView(tracking_user_id, productData);
|
|
1844
|
+
}
|
|
1845
|
+
// Static method to track add to cart
|
|
1846
|
+
static async trackAddToCart(tracking_user_id, cartData) {
|
|
1847
|
+
return await trackAddToCart(tracking_user_id, cartData);
|
|
1848
|
+
}
|
|
1849
|
+
// Static method to track page click
|
|
1850
|
+
static async trackPageClick(tracking_user_id, clickData) {
|
|
1851
|
+
return await trackPageClick(tracking_user_id, clickData);
|
|
1852
|
+
}
|
|
1758
1853
|
// Static method to get attribution data
|
|
1759
1854
|
static getAttributionData() {
|
|
1760
1855
|
return getAttributionData();
|
|
@@ -1802,10 +1897,15 @@ if (typeof window !== "undefined") {
|
|
|
1802
1897
|
waitForSDK,
|
|
1803
1898
|
trackEvent,
|
|
1804
1899
|
trackPageView,
|
|
1900
|
+
trackPageClick,
|
|
1805
1901
|
trackPurchase,
|
|
1806
1902
|
trackLogin,
|
|
1807
1903
|
trackSignup,
|
|
1808
1904
|
trackFormSubmit,
|
|
1905
|
+
trackVideoPlay,
|
|
1906
|
+
trackEmailVerification,
|
|
1907
|
+
trackProductView,
|
|
1908
|
+
trackAddToCart,
|
|
1809
1909
|
getAttributionData,
|
|
1810
1910
|
flush,
|
|
1811
1911
|
getStatus,
|
|
@@ -1821,10 +1921,15 @@ if (typeof window !== "undefined") {
|
|
|
1821
1921
|
window.waitForSDK = waitForSDK;
|
|
1822
1922
|
window.trackEvent = trackEvent;
|
|
1823
1923
|
window.trackPageView = trackPageView;
|
|
1924
|
+
window.trackPageClick = trackPageClick;
|
|
1824
1925
|
window.trackPurchase = trackPurchase;
|
|
1825
1926
|
window.trackLogin = trackLogin;
|
|
1826
1927
|
window.trackSignup = trackSignup;
|
|
1827
1928
|
window.trackFormSubmit = trackFormSubmit;
|
|
1929
|
+
window.trackVideoPlay = trackVideoPlay;
|
|
1930
|
+
window.trackEmailVerification = trackEmailVerification;
|
|
1931
|
+
window.trackProductView = trackProductView;
|
|
1932
|
+
window.trackAddToCart = trackAddToCart;
|
|
1828
1933
|
window.getAttributionData = getAttributionData;
|
|
1829
1934
|
window.flush = flush;
|
|
1830
1935
|
window.getStatus = getStatus;
|
|
@@ -1840,10 +1945,15 @@ var index = {
|
|
|
1840
1945
|
waitForSDK,
|
|
1841
1946
|
trackEvent,
|
|
1842
1947
|
trackPageView,
|
|
1948
|
+
trackPageClick,
|
|
1843
1949
|
trackPurchase,
|
|
1844
1950
|
trackLogin,
|
|
1845
1951
|
trackSignup,
|
|
1846
1952
|
trackFormSubmit,
|
|
1953
|
+
trackVideoPlay,
|
|
1954
|
+
trackEmailVerification,
|
|
1955
|
+
trackProductView,
|
|
1956
|
+
trackAddToCart,
|
|
1847
1957
|
getAttributionData,
|
|
1848
1958
|
flush,
|
|
1849
1959
|
getStatus,
|
|
@@ -1855,5 +1965,5 @@ var index = {
|
|
|
1855
1965
|
AttributionSDK: AttributionSDKStatic, // 包含带静态方法的AttributionSDK类
|
|
1856
1966
|
};
|
|
1857
1967
|
|
|
1858
|
-
export { AttributionSDKStatic as AttributionSDK, Currency, EventType, addUTMToURL, index as default, destroy, flush, getAttributionData, getCurrentUTMParams, getSDK, getStatus, init, trackEvent, trackFormSubmit, trackLogin, trackPageView, trackPurchase, trackSignup, waitForSDK };
|
|
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 };
|
|
1859
1969
|
//# sourceMappingURL=index.esm.js.map
|