@prodact.ai/sdk 0.0.10 → 0.0.11
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 +8 -7
- package/dist/cdn/sdk.global.js.map +1 -1
- package/dist/index.js +70 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +410 -73
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +403 -66
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1282,7 +1282,7 @@ var UserFlowTracker = class {
|
|
|
1282
1282
|
samplingRate: this.config.samplingRate,
|
|
1283
1283
|
currentState: this.state,
|
|
1284
1284
|
apiUrl: this.apiUrl,
|
|
1285
|
-
hasSessionToken: !!this.
|
|
1285
|
+
hasSessionToken: !!this.sdkSessionToken
|
|
1286
1286
|
});
|
|
1287
1287
|
if (!this.config.enabled) {
|
|
1288
1288
|
console.warn("[UserFlow] Tracking disabled by config");
|
|
@@ -1408,6 +1408,57 @@ var UserFlowTracker = class {
|
|
|
1408
1408
|
isTracking() {
|
|
1409
1409
|
return this.state === "tracking";
|
|
1410
1410
|
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Get recent events for context (excludes SDK UI interactions like chat widget)
|
|
1413
|
+
* @param limit - Maximum number of events to return (default: 10)
|
|
1414
|
+
* @param excludeSelectors - CSS selectors to exclude (default: produck SDK elements)
|
|
1415
|
+
*/
|
|
1416
|
+
getRecentEvents(limit = 10, excludeSelectors) {
|
|
1417
|
+
const defaultExcludeSelectors = [
|
|
1418
|
+
"[data-produck-chat]",
|
|
1419
|
+
".produck-chat",
|
|
1420
|
+
".produck-widget",
|
|
1421
|
+
"#produck-chat",
|
|
1422
|
+
"#produck-widget",
|
|
1423
|
+
'[class*="produck"]',
|
|
1424
|
+
'[id*="produck"]'
|
|
1425
|
+
];
|
|
1426
|
+
const selectorsToExclude = excludeSelectors || defaultExcludeSelectors;
|
|
1427
|
+
const filteredEvents = this.events.filter((event) => {
|
|
1428
|
+
if (event.eventType === "navigation") return true;
|
|
1429
|
+
if (event.element?.selector) {
|
|
1430
|
+
const selectorLower = event.element.selector.toLowerCase();
|
|
1431
|
+
const matchesExclude = selectorsToExclude.some((excludeSel) => {
|
|
1432
|
+
const excludeLower = excludeSel.toLowerCase();
|
|
1433
|
+
if (excludeLower.includes("produck")) {
|
|
1434
|
+
return selectorLower.includes("produck");
|
|
1435
|
+
}
|
|
1436
|
+
return selectorLower.includes(excludeLower.replace(/[\[\].*#]/g, ""));
|
|
1437
|
+
});
|
|
1438
|
+
if (matchesExclude) return false;
|
|
1439
|
+
}
|
|
1440
|
+
return true;
|
|
1441
|
+
});
|
|
1442
|
+
return filteredEvents.slice(-limit);
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Get recent events as a summary string for chat context
|
|
1446
|
+
*/
|
|
1447
|
+
getRecentEventsAsSummary(limit = 10) {
|
|
1448
|
+
const events = this.getRecentEvents(limit);
|
|
1449
|
+
if (events.length === 0) return "";
|
|
1450
|
+
return events.map((event) => {
|
|
1451
|
+
if (event.eventType === "navigation") {
|
|
1452
|
+
return `Navigated to: ${event.pageTitle || event.pagePath}`;
|
|
1453
|
+
} else if (event.eventType === "click" && event.element) {
|
|
1454
|
+
const elementDesc = event.element.text || event.element.tag || "element";
|
|
1455
|
+
return `Clicked: ${elementDesc}${event.pageTitle ? ` on ${event.pageTitle}` : ""}`;
|
|
1456
|
+
} else if (event.eventType === "form_submit") {
|
|
1457
|
+
return `Submitted form on: ${event.pageTitle || event.pagePath}`;
|
|
1458
|
+
}
|
|
1459
|
+
return `${event.eventType}: ${event.pageTitle || event.pagePath}`;
|
|
1460
|
+
}).join("\n");
|
|
1461
|
+
}
|
|
1411
1462
|
/**
|
|
1412
1463
|
* Add a custom event
|
|
1413
1464
|
*/
|
|
@@ -2053,12 +2104,16 @@ Check the Network tab in DevTools for more details.`
|
|
|
2053
2104
|
});
|
|
2054
2105
|
}
|
|
2055
2106
|
}
|
|
2107
|
+
const userContext = this.getRecentUserFlowSummary(10);
|
|
2056
2108
|
const sessionResponse = await fetch(
|
|
2057
2109
|
`${this.config.apiUrl}/chat/sessions/${this.sessionToken}/message`,
|
|
2058
2110
|
{
|
|
2059
2111
|
method: "POST",
|
|
2060
2112
|
headers: { "Content-Type": "application/json" },
|
|
2061
|
-
body: JSON.stringify({
|
|
2113
|
+
body: JSON.stringify({
|
|
2114
|
+
message,
|
|
2115
|
+
userContext: userContext || void 0
|
|
2116
|
+
})
|
|
2062
2117
|
}
|
|
2063
2118
|
);
|
|
2064
2119
|
if (!sessionResponse.ok) {
|
|
@@ -2749,6 +2804,19 @@ Check the Network tab in DevTools for more details.`
|
|
|
2749
2804
|
getUserFlowStats() {
|
|
2750
2805
|
return this.userFlowTracker?.getStats() ?? null;
|
|
2751
2806
|
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Get recent user flow events (excluding SDK UI interactions)
|
|
2809
|
+
* Useful for providing context to chat
|
|
2810
|
+
*/
|
|
2811
|
+
getRecentUserFlowEvents(limit = 10) {
|
|
2812
|
+
return this.userFlowTracker?.getRecentEvents(limit) ?? [];
|
|
2813
|
+
}
|
|
2814
|
+
/**
|
|
2815
|
+
* Get recent user flow events as a summary string for chat context
|
|
2816
|
+
*/
|
|
2817
|
+
getRecentUserFlowSummary(limit = 10) {
|
|
2818
|
+
return this.userFlowTracker?.getRecentEventsAsSummary(limit) ?? "";
|
|
2819
|
+
}
|
|
2752
2820
|
/**
|
|
2753
2821
|
* Check if user flow tracking is active
|
|
2754
2822
|
*/
|