@encatch/web-sdk 0.0.23 → 0.0.24
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-sdk/plugin/sdk/{core-wrapper-C-0jtOUK.js → core-wrapper-Ga-OMvC7.js} +3808 -3786
- package/dist-sdk/plugin/sdk/{module-CEWmgbr-.js → module-Dicww8nS.js} +1 -1
- package/dist-sdk/plugin/sdk/module.js +1 -1
- package/package.json +1 -1
- package/src/hooks/useFetchElligibleFeedbackConfiguration.ts +31 -7
- package/src/utils/duration-utils.ts +16 -1
|
@@ -319,7 +319,7 @@ async function Ee() {
|
|
|
319
319
|
if (!(te || typeof window > "u" || typeof document > "u")) {
|
|
320
320
|
te = !0;
|
|
321
321
|
try {
|
|
322
|
-
const { render: t } = await Promise.resolve().then(() => be), e = (await import("./core-wrapper-
|
|
322
|
+
const { render: t } = await Promise.resolve().then(() => be), e = (await import("./core-wrapper-Ga-OMvC7.js")).default;
|
|
323
323
|
if (typeof document > "u") return;
|
|
324
324
|
let n = document.getElementById("enisght-root");
|
|
325
325
|
!n && document.body && (n = document.createElement("div"), n.id = "enisght-root", document.body.appendChild(n)), n && t(/* @__PURE__ */ Se(e, {}), n);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@encatch/web-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "A powerful, lightweight JavaScript SDK for collecting user feedback and running surveys on web applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist-sdk/plugin/sdk/module.js",
|
|
@@ -24,15 +24,27 @@ const filterByFrequencyRules = (
|
|
|
24
24
|
|
|
25
25
|
const filtered = feedbacks.filter((fb) => {
|
|
26
26
|
const fbId = fb.feedbackConfigurationId;
|
|
27
|
+
const isManual = fb.triggerProperties?.isManual === true;
|
|
27
28
|
|
|
28
29
|
// Check frequency rules
|
|
29
30
|
const tracking = frequencyTracking[fbId];
|
|
31
|
+
|
|
30
32
|
if (!tracking) {
|
|
31
|
-
//
|
|
33
|
+
// No tracking data yet
|
|
34
|
+
if (isManual && fb.frequencyAndScheduling) {
|
|
35
|
+
// For manual feedbacks without tracking, check date range directly
|
|
36
|
+
const startDate = new Date(fb.frequencyAndScheduling.startDate).getTime();
|
|
37
|
+
const stopDate = new Date(fb.frequencyAndScheduling.stopDate).getTime();
|
|
38
|
+
return currentTime >= startDate && currentTime <= stopDate;
|
|
39
|
+
}
|
|
40
|
+
// Never interacted before, always eligible for non-manual
|
|
32
41
|
return true;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
|
-
|
|
44
|
+
// Pass isManual flag to eligibility check
|
|
45
|
+
// Manual feedbacks: Only check date range, bypass all other frequency rules
|
|
46
|
+
// Non-manual feedbacks: Apply all frequency rules
|
|
47
|
+
const eligible = isEligibleByFrequency(tracking, currentTime, isManual);
|
|
36
48
|
return eligible;
|
|
37
49
|
});
|
|
38
50
|
|
|
@@ -138,6 +150,7 @@ export const useFetchElligibleFeedbackConfiguration = ({
|
|
|
138
150
|
const [loading, setLoading] = useState(false);
|
|
139
151
|
const [error, setError] = useState<string | null>(null);
|
|
140
152
|
const [data, setData] = useState<any>(null);
|
|
153
|
+
const [allFeedbacks, setAllFeedbacks] = useState<FeedbackConfigurationItem[]>([]); // Store all feedbacks including manual
|
|
141
154
|
const [lastFetchParams, setLastFetchParams] =
|
|
142
155
|
useState<FetchConfigurationListRequest | null>(null);
|
|
143
156
|
const lastFetchParamsRef = useRef<FetchConfigurationListRequest | null>(null);
|
|
@@ -176,8 +189,15 @@ export const useFetchElligibleFeedbackConfiguration = ({
|
|
|
176
189
|
? []
|
|
177
190
|
: config?.feedbackConfiguration || [];
|
|
178
191
|
|
|
192
|
+
// Store ALL feedbacks (including manual) for lookup by openFeedbackById/openFeedbackByName
|
|
193
|
+
setAllFeedbacks(feedbackConfigurations);
|
|
194
|
+
|
|
195
|
+
// Include all feedbacks in pending list
|
|
196
|
+
// Manual feedbacks will respect frequency rules but bypass showOnce
|
|
197
|
+
const pendingConfigurations = feedbackConfigurations || [];
|
|
198
|
+
|
|
179
199
|
const storedConfig: StoredConfiguration = {
|
|
180
|
-
feedbackConfiguration:
|
|
200
|
+
feedbackConfiguration: pendingConfigurations,
|
|
181
201
|
expiry,
|
|
182
202
|
feedbackInterval: feedbackIntervalConfig,
|
|
183
203
|
masterProperties: config?.masterProperties,
|
|
@@ -190,11 +210,14 @@ export const useFetchElligibleFeedbackConfiguration = ({
|
|
|
190
210
|
JSON.stringify(storedConfig)
|
|
191
211
|
);
|
|
192
212
|
|
|
193
|
-
|
|
213
|
+
// Persist all configurations (including manual)
|
|
214
|
+
setPendingFeedbacks(pendingConfigurations);
|
|
194
215
|
|
|
195
|
-
// Initialize tracking for
|
|
196
|
-
|
|
197
|
-
|
|
216
|
+
// Initialize tracking only for non-manual feedbacks
|
|
217
|
+
// Manual feedbacks don't need tracking as they only check date range
|
|
218
|
+
pendingConfigurations.forEach((fb) => {
|
|
219
|
+
const isManual = fb.triggerProperties?.isManual === true;
|
|
220
|
+
if (fb.frequencyAndScheduling && !isManual) {
|
|
198
221
|
initializeOrUpdateTracking(
|
|
199
222
|
fb.feedbackConfigurationId,
|
|
200
223
|
fb.frequencyAndScheduling as any
|
|
@@ -321,6 +344,7 @@ export const useFetchElligibleFeedbackConfiguration = ({
|
|
|
321
344
|
|
|
322
345
|
return {
|
|
323
346
|
data,
|
|
347
|
+
allFeedbacks, // Export all feedbacks including manual ones
|
|
324
348
|
loading,
|
|
325
349
|
error,
|
|
326
350
|
fetchConfiguration,
|
|
@@ -41,10 +41,14 @@ export const convertDurationToMs = (
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Check if a feedback is eligible based on frequency rules
|
|
44
|
+
* @param tracking - The frequency tracking data
|
|
45
|
+
* @param currentTime - Current timestamp in milliseconds
|
|
46
|
+
* @param isManual - Whether this is a manual feedback (only checks date range, bypasses all other rules)
|
|
44
47
|
*/
|
|
45
48
|
export const isEligibleByFrequency = (
|
|
46
49
|
tracking: FeedbackFrequencyTracking,
|
|
47
|
-
currentTime: number = Date.now()
|
|
50
|
+
currentTime: number = Date.now(),
|
|
51
|
+
isManual: boolean = false
|
|
48
52
|
): boolean => {
|
|
49
53
|
const {
|
|
50
54
|
frequencyConfig,
|
|
@@ -53,6 +57,17 @@ export const isEligibleByFrequency = (
|
|
|
53
57
|
responseCount,
|
|
54
58
|
} = tracking;
|
|
55
59
|
|
|
60
|
+
// For manual feedbacks: Only check start/stop dates, bypass all other frequency rules
|
|
61
|
+
if (isManual) {
|
|
62
|
+
// Check if within date range
|
|
63
|
+
const startDate = new Date(frequencyConfig.startDate).getTime();
|
|
64
|
+
const stopDate = new Date(frequencyConfig.stopDate).getTime();
|
|
65
|
+
|
|
66
|
+
return currentTime >= startDate && currentTime <= stopDate;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// For non-manual feedbacks: Apply all frequency rules
|
|
70
|
+
|
|
56
71
|
// Check if response limit reached
|
|
57
72
|
const stopCount = parseInt(frequencyConfig.stopWhenResponsesCount, 10);
|
|
58
73
|
|