@prodact.ai/sdk 0.0.7 → 0.0.9
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/cdn/sdk.global.js +81 -62
- package/dist/cdn/sdk.global.js.map +1 -1
- package/dist/index.js +152 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +152 -18
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +152 -18
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +152 -18
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -97,7 +97,8 @@ var DEFAULT_CAPTURE_CONFIG = {
|
|
|
97
97
|
};
|
|
98
98
|
function mergeConfig(userConfig) {
|
|
99
99
|
return {
|
|
100
|
-
enabled: userConfig?.enabled ??
|
|
100
|
+
enabled: userConfig?.enabled ?? true,
|
|
101
|
+
// Enabled by default!
|
|
101
102
|
samplingRate: userConfig?.samplingRate ?? 1,
|
|
102
103
|
privacy: { ...DEFAULT_PRIVACY_CONFIG, ...userConfig?.privacy },
|
|
103
104
|
performance: { ...DEFAULT_PERFORMANCE_CONFIG, ...userConfig?.performance },
|
|
@@ -1150,7 +1151,8 @@ async function captureElementScreenshot(element, maxSize = 200) {
|
|
|
1150
1151
|
}
|
|
1151
1152
|
function mergeConfig2(config) {
|
|
1152
1153
|
const defaults = {
|
|
1153
|
-
enabled:
|
|
1154
|
+
enabled: true,
|
|
1155
|
+
// Enabled by default!
|
|
1154
1156
|
samplingRate: 1,
|
|
1155
1157
|
events: {
|
|
1156
1158
|
clicks: true,
|
|
@@ -1275,7 +1277,15 @@ var UserFlowTracker = class {
|
|
|
1275
1277
|
console.warn("[UserFlow] Cannot track outside browser environment");
|
|
1276
1278
|
return null;
|
|
1277
1279
|
}
|
|
1280
|
+
console.log("[UserFlow] start() called", {
|
|
1281
|
+
enabled: this.config.enabled,
|
|
1282
|
+
samplingRate: this.config.samplingRate,
|
|
1283
|
+
currentState: this.state,
|
|
1284
|
+
apiUrl: this.apiUrl,
|
|
1285
|
+
hasSessionToken: !!this.sessionToken
|
|
1286
|
+
});
|
|
1278
1287
|
if (!this.config.enabled) {
|
|
1288
|
+
console.warn("[UserFlow] Tracking disabled by config");
|
|
1279
1289
|
return null;
|
|
1280
1290
|
}
|
|
1281
1291
|
if (this.state === "tracking") {
|
|
@@ -1621,16 +1631,25 @@ var UserFlowTracker = class {
|
|
|
1621
1631
|
// Link to rrweb recording session if available
|
|
1622
1632
|
linkedRecordingSessionId: this.linkedRecordingSessionId
|
|
1623
1633
|
};
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
+
try {
|
|
1635
|
+
const response = await fetch(endpoint, {
|
|
1636
|
+
method: "POST",
|
|
1637
|
+
headers: {
|
|
1638
|
+
"Content-Type": "application/json",
|
|
1639
|
+
...this.sdkKey ? { "X-SDK-Key": this.sdkKey } : {}
|
|
1640
|
+
},
|
|
1641
|
+
body: JSON.stringify(body)
|
|
1642
|
+
});
|
|
1643
|
+
if (!response.ok) {
|
|
1644
|
+
console.error("[UserFlow] Failed to start session:", response.status, response.statusText);
|
|
1645
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1646
|
+
throw new Error(`Failed to start session: ${response.status}`);
|
|
1647
|
+
}
|
|
1648
|
+
console.log("[UserFlow] Session started successfully:", this.sessionId);
|
|
1649
|
+
} catch (error) {
|
|
1650
|
+
console.error("[UserFlow] Network error starting session:", error);
|
|
1651
|
+
console.error("[UserFlow] Attempted endpoint:", endpoint);
|
|
1652
|
+
throw error;
|
|
1634
1653
|
}
|
|
1635
1654
|
}
|
|
1636
1655
|
/**
|
|
@@ -1659,9 +1678,15 @@ var UserFlowTracker = class {
|
|
|
1659
1678
|
});
|
|
1660
1679
|
if (response.ok) {
|
|
1661
1680
|
this.batchesSent++;
|
|
1681
|
+
console.log(`[UserFlow] Event batch ${this.batchIndex - 1} sent (${eventsToSend.length} events)`);
|
|
1682
|
+
} else {
|
|
1683
|
+
console.error("[UserFlow] Failed to send event batch:", response.status, response.statusText);
|
|
1684
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1685
|
+
this.events = [...eventsToSend, ...this.events];
|
|
1662
1686
|
}
|
|
1663
1687
|
} catch (error) {
|
|
1664
|
-
console.error("[UserFlow]
|
|
1688
|
+
console.error("[UserFlow] Network error sending event batch:", error);
|
|
1689
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1665
1690
|
this.events = [...eventsToSend, ...this.events];
|
|
1666
1691
|
}
|
|
1667
1692
|
}
|
|
@@ -1782,9 +1807,32 @@ var ProduckSDK = class {
|
|
|
1782
1807
|
/** User flow tracker instance (optional, isolated module) */
|
|
1783
1808
|
this.userFlowTracker = null;
|
|
1784
1809
|
let apiUrl = config.apiUrl;
|
|
1810
|
+
let apiUrlAutoDetected = false;
|
|
1785
1811
|
if (!apiUrl) {
|
|
1812
|
+
apiUrlAutoDetected = true;
|
|
1786
1813
|
if (typeof window !== "undefined") {
|
|
1787
|
-
|
|
1814
|
+
const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
|
|
1815
|
+
if (isLocalhost) {
|
|
1816
|
+
apiUrl = "http://localhost:4001/api/v1";
|
|
1817
|
+
} else {
|
|
1818
|
+
apiUrl = `${window.location.protocol}//${window.location.host}/api/v1`;
|
|
1819
|
+
console.warn(
|
|
1820
|
+
"%c\u26A0\uFE0F Produck SDK Warning: apiUrl not configured!",
|
|
1821
|
+
"background: #fbbf24; color: #000; padding: 4px 8px; font-weight: bold;"
|
|
1822
|
+
);
|
|
1823
|
+
console.warn(
|
|
1824
|
+
`The SDK is auto-detecting apiUrl as: ${apiUrl}
|
|
1825
|
+
This is likely WRONG for production. Your backend is probably at a different URL.
|
|
1826
|
+
|
|
1827
|
+
To fix this, provide apiUrl in your SDK config:
|
|
1828
|
+
|
|
1829
|
+
createProduck({
|
|
1830
|
+
sdkKey: 'your_sdk_key',
|
|
1831
|
+
apiUrl: 'https://your-backend.com/api/v1', // <-- Add this!
|
|
1832
|
+
})
|
|
1833
|
+
`
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1788
1836
|
} else {
|
|
1789
1837
|
apiUrl = "http://localhost:4001/api/v1";
|
|
1790
1838
|
}
|
|
@@ -1793,11 +1841,30 @@ var ProduckSDK = class {
|
|
|
1793
1841
|
apiUrl,
|
|
1794
1842
|
...config
|
|
1795
1843
|
};
|
|
1844
|
+
if (typeof window !== "undefined") {
|
|
1845
|
+
console.log(
|
|
1846
|
+
"%c\u{1F527} Produck SDK Config",
|
|
1847
|
+
"background: #3b82f6; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
1848
|
+
{
|
|
1849
|
+
apiUrl: this.config.apiUrl,
|
|
1850
|
+
apiUrlAutoDetected,
|
|
1851
|
+
sdkKey: this.config.sdkKey ? `${this.config.sdkKey.substring(0, 10)}...` : "not set",
|
|
1852
|
+
guiderId: this.config.guiderId || "not set"
|
|
1853
|
+
}
|
|
1854
|
+
);
|
|
1855
|
+
}
|
|
1796
1856
|
}
|
|
1797
1857
|
/**
|
|
1798
1858
|
* Initialize the SDK and create a chat session
|
|
1799
1859
|
*/
|
|
1800
1860
|
async init() {
|
|
1861
|
+
if (typeof window !== "undefined") {
|
|
1862
|
+
console.log(
|
|
1863
|
+
"%c\u{1F680} Produck SDK Initializing...",
|
|
1864
|
+
"background: #10b981; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
1865
|
+
{ endpoint: this.config.apiUrl }
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1801
1868
|
await this.log("info", "SDK Initializing", {
|
|
1802
1869
|
apiUrl: this.config.apiUrl,
|
|
1803
1870
|
hasSDKKey: !!this.config.sdkKey,
|
|
@@ -1824,20 +1891,43 @@ var ProduckSDK = class {
|
|
|
1824
1891
|
headers
|
|
1825
1892
|
});
|
|
1826
1893
|
if (!response.ok) {
|
|
1827
|
-
|
|
1894
|
+
let errorDetail = "";
|
|
1895
|
+
try {
|
|
1896
|
+
errorDetail = await response.text();
|
|
1897
|
+
} catch {
|
|
1898
|
+
errorDetail = "Could not read response body";
|
|
1899
|
+
}
|
|
1900
|
+
console.error(
|
|
1901
|
+
"%c\u274C Produck SDK: Failed to create session",
|
|
1902
|
+
"background: #ef4444; color: #fff; padding: 2px 6px; border-radius: 3px;"
|
|
1903
|
+
);
|
|
1904
|
+
console.error(`Status: ${response.status} ${response.statusText}`);
|
|
1905
|
+
console.error(`Endpoint: ${endpoint}`);
|
|
1906
|
+
console.error(`Response: ${errorDetail}`);
|
|
1907
|
+
if (response.status === 404) {
|
|
1908
|
+
console.error(
|
|
1909
|
+
`
|
|
1910
|
+
\u{1F4A1} Tip: A 404 error usually means the apiUrl is wrong.
|
|
1911
|
+
Current apiUrl: ${this.config.apiUrl}
|
|
1912
|
+
Make sure your backend is running and the URL is correct.`
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1915
|
+
await this.log("error", "Failed to create session", { status: response.status, errorDetail });
|
|
1828
1916
|
throw new Error(`Failed to create session: ${response.status}`);
|
|
1829
1917
|
}
|
|
1830
1918
|
const session = await response.json();
|
|
1831
1919
|
this.sessionToken = session.session_token;
|
|
1832
1920
|
this.isReady = true;
|
|
1833
1921
|
await this.log("info", "SDK initialized successfully", { hasSessionToken: !!this.sessionToken });
|
|
1834
|
-
|
|
1922
|
+
const recordingEnabled = this.config.recording?.enabled !== false;
|
|
1923
|
+
if (recordingEnabled) {
|
|
1835
1924
|
await this.initRecording();
|
|
1836
1925
|
}
|
|
1837
1926
|
if (this.config.proactive?.enabled) {
|
|
1838
1927
|
this.initProactive();
|
|
1839
1928
|
}
|
|
1840
|
-
|
|
1929
|
+
const userFlowsEnabled = this.config.userFlows?.enabled !== false;
|
|
1930
|
+
if (userFlowsEnabled) {
|
|
1841
1931
|
await this.initUserFlowTracking();
|
|
1842
1932
|
}
|
|
1843
1933
|
this.emit("ready", { sessionToken: this.sessionToken });
|
|
@@ -1845,7 +1935,27 @@ var ProduckSDK = class {
|
|
|
1845
1935
|
await this.sendInitialMessage();
|
|
1846
1936
|
}
|
|
1847
1937
|
} catch (error) {
|
|
1848
|
-
|
|
1938
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1939
|
+
const isNetworkError = errorMessage.includes("fetch") || errorMessage.includes("network") || errorMessage.includes("Failed to fetch") || errorMessage.includes("NetworkError");
|
|
1940
|
+
console.error(
|
|
1941
|
+
"%c\u274C Produck SDK initialization failed",
|
|
1942
|
+
"background: #ef4444; color: #fff; padding: 4px 8px; font-weight: bold;"
|
|
1943
|
+
);
|
|
1944
|
+
console.error(`Error: ${errorMessage}`);
|
|
1945
|
+
console.error(`API URL: ${this.config.apiUrl}`);
|
|
1946
|
+
if (isNetworkError) {
|
|
1947
|
+
console.error(
|
|
1948
|
+
`
|
|
1949
|
+
\u{1F4A1} This looks like a network error. Common causes:
|
|
1950
|
+
1. The apiUrl is incorrect or the backend is not running
|
|
1951
|
+
2. CORS is blocking the request
|
|
1952
|
+
3. The backend server is unreachable
|
|
1953
|
+
|
|
1954
|
+
Current apiUrl: ${this.config.apiUrl}
|
|
1955
|
+
Check the Network tab in DevTools for more details.`
|
|
1956
|
+
);
|
|
1957
|
+
}
|
|
1958
|
+
await this.log("error", "SDK initialization failed", { error: errorMessage });
|
|
1849
1959
|
this.emit("error", error);
|
|
1850
1960
|
throw error;
|
|
1851
1961
|
}
|
|
@@ -2529,6 +2639,15 @@ var ProduckSDK = class {
|
|
|
2529
2639
|
*/
|
|
2530
2640
|
async initUserFlowTracking() {
|
|
2531
2641
|
try {
|
|
2642
|
+
console.log(
|
|
2643
|
+
"%c\u{1F4CA} Initializing User Flow Tracking",
|
|
2644
|
+
"background: #8b5cf6; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
2645
|
+
{
|
|
2646
|
+
config: this.config.userFlows,
|
|
2647
|
+
apiUrl: this.config.apiUrl,
|
|
2648
|
+
sdkKey: this.config.sdkKey ? "present" : "missing"
|
|
2649
|
+
}
|
|
2650
|
+
);
|
|
2532
2651
|
this.userFlowTracker = new UserFlowTracker(this.config.userFlows);
|
|
2533
2652
|
this.userFlowTracker.initialize(
|
|
2534
2653
|
this.sessionToken,
|
|
@@ -2538,12 +2657,27 @@ var ProduckSDK = class {
|
|
|
2538
2657
|
const recordingSessionId = this.recorder?.getSessionId?.() || null;
|
|
2539
2658
|
const sessionId = await this.userFlowTracker.start(recordingSessionId);
|
|
2540
2659
|
if (sessionId) {
|
|
2660
|
+
console.log(
|
|
2661
|
+
"%c\u2705 User Flow Tracking Started",
|
|
2662
|
+
"background: #10b981; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
2663
|
+
{ flowSessionId: sessionId, linkedRecordingSession: recordingSessionId }
|
|
2664
|
+
);
|
|
2541
2665
|
await this.log("info", "User flow tracking started", {
|
|
2542
2666
|
flowSessionId: sessionId,
|
|
2543
2667
|
linkedRecordingSession: recordingSessionId
|
|
2544
2668
|
});
|
|
2669
|
+
} else {
|
|
2670
|
+
console.warn(
|
|
2671
|
+
"%c\u26A0\uFE0F User Flow Tracking: No session ID returned",
|
|
2672
|
+
"background: #f59e0b; color: #000; padding: 2px 6px; border-radius: 3px;"
|
|
2673
|
+
);
|
|
2545
2674
|
}
|
|
2546
2675
|
} catch (error) {
|
|
2676
|
+
console.error(
|
|
2677
|
+
"%c\u274C User Flow Tracking Failed",
|
|
2678
|
+
"background: #ef4444; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
2679
|
+
error
|
|
2680
|
+
);
|
|
2547
2681
|
await this.log("warn", "Failed to initialize user flow tracking", {
|
|
2548
2682
|
error: error instanceof Error ? error.message : String(error)
|
|
2549
2683
|
});
|