@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/react.mjs
CHANGED
|
@@ -59,7 +59,8 @@ var DEFAULT_CAPTURE_CONFIG = {
|
|
|
59
59
|
};
|
|
60
60
|
function mergeConfig(userConfig) {
|
|
61
61
|
return {
|
|
62
|
-
enabled: userConfig?.enabled ??
|
|
62
|
+
enabled: userConfig?.enabled ?? true,
|
|
63
|
+
// Enabled by default!
|
|
63
64
|
samplingRate: userConfig?.samplingRate ?? 1,
|
|
64
65
|
privacy: { ...DEFAULT_PRIVACY_CONFIG, ...userConfig?.privacy },
|
|
65
66
|
performance: { ...DEFAULT_PERFORMANCE_CONFIG, ...userConfig?.performance },
|
|
@@ -1071,7 +1072,8 @@ async function captureElementScreenshot(element, maxSize = 200) {
|
|
|
1071
1072
|
}
|
|
1072
1073
|
function mergeConfig2(config) {
|
|
1073
1074
|
const defaults = {
|
|
1074
|
-
enabled:
|
|
1075
|
+
enabled: true,
|
|
1076
|
+
// Enabled by default!
|
|
1075
1077
|
samplingRate: 1,
|
|
1076
1078
|
events: {
|
|
1077
1079
|
clicks: true,
|
|
@@ -1196,7 +1198,15 @@ var UserFlowTracker = class {
|
|
|
1196
1198
|
console.warn("[UserFlow] Cannot track outside browser environment");
|
|
1197
1199
|
return null;
|
|
1198
1200
|
}
|
|
1201
|
+
console.log("[UserFlow] start() called", {
|
|
1202
|
+
enabled: this.config.enabled,
|
|
1203
|
+
samplingRate: this.config.samplingRate,
|
|
1204
|
+
currentState: this.state,
|
|
1205
|
+
apiUrl: this.apiUrl,
|
|
1206
|
+
hasSessionToken: !!this.sessionToken
|
|
1207
|
+
});
|
|
1199
1208
|
if (!this.config.enabled) {
|
|
1209
|
+
console.warn("[UserFlow] Tracking disabled by config");
|
|
1200
1210
|
return null;
|
|
1201
1211
|
}
|
|
1202
1212
|
if (this.state === "tracking") {
|
|
@@ -1542,16 +1552,25 @@ var UserFlowTracker = class {
|
|
|
1542
1552
|
// Link to rrweb recording session if available
|
|
1543
1553
|
linkedRecordingSessionId: this.linkedRecordingSessionId
|
|
1544
1554
|
};
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
+
try {
|
|
1556
|
+
const response = await fetch(endpoint, {
|
|
1557
|
+
method: "POST",
|
|
1558
|
+
headers: {
|
|
1559
|
+
"Content-Type": "application/json",
|
|
1560
|
+
...this.sdkKey ? { "X-SDK-Key": this.sdkKey } : {}
|
|
1561
|
+
},
|
|
1562
|
+
body: JSON.stringify(body)
|
|
1563
|
+
});
|
|
1564
|
+
if (!response.ok) {
|
|
1565
|
+
console.error("[UserFlow] Failed to start session:", response.status, response.statusText);
|
|
1566
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1567
|
+
throw new Error(`Failed to start session: ${response.status}`);
|
|
1568
|
+
}
|
|
1569
|
+
console.log("[UserFlow] Session started successfully:", this.sessionId);
|
|
1570
|
+
} catch (error) {
|
|
1571
|
+
console.error("[UserFlow] Network error starting session:", error);
|
|
1572
|
+
console.error("[UserFlow] Attempted endpoint:", endpoint);
|
|
1573
|
+
throw error;
|
|
1555
1574
|
}
|
|
1556
1575
|
}
|
|
1557
1576
|
/**
|
|
@@ -1580,9 +1599,15 @@ var UserFlowTracker = class {
|
|
|
1580
1599
|
});
|
|
1581
1600
|
if (response.ok) {
|
|
1582
1601
|
this.batchesSent++;
|
|
1602
|
+
console.log(`[UserFlow] Event batch ${this.batchIndex - 1} sent (${eventsToSend.length} events)`);
|
|
1603
|
+
} else {
|
|
1604
|
+
console.error("[UserFlow] Failed to send event batch:", response.status, response.statusText);
|
|
1605
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1606
|
+
this.events = [...eventsToSend, ...this.events];
|
|
1583
1607
|
}
|
|
1584
1608
|
} catch (error) {
|
|
1585
|
-
console.error("[UserFlow]
|
|
1609
|
+
console.error("[UserFlow] Network error sending event batch:", error);
|
|
1610
|
+
console.error("[UserFlow] Endpoint:", endpoint);
|
|
1586
1611
|
this.events = [...eventsToSend, ...this.events];
|
|
1587
1612
|
}
|
|
1588
1613
|
}
|
|
@@ -1700,9 +1725,32 @@ var ProduckSDK = class {
|
|
|
1700
1725
|
/** User flow tracker instance (optional, isolated module) */
|
|
1701
1726
|
this.userFlowTracker = null;
|
|
1702
1727
|
let apiUrl = config.apiUrl;
|
|
1728
|
+
let apiUrlAutoDetected = false;
|
|
1703
1729
|
if (!apiUrl) {
|
|
1730
|
+
apiUrlAutoDetected = true;
|
|
1704
1731
|
if (typeof window !== "undefined") {
|
|
1705
|
-
|
|
1732
|
+
const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
|
|
1733
|
+
if (isLocalhost) {
|
|
1734
|
+
apiUrl = "http://localhost:4001/api/v1";
|
|
1735
|
+
} else {
|
|
1736
|
+
apiUrl = `${window.location.protocol}//${window.location.host}/api/v1`;
|
|
1737
|
+
console.warn(
|
|
1738
|
+
"%c\u26A0\uFE0F Produck SDK Warning: apiUrl not configured!",
|
|
1739
|
+
"background: #fbbf24; color: #000; padding: 4px 8px; font-weight: bold;"
|
|
1740
|
+
);
|
|
1741
|
+
console.warn(
|
|
1742
|
+
`The SDK is auto-detecting apiUrl as: ${apiUrl}
|
|
1743
|
+
This is likely WRONG for production. Your backend is probably at a different URL.
|
|
1744
|
+
|
|
1745
|
+
To fix this, provide apiUrl in your SDK config:
|
|
1746
|
+
|
|
1747
|
+
createProduck({
|
|
1748
|
+
sdkKey: 'your_sdk_key',
|
|
1749
|
+
apiUrl: 'https://your-backend.com/api/v1', // <-- Add this!
|
|
1750
|
+
})
|
|
1751
|
+
`
|
|
1752
|
+
);
|
|
1753
|
+
}
|
|
1706
1754
|
} else {
|
|
1707
1755
|
apiUrl = "http://localhost:4001/api/v1";
|
|
1708
1756
|
}
|
|
@@ -1711,11 +1759,30 @@ var ProduckSDK = class {
|
|
|
1711
1759
|
apiUrl,
|
|
1712
1760
|
...config
|
|
1713
1761
|
};
|
|
1762
|
+
if (typeof window !== "undefined") {
|
|
1763
|
+
console.log(
|
|
1764
|
+
"%c\u{1F527} Produck SDK Config",
|
|
1765
|
+
"background: #3b82f6; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
1766
|
+
{
|
|
1767
|
+
apiUrl: this.config.apiUrl,
|
|
1768
|
+
apiUrlAutoDetected,
|
|
1769
|
+
sdkKey: this.config.sdkKey ? `${this.config.sdkKey.substring(0, 10)}...` : "not set",
|
|
1770
|
+
guiderId: this.config.guiderId || "not set"
|
|
1771
|
+
}
|
|
1772
|
+
);
|
|
1773
|
+
}
|
|
1714
1774
|
}
|
|
1715
1775
|
/**
|
|
1716
1776
|
* Initialize the SDK and create a chat session
|
|
1717
1777
|
*/
|
|
1718
1778
|
async init() {
|
|
1779
|
+
if (typeof window !== "undefined") {
|
|
1780
|
+
console.log(
|
|
1781
|
+
"%c\u{1F680} Produck SDK Initializing...",
|
|
1782
|
+
"background: #10b981; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
1783
|
+
{ endpoint: this.config.apiUrl }
|
|
1784
|
+
);
|
|
1785
|
+
}
|
|
1719
1786
|
await this.log("info", "SDK Initializing", {
|
|
1720
1787
|
apiUrl: this.config.apiUrl,
|
|
1721
1788
|
hasSDKKey: !!this.config.sdkKey,
|
|
@@ -1742,20 +1809,43 @@ var ProduckSDK = class {
|
|
|
1742
1809
|
headers
|
|
1743
1810
|
});
|
|
1744
1811
|
if (!response.ok) {
|
|
1745
|
-
|
|
1812
|
+
let errorDetail = "";
|
|
1813
|
+
try {
|
|
1814
|
+
errorDetail = await response.text();
|
|
1815
|
+
} catch {
|
|
1816
|
+
errorDetail = "Could not read response body";
|
|
1817
|
+
}
|
|
1818
|
+
console.error(
|
|
1819
|
+
"%c\u274C Produck SDK: Failed to create session",
|
|
1820
|
+
"background: #ef4444; color: #fff; padding: 2px 6px; border-radius: 3px;"
|
|
1821
|
+
);
|
|
1822
|
+
console.error(`Status: ${response.status} ${response.statusText}`);
|
|
1823
|
+
console.error(`Endpoint: ${endpoint}`);
|
|
1824
|
+
console.error(`Response: ${errorDetail}`);
|
|
1825
|
+
if (response.status === 404) {
|
|
1826
|
+
console.error(
|
|
1827
|
+
`
|
|
1828
|
+
\u{1F4A1} Tip: A 404 error usually means the apiUrl is wrong.
|
|
1829
|
+
Current apiUrl: ${this.config.apiUrl}
|
|
1830
|
+
Make sure your backend is running and the URL is correct.`
|
|
1831
|
+
);
|
|
1832
|
+
}
|
|
1833
|
+
await this.log("error", "Failed to create session", { status: response.status, errorDetail });
|
|
1746
1834
|
throw new Error(`Failed to create session: ${response.status}`);
|
|
1747
1835
|
}
|
|
1748
1836
|
const session = await response.json();
|
|
1749
1837
|
this.sessionToken = session.session_token;
|
|
1750
1838
|
this.isReady = true;
|
|
1751
1839
|
await this.log("info", "SDK initialized successfully", { hasSessionToken: !!this.sessionToken });
|
|
1752
|
-
|
|
1840
|
+
const recordingEnabled = this.config.recording?.enabled !== false;
|
|
1841
|
+
if (recordingEnabled) {
|
|
1753
1842
|
await this.initRecording();
|
|
1754
1843
|
}
|
|
1755
1844
|
if (this.config.proactive?.enabled) {
|
|
1756
1845
|
this.initProactive();
|
|
1757
1846
|
}
|
|
1758
|
-
|
|
1847
|
+
const userFlowsEnabled = this.config.userFlows?.enabled !== false;
|
|
1848
|
+
if (userFlowsEnabled) {
|
|
1759
1849
|
await this.initUserFlowTracking();
|
|
1760
1850
|
}
|
|
1761
1851
|
this.emit("ready", { sessionToken: this.sessionToken });
|
|
@@ -1763,7 +1853,27 @@ var ProduckSDK = class {
|
|
|
1763
1853
|
await this.sendInitialMessage();
|
|
1764
1854
|
}
|
|
1765
1855
|
} catch (error) {
|
|
1766
|
-
|
|
1856
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1857
|
+
const isNetworkError = errorMessage.includes("fetch") || errorMessage.includes("network") || errorMessage.includes("Failed to fetch") || errorMessage.includes("NetworkError");
|
|
1858
|
+
console.error(
|
|
1859
|
+
"%c\u274C Produck SDK initialization failed",
|
|
1860
|
+
"background: #ef4444; color: #fff; padding: 4px 8px; font-weight: bold;"
|
|
1861
|
+
);
|
|
1862
|
+
console.error(`Error: ${errorMessage}`);
|
|
1863
|
+
console.error(`API URL: ${this.config.apiUrl}`);
|
|
1864
|
+
if (isNetworkError) {
|
|
1865
|
+
console.error(
|
|
1866
|
+
`
|
|
1867
|
+
\u{1F4A1} This looks like a network error. Common causes:
|
|
1868
|
+
1. The apiUrl is incorrect or the backend is not running
|
|
1869
|
+
2. CORS is blocking the request
|
|
1870
|
+
3. The backend server is unreachable
|
|
1871
|
+
|
|
1872
|
+
Current apiUrl: ${this.config.apiUrl}
|
|
1873
|
+
Check the Network tab in DevTools for more details.`
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
await this.log("error", "SDK initialization failed", { error: errorMessage });
|
|
1767
1877
|
this.emit("error", error);
|
|
1768
1878
|
throw error;
|
|
1769
1879
|
}
|
|
@@ -2447,6 +2557,15 @@ var ProduckSDK = class {
|
|
|
2447
2557
|
*/
|
|
2448
2558
|
async initUserFlowTracking() {
|
|
2449
2559
|
try {
|
|
2560
|
+
console.log(
|
|
2561
|
+
"%c\u{1F4CA} Initializing User Flow Tracking",
|
|
2562
|
+
"background: #8b5cf6; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
2563
|
+
{
|
|
2564
|
+
config: this.config.userFlows,
|
|
2565
|
+
apiUrl: this.config.apiUrl,
|
|
2566
|
+
sdkKey: this.config.sdkKey ? "present" : "missing"
|
|
2567
|
+
}
|
|
2568
|
+
);
|
|
2450
2569
|
this.userFlowTracker = new UserFlowTracker(this.config.userFlows);
|
|
2451
2570
|
this.userFlowTracker.initialize(
|
|
2452
2571
|
this.sessionToken,
|
|
@@ -2456,12 +2575,27 @@ var ProduckSDK = class {
|
|
|
2456
2575
|
const recordingSessionId = this.recorder?.getSessionId?.() || null;
|
|
2457
2576
|
const sessionId = await this.userFlowTracker.start(recordingSessionId);
|
|
2458
2577
|
if (sessionId) {
|
|
2578
|
+
console.log(
|
|
2579
|
+
"%c\u2705 User Flow Tracking Started",
|
|
2580
|
+
"background: #10b981; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
2581
|
+
{ flowSessionId: sessionId, linkedRecordingSession: recordingSessionId }
|
|
2582
|
+
);
|
|
2459
2583
|
await this.log("info", "User flow tracking started", {
|
|
2460
2584
|
flowSessionId: sessionId,
|
|
2461
2585
|
linkedRecordingSession: recordingSessionId
|
|
2462
2586
|
});
|
|
2587
|
+
} else {
|
|
2588
|
+
console.warn(
|
|
2589
|
+
"%c\u26A0\uFE0F User Flow Tracking: No session ID returned",
|
|
2590
|
+
"background: #f59e0b; color: #000; padding: 2px 6px; border-radius: 3px;"
|
|
2591
|
+
);
|
|
2463
2592
|
}
|
|
2464
2593
|
} catch (error) {
|
|
2594
|
+
console.error(
|
|
2595
|
+
"%c\u274C User Flow Tracking Failed",
|
|
2596
|
+
"background: #ef4444; color: #fff; padding: 2px 6px; border-radius: 3px;",
|
|
2597
|
+
error
|
|
2598
|
+
);
|
|
2465
2599
|
await this.log("warn", "Failed to initialize user flow tracking", {
|
|
2466
2600
|
error: error instanceof Error ? error.message : String(error)
|
|
2467
2601
|
});
|