@screeb/sdk-react 0.1.5 → 0.1.7
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/cjs/context.d.ts +4 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +364 -0
- package/dist/cjs/logger.d.ts +9 -0
- package/dist/cjs/provider.d.ts +4 -0
- package/dist/cjs/types.d.ts +375 -0
- package/dist/cjs/useScreeb.d.ts +1 -0
- package/dist/cjs/utils.d.ts +7 -0
- package/package.json +4 -9
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var Screeb = require('@screeb/sdk-browser');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var Screeb__namespace = /*#__PURE__*/_interopNamespaceDefault(Screeb);
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
|
+
|
|
27
|
+
/******************************************************************************
|
|
28
|
+
Copyright (c) Microsoft Corporation.
|
|
29
|
+
|
|
30
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
31
|
+
purpose with or without fee is hereby granted.
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
34
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
35
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
36
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
37
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
38
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
39
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
40
|
+
***************************************************************************** */
|
|
41
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function __rest(s, e) {
|
|
45
|
+
var t = {};
|
|
46
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
47
|
+
t[p] = s[p];
|
|
48
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
49
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
50
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
51
|
+
t[p[i]] = s[p[i]];
|
|
52
|
+
}
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
57
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
58
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
59
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
60
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
61
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
62
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function __generator(thisArg, body) {
|
|
67
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
68
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
69
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
70
|
+
function step(op) {
|
|
71
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
72
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
73
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
74
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
75
|
+
switch (op[0]) {
|
|
76
|
+
case 0: case 1: t = op; break;
|
|
77
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
78
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
79
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
80
|
+
default:
|
|
81
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
82
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
83
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
84
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
85
|
+
if (t[2]) _.ops.pop();
|
|
86
|
+
_.trys.pop(); continue;
|
|
87
|
+
}
|
|
88
|
+
op = body.call(thisArg, _);
|
|
89
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
90
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
95
|
+
var e = new Error(message);
|
|
96
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
var ScreebContext = React__namespace.createContext(undefined);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Logs messages in the console with a corresponding urgency
|
|
103
|
+
*
|
|
104
|
+
* @param level the urgency of the message
|
|
105
|
+
* @param message the message to log in the console
|
|
106
|
+
*/
|
|
107
|
+
var log = function (level, message) {
|
|
108
|
+
var packageName = "[@screeb/react-sdk]";
|
|
109
|
+
switch (level) {
|
|
110
|
+
case "info":
|
|
111
|
+
// eslint-disable-next-line no-console
|
|
112
|
+
console.log("".concat(packageName, " ").concat(message));
|
|
113
|
+
break;
|
|
114
|
+
case "warn":
|
|
115
|
+
// eslint-disable-next-line no-console
|
|
116
|
+
console.warn("".concat(packageName, " ").concat(message));
|
|
117
|
+
break;
|
|
118
|
+
case "error":
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
120
|
+
console.error("".concat(packageName, " ").concat(message));
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
// eslint-disable-next-line no-console
|
|
124
|
+
console.log("".concat(packageName, " ").concat(message));
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
var isSSR = typeof window === "undefined";
|
|
129
|
+
|
|
130
|
+
var isInitialized = false;
|
|
131
|
+
var ScreebProvider = function (_a) {
|
|
132
|
+
var websiteId = _a.websiteId, userId = _a.userId, userProperties = _a.userProperties, hooks = _a.hooks, children = _a.children, _b = _a.shouldLoad, shouldLoad = _b === void 0 ? !isSSR : _b, _c = _a.autoInit, autoInit = _c === void 0 ? false : _c, options = _a.options, rest = __rest(_a, ["websiteId", "userId", "userProperties", "hooks", "children", "shouldLoad", "autoInit", "options"]);
|
|
133
|
+
var isLoaded = React__namespace.useRef(Screeb__namespace.isLoaded());
|
|
134
|
+
// Allow data-x attributes, see https://github.com/devrnt/react-use-screeb/issues/478
|
|
135
|
+
var invalidPropKeys = Object.keys(rest).filter(function (key) { return !key.startsWith("data-"); });
|
|
136
|
+
if (invalidPropKeys.length > 0) {
|
|
137
|
+
log("warn", [
|
|
138
|
+
"some invalid props were passed to ScreebProvider. ",
|
|
139
|
+
"Please check following props: ".concat(invalidPropKeys.join(", "), "."),
|
|
140
|
+
].join(""));
|
|
141
|
+
}
|
|
142
|
+
var ensureScreeb = React__namespace.useCallback(
|
|
143
|
+
// eslint-disable-next-line no-unused-vars
|
|
144
|
+
function (functionName, callback, onlyLoaded) {
|
|
145
|
+
if (onlyLoaded === void 0) { onlyLoaded = false; }
|
|
146
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
+
var message, message;
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
if (!Screeb__namespace.isLoaded() && !shouldLoad) {
|
|
150
|
+
message = "Screeb instance is not loaded because `shouldLoad` is set to `false` in `ScreebProvider`";
|
|
151
|
+
log("warn", message);
|
|
152
|
+
return [2 /*return*/, Promise.reject(message)];
|
|
153
|
+
}
|
|
154
|
+
if (!isInitialized && !onlyLoaded) {
|
|
155
|
+
message = [
|
|
156
|
+
"\"".concat(functionName, "\" was called but Screeb has not been initialized yet. "),
|
|
157
|
+
"Please call 'init' before calling '".concat(functionName, "' or "),
|
|
158
|
+
"set 'autoInit' to true in the ScreebProvider.",
|
|
159
|
+
].join("");
|
|
160
|
+
log("warn", message);
|
|
161
|
+
return [2 /*return*/, Promise.reject(message)];
|
|
162
|
+
}
|
|
163
|
+
return [2 /*return*/, Promise.resolve(callback())];
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}, [shouldLoad]);
|
|
167
|
+
var close = React__namespace.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
if (!isLoaded.current) return [3 /*break*/, 2];
|
|
172
|
+
return [4 /*yield*/, Screeb__namespace.close()];
|
|
173
|
+
case 1:
|
|
174
|
+
_a.sent();
|
|
175
|
+
isLoaded.current = false;
|
|
176
|
+
_a.label = 2;
|
|
177
|
+
case 2: return [2 /*return*/];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}); }, [isLoaded.current]);
|
|
181
|
+
var debug = React__namespace.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
182
|
+
switch (_a.label) {
|
|
183
|
+
case 0: return [4 /*yield*/, ensureScreeb("debug", function () { return Screeb__namespace.debug(); })];
|
|
184
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
185
|
+
}
|
|
186
|
+
}); }); }, []);
|
|
187
|
+
var eventTrack = React__namespace.useCallback(function (eventName, eventProperties) { return __awaiter(void 0, void 0, void 0, function () {
|
|
188
|
+
return __generator(this, function (_a) {
|
|
189
|
+
switch (_a.label) {
|
|
190
|
+
case 0: return [4 /*yield*/, ensureScreeb("eventTrack", function () {
|
|
191
|
+
return Screeb__namespace.eventTrack(eventName, eventProperties);
|
|
192
|
+
})];
|
|
193
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}); }, []);
|
|
197
|
+
var identity = React__namespace.useCallback(function (userId, userProperties) { return __awaiter(void 0, void 0, void 0, function () {
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0: return [4 /*yield*/, ensureScreeb("identity", function () {
|
|
201
|
+
return Screeb__namespace.identity(userId, userProperties);
|
|
202
|
+
})];
|
|
203
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}); }, []);
|
|
207
|
+
var identityGet = React__namespace.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0: return [4 /*yield*/, ensureScreeb("identityGet", function () { return Screeb__namespace.identityGet(); })];
|
|
210
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
211
|
+
}
|
|
212
|
+
}); }); }, []);
|
|
213
|
+
var identityGroupAssign = React__namespace.useCallback(function (groupName, groupType, groupProperties) { return __awaiter(void 0, void 0, void 0, function () {
|
|
214
|
+
return __generator(this, function (_a) {
|
|
215
|
+
switch (_a.label) {
|
|
216
|
+
case 0: return [4 /*yield*/, ensureScreeb("identityGroupAssign", function () {
|
|
217
|
+
return Screeb__namespace.identityGroupAssign(groupName, groupType, groupProperties);
|
|
218
|
+
})];
|
|
219
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}); }, []);
|
|
223
|
+
var identityGroupUnassign = React__namespace.useCallback(function (groupName, groupType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
224
|
+
return __generator(this, function (_a) {
|
|
225
|
+
switch (_a.label) {
|
|
226
|
+
case 0: return [4 /*yield*/, ensureScreeb("identityGroupUnassign", function () {
|
|
227
|
+
return Screeb__namespace.identityGroupUnassign(groupName, groupType);
|
|
228
|
+
})];
|
|
229
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}); }, []);
|
|
233
|
+
var identityProperties = React__namespace.useCallback(function (userProperties) { return __awaiter(void 0, void 0, void 0, function () {
|
|
234
|
+
return __generator(this, function (_a) {
|
|
235
|
+
switch (_a.label) {
|
|
236
|
+
case 0: return [4 /*yield*/, ensureScreeb("identityProperties", function () {
|
|
237
|
+
return Screeb__namespace.identityProperties(userProperties);
|
|
238
|
+
})];
|
|
239
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}); }, []);
|
|
243
|
+
var identityReset = React__namespace.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
244
|
+
switch (_a.label) {
|
|
245
|
+
case 0: return [4 /*yield*/, ensureScreeb("identityReset", function () { return Screeb__namespace.identityReset(); })];
|
|
246
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
247
|
+
}
|
|
248
|
+
}); }); }, []);
|
|
249
|
+
var init = React__namespace.useCallback(function (websiteId, userId, userProperties, hooks) { return __awaiter(void 0, void 0, void 0, function () {
|
|
250
|
+
return __generator(this, function (_a) {
|
|
251
|
+
switch (_a.label) {
|
|
252
|
+
case 0: return [4 /*yield*/, ensureScreeb("init", function () {
|
|
253
|
+
if (!isInitialized) {
|
|
254
|
+
Screeb__namespace.init(websiteId, userId, userProperties, hooks);
|
|
255
|
+
isInitialized = true;
|
|
256
|
+
}
|
|
257
|
+
}, true)];
|
|
258
|
+
case 1:
|
|
259
|
+
_a.sent();
|
|
260
|
+
return [2 /*return*/];
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}); }, [ensureScreeb, websiteId, shouldLoad]);
|
|
264
|
+
var load = React__namespace.useCallback(function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
265
|
+
return __generator(this, function (_a) {
|
|
266
|
+
switch (_a.label) {
|
|
267
|
+
case 0:
|
|
268
|
+
if (!!isLoaded.current) return [3 /*break*/, 3];
|
|
269
|
+
Screeb__namespace.load(options);
|
|
270
|
+
isLoaded.current = true;
|
|
271
|
+
if (!autoInit) return [3 /*break*/, 3];
|
|
272
|
+
if (!websiteId) return [3 /*break*/, 2];
|
|
273
|
+
return [4 /*yield*/, init(websiteId, userId, userProperties, hooks)];
|
|
274
|
+
case 1:
|
|
275
|
+
_a.sent();
|
|
276
|
+
return [3 /*break*/, 3];
|
|
277
|
+
case 2:
|
|
278
|
+
log("warn", "autoInit is set to true, but no websiteId have been provided.");
|
|
279
|
+
_a.label = 3;
|
|
280
|
+
case 3: return [2 /*return*/];
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}); }, [isLoaded.current, autoInit]);
|
|
284
|
+
var surveyClose = React__namespace.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
285
|
+
switch (_a.label) {
|
|
286
|
+
case 0: return [4 /*yield*/, ensureScreeb("surveyClose", function () { return Screeb__namespace.surveyClose(); })];
|
|
287
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
288
|
+
}
|
|
289
|
+
}); }); }, []);
|
|
290
|
+
var surveyStart = React__namespace.useCallback(function (surveyId, allowMultipleResponses, hiddenFields, hooks) { return __awaiter(void 0, void 0, void 0, function () {
|
|
291
|
+
return __generator(this, function (_a) {
|
|
292
|
+
switch (_a.label) {
|
|
293
|
+
case 0: return [4 /*yield*/, ensureScreeb("surveyStart", function () {
|
|
294
|
+
return Screeb__namespace.surveyStart(surveyId, allowMultipleResponses, hiddenFields, hooks);
|
|
295
|
+
})];
|
|
296
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}); }, []);
|
|
300
|
+
var targetingCheck = React__namespace.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
301
|
+
switch (_a.label) {
|
|
302
|
+
case 0: return [4 /*yield*/, ensureScreeb("targetingCheck", function () { return Screeb__namespace.targetingCheck(); })];
|
|
303
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
304
|
+
}
|
|
305
|
+
}); }); }, []);
|
|
306
|
+
var targetingDebug = React__namespace.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
307
|
+
switch (_a.label) {
|
|
308
|
+
case 0: return [4 /*yield*/, ensureScreeb("targetingDebug", function () { return Screeb__namespace.targetingDebug(); })];
|
|
309
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
310
|
+
}
|
|
311
|
+
}); }); }, []);
|
|
312
|
+
var providerValue = React__namespace.useMemo(function () { return ({
|
|
313
|
+
close: close,
|
|
314
|
+
debug: debug,
|
|
315
|
+
eventTrack: eventTrack,
|
|
316
|
+
identity: identity,
|
|
317
|
+
identityGet: identityGet,
|
|
318
|
+
identityGroupAssign: identityGroupAssign,
|
|
319
|
+
identityGroupUnassign: identityGroupUnassign,
|
|
320
|
+
identityProperties: identityProperties,
|
|
321
|
+
identityReset: identityReset,
|
|
322
|
+
init: init,
|
|
323
|
+
load: load,
|
|
324
|
+
surveyClose: surveyClose,
|
|
325
|
+
surveyStart: surveyStart,
|
|
326
|
+
targetingCheck: targetingCheck,
|
|
327
|
+
targetingDebug: targetingDebug,
|
|
328
|
+
}); }, [
|
|
329
|
+
close,
|
|
330
|
+
debug,
|
|
331
|
+
eventTrack,
|
|
332
|
+
identity,
|
|
333
|
+
identityGet,
|
|
334
|
+
identityGroupAssign,
|
|
335
|
+
identityGroupUnassign,
|
|
336
|
+
identityProperties,
|
|
337
|
+
identityReset,
|
|
338
|
+
init,
|
|
339
|
+
load,
|
|
340
|
+
surveyClose,
|
|
341
|
+
surveyStart,
|
|
342
|
+
targetingCheck,
|
|
343
|
+
targetingDebug,
|
|
344
|
+
]);
|
|
345
|
+
if (!isSSR && shouldLoad) {
|
|
346
|
+
load(options);
|
|
347
|
+
}
|
|
348
|
+
return (jsxRuntime.jsx(ScreebContext.Provider, { value: providerValue, children: children }));
|
|
349
|
+
};
|
|
350
|
+
var useScreebContext = function () {
|
|
351
|
+
var context = React__namespace.useContext(ScreebContext);
|
|
352
|
+
if (context === undefined) {
|
|
353
|
+
// eslint-disable-next-line no-console
|
|
354
|
+
console.warn("`useScreeb` must be used within `ScreebProvider`.");
|
|
355
|
+
}
|
|
356
|
+
return context;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
var useScreeb = function () {
|
|
360
|
+
return useScreebContext();
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
exports.ScreebProvider = ScreebProvider;
|
|
364
|
+
exports.useScreeb = useScreeb;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type LogLevel = "info" | "error" | "warn";
|
|
2
|
+
/**
|
|
3
|
+
* Logs messages in the console with a corresponding urgency
|
|
4
|
+
*
|
|
5
|
+
* @param level the urgency of the message
|
|
6
|
+
* @param message the message to log in the console
|
|
7
|
+
*/
|
|
8
|
+
export declare const log: (level: LogLevel, message: string) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { Hooks, PropertyRecord, ScreebIdentityGetReturn, ScreebOptions } from "@screeb/sdk-browser";
|
|
2
|
+
/** Properties of Screeb provider */
|
|
3
|
+
export type ScreebProps = {
|
|
4
|
+
/** Your website/channel id. */
|
|
5
|
+
websiteId: string;
|
|
6
|
+
/** The unique identifier of your user. */
|
|
7
|
+
userId?: string;
|
|
8
|
+
/** The properties of your user. */
|
|
9
|
+
userProperties?: PropertyRecord;
|
|
10
|
+
/** Hooks to define callback for various event */
|
|
11
|
+
hooks?: Hooks;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Shutdowns current Screeb session.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const { close } = useScreeb();
|
|
19
|
+
*
|
|
20
|
+
* close();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type CloseFunction = () => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Prints the actual state information of Screeb tag.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const { debug } = useScreeb();
|
|
30
|
+
*
|
|
31
|
+
* debug();
|
|
32
|
+
* // ******************* SCREEB SESSION DEBUG *********************
|
|
33
|
+
* // Screeb channel id: <UUID>
|
|
34
|
+
* // Screeb channel type: widget
|
|
35
|
+
* // Screeb respondent id: <UUID>
|
|
36
|
+
* // Screeb survey id: none
|
|
37
|
+
* // Screeb response id: none
|
|
38
|
+
* //
|
|
39
|
+
* // Screeb current session start: Thu May 04 2023 16:53:49 GMT+0200 (Central European Summer Time)
|
|
40
|
+
* // Screeb current session last activity: Thu May 04 2023 17:41:30 GMT+0200 (Central European Summer Time)
|
|
41
|
+
* //
|
|
42
|
+
* // Screeb targeting engine status: disabled
|
|
43
|
+
* // Screeb targeting engine: 3 surveys
|
|
44
|
+
* //
|
|
45
|
+
* // Detected platform: desktop
|
|
46
|
+
* // Detected locale: en-GB
|
|
47
|
+
* // Detected timezone: -120
|
|
48
|
+
* // **************************************************************
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export type DebugFunction = () => Promise<unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* Tracks a user event.
|
|
54
|
+
*
|
|
55
|
+
* @param eventName The event name.
|
|
56
|
+
* @param eventProperties The properties of your event.
|
|
57
|
+
* ```text Requirements:
|
|
58
|
+
* - Property names must be limited to 128 characters
|
|
59
|
+
* - No more than 1000 attributes
|
|
60
|
+
* - Supported types for values: string, number, boolean and Date.
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const { eventTrack } = useScreeb();
|
|
66
|
+
*
|
|
67
|
+
* eventTrack(
|
|
68
|
+
* "Product added to cart",
|
|
69
|
+
* {
|
|
70
|
+
* product_name: 'Red bike 2021',
|
|
71
|
+
* category: 'sport',
|
|
72
|
+
* color: 'red',
|
|
73
|
+
* price: 299,
|
|
74
|
+
* count: 1,
|
|
75
|
+
* reference: '2CF093TG1',
|
|
76
|
+
* delivery_method: 'UPS',
|
|
77
|
+
* user_logged: false,
|
|
78
|
+
* added_at: new Date(),
|
|
79
|
+
* }
|
|
80
|
+
* );
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export type EventTrackFunction = (eventName: string, eventProperties?: PropertyRecord) => Promise<unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* Change the current user identity.
|
|
86
|
+
* Warning: Running surveys will be closed.
|
|
87
|
+
*
|
|
88
|
+
* @param userId The unique identifier of your user.
|
|
89
|
+
* @param userProperties The properties of your user.
|
|
90
|
+
* ```text Requirements:
|
|
91
|
+
* - Property names must be limited to 128 characters
|
|
92
|
+
* - No more than 1000 attributes
|
|
93
|
+
* - Supported types for values: string, number, boolean and Date.
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const { identity } = useScreeb();
|
|
99
|
+
*
|
|
100
|
+
* identity(
|
|
101
|
+
* "<your-user-id>",
|
|
102
|
+
* {
|
|
103
|
+
* firstname: '<user-firstname>',
|
|
104
|
+
* lastname: '<user-lastname>',
|
|
105
|
+
* plan: '<user-plan>',
|
|
106
|
+
* last_seen_at: new Date(),
|
|
107
|
+
* authenticated: true
|
|
108
|
+
* }
|
|
109
|
+
* );
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export type IdentityFunction = (userId: string, userProperties?: PropertyRecord) => Promise<unknown>;
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves the current user identity.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const { identityGet } = useScreeb();
|
|
119
|
+
*
|
|
120
|
+
* console.log(await identityGet());
|
|
121
|
+
* // {
|
|
122
|
+
* // anonymous_id: "<UUID>",
|
|
123
|
+
* // user_id: "<UUID>",
|
|
124
|
+
* // session_id: "<UUID>",
|
|
125
|
+
* // session_start: "2023-05-04T16:30:15.882Z",
|
|
126
|
+
* // session_end: "2023-05-04T17:02:09.087Z",
|
|
127
|
+
* // channel_id: "<UUID>",
|
|
128
|
+
* // is_ready: true,
|
|
129
|
+
* // }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export type IdentityGetFunction = () => Promise<ScreebIdentityGetReturn>;
|
|
133
|
+
/**
|
|
134
|
+
* Assigns the current user to a group.
|
|
135
|
+
*
|
|
136
|
+
* @param groupName
|
|
137
|
+
* @param groupType
|
|
138
|
+
* @param groupProperties The properties of your user group.
|
|
139
|
+
* ```text Requirements:
|
|
140
|
+
* - Property names must be limited to 128 characters
|
|
141
|
+
* - No more than 1000 attributes
|
|
142
|
+
* - Supported types for values: string, number, boolean and Date.
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const { identityGroupAssign } = useScreeb();
|
|
148
|
+
*
|
|
149
|
+
* identityGroupAssign(
|
|
150
|
+
* 'company',
|
|
151
|
+
* 'Apple',
|
|
152
|
+
* {
|
|
153
|
+
* address_line_1: 'Apple Campus',
|
|
154
|
+
* address_line_2: '1 Infinite Loop',
|
|
155
|
+
* city: 'Cupertino',
|
|
156
|
+
* zipcode: 95014,
|
|
157
|
+
* state: 'California',
|
|
158
|
+
* country: 'United states',
|
|
159
|
+
* }
|
|
160
|
+
* );
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export type IdentityGroupAssignFunction = (groupName: string, groupType?: string, groupProperties?: PropertyRecord) => Promise<unknown>;
|
|
164
|
+
/**
|
|
165
|
+
* Unassigns the current user to a group.
|
|
166
|
+
*
|
|
167
|
+
* @param groupName The name of your user group.
|
|
168
|
+
* @param groupType The type of your user group.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const { identityGroupUnassign } = useScreeb();
|
|
173
|
+
*
|
|
174
|
+
* identityGroupUnassign('company', 'Apple');
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export type IdentityGroupUnassignFunction = (groupName: string, groupType?: string) => Promise<unknown>;
|
|
178
|
+
/**
|
|
179
|
+
* Adds properties to the current user identity.
|
|
180
|
+
*
|
|
181
|
+
* @param userProperties The properties of your user.
|
|
182
|
+
* ```text Requirements:
|
|
183
|
+
* - Property names must be limited to 128 characters
|
|
184
|
+
* - No more than 1000 attributes
|
|
185
|
+
* - Supported types for values: string, number, boolean and Date.
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const { identityProperties } = useScreeb();
|
|
191
|
+
*
|
|
192
|
+
* // Set user properties
|
|
193
|
+
* identityProperties(
|
|
194
|
+
* {
|
|
195
|
+
* firstname: '<user-firstname>',
|
|
196
|
+
* lastname: '<user-lastname>',
|
|
197
|
+
* plan: '<user-plan>',
|
|
198
|
+
* last_seen_at: new Date(),
|
|
199
|
+
* authenticated: true
|
|
200
|
+
* }
|
|
201
|
+
* );
|
|
202
|
+
*
|
|
203
|
+
* // Delete user property : set values to null
|
|
204
|
+
* identityProperties(
|
|
205
|
+
* {
|
|
206
|
+
* age: null,
|
|
207
|
+
* company: null,
|
|
208
|
+
* logged: true,
|
|
209
|
+
* }
|
|
210
|
+
* );
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export type IdentityPropertiesFunction = (userProperties: PropertyRecord) => Promise<unknown>;
|
|
214
|
+
/**
|
|
215
|
+
* Resets the current user identity.
|
|
216
|
+
* Warning: This command must be called only once, since it creates a new identity on Screeb side.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* const { identityReset } = useScreeb();
|
|
221
|
+
*
|
|
222
|
+
* identityReset();
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export type IdentityResetFunction = () => Promise<unknown>;
|
|
226
|
+
/**
|
|
227
|
+
* Initializes Screeb tag.
|
|
228
|
+
*
|
|
229
|
+
* @param websiteId Your website/channel id.
|
|
230
|
+
* @param userId The unique identifier of your user.
|
|
231
|
+
* @param userProperties The properties of your user.
|
|
232
|
+
* ```text Requirements:
|
|
233
|
+
* - Property names must be limited to 128 characters
|
|
234
|
+
* - No more than 1000 attributes
|
|
235
|
+
* - Supported types for values: string, number, boolean and Date
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* const { init } = useScreeb();
|
|
241
|
+
*
|
|
242
|
+
* init(
|
|
243
|
+
* "<your-website-id>",
|
|
244
|
+
* "<your-user-id>",
|
|
245
|
+
* {
|
|
246
|
+
* firstname: '<user-firstname>',
|
|
247
|
+
* lastname: '<user-lastname>',
|
|
248
|
+
* plan: '<user-plan>',
|
|
249
|
+
* last_seen_at: new Date(),
|
|
250
|
+
* authenticated: true
|
|
251
|
+
* }
|
|
252
|
+
* );
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
export type InitFunction = (websiteId: string, userId?: string, userProperties?: PropertyRecord) => Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Appends Screeb tag into your dom.
|
|
258
|
+
*
|
|
259
|
+
* @param options Screeb module options.
|
|
260
|
+
* @param options.window If you're running Screeb tag in an iframe, please set the inner window here.
|
|
261
|
+
* @param options.screebEndpoint Please don't do this.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* const { load } = useScreeb();
|
|
266
|
+
*
|
|
267
|
+
* load();
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
export type LoadFunction = (options?: ScreebOptions) => Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Interrupts a running survey.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* const { surveyClose } = useScreeb();
|
|
277
|
+
*
|
|
278
|
+
* surveyClose();
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
export type SurveyCloseFunction = () => Promise<unknown>;
|
|
282
|
+
/**
|
|
283
|
+
* Starts a survey by its ID.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* const { surveyStart } = useScreeb();
|
|
288
|
+
*
|
|
289
|
+
* surveyStart(
|
|
290
|
+
* '<UUID>',
|
|
291
|
+
* false,
|
|
292
|
+
* {
|
|
293
|
+
* color: "green",
|
|
294
|
+
* article_id: 42
|
|
295
|
+
* }
|
|
296
|
+
* );
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
export type SurveyStartFunction = (surveyId: string, allowMultipleResponses: boolean, hiddenFields: PropertyRecord) => Promise<unknown>;
|
|
300
|
+
/**
|
|
301
|
+
* Forces a targeting check.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* const { targetingCheck } = useScreeb();
|
|
306
|
+
*
|
|
307
|
+
* targetingCheck();
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
export type TargetingCheckFunction = () => Promise<unknown>;
|
|
311
|
+
/**
|
|
312
|
+
* Prints the current state of the targeting engine.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* const { targetingDebug } = useScreeb();
|
|
317
|
+
*
|
|
318
|
+
* console.log(await targetingDebug());
|
|
319
|
+
* // targeting ************ SCREEB TARGETING RULES DEBUG **************
|
|
320
|
+
* // Disabled surveys are not listed here.
|
|
321
|
+
* //
|
|
322
|
+
* // Screeb channel id: <UUID>
|
|
323
|
+
* // Screeb respondent id: <UUID>
|
|
324
|
+
* //
|
|
325
|
+
* // Survey <UUID>:
|
|
326
|
+
* // https://admin.screeb.app/org/last/survey/<UUID>/share
|
|
327
|
+
* //
|
|
328
|
+
* // - Rule of type "Device type (desktop/mobile/tablet)": true 🟢
|
|
329
|
+
* // - Rule of type "Multiple display": true 🟢
|
|
330
|
+
* // - Rule of type "Capping per time between survey display on current respondent": true 🟢
|
|
331
|
+
* // - Rule of type "User event count": false 🔴
|
|
332
|
+
* // - Rule of type "Capping per respondent display count": false 🔴
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
export type TargetingDebugFunction = () => Promise<unknown>;
|
|
336
|
+
/** Screeb context API */
|
|
337
|
+
export type ScreebContextValues = {
|
|
338
|
+
close: CloseFunction;
|
|
339
|
+
debug: DebugFunction;
|
|
340
|
+
eventTrack: EventTrackFunction;
|
|
341
|
+
identity: IdentityFunction;
|
|
342
|
+
identityGet: IdentityGetFunction;
|
|
343
|
+
identityGroupAssign: IdentityGroupAssignFunction;
|
|
344
|
+
identityGroupUnassign: IdentityGroupUnassignFunction;
|
|
345
|
+
identityProperties: IdentityPropertiesFunction;
|
|
346
|
+
identityReset: IdentityResetFunction;
|
|
347
|
+
init: InitFunction;
|
|
348
|
+
load: LoadFunction;
|
|
349
|
+
surveyClose: SurveyCloseFunction;
|
|
350
|
+
surveyStart: SurveyStartFunction;
|
|
351
|
+
targetingCheck: TargetingCheckFunction;
|
|
352
|
+
targetingDebug: TargetingDebugFunction;
|
|
353
|
+
};
|
|
354
|
+
/** Properties of Screeb provider */
|
|
355
|
+
export type ScreebProviderProps = {
|
|
356
|
+
/**
|
|
357
|
+
* Indicates if Screeb should be automatically loaded.
|
|
358
|
+
* This will ping to the Screeb servers.
|
|
359
|
+
*
|
|
360
|
+
* @remarks if `true`, 'load' does not need to be called manually. Can be used for multistaged environments
|
|
361
|
+
*/
|
|
362
|
+
shouldLoad?: boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Indicates if Screeb should be automatically initialized.
|
|
365
|
+
*
|
|
366
|
+
* @remarks if `true`, 'init' does not need to be called manually
|
|
367
|
+
* */
|
|
368
|
+
autoInit?: boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Screeb tag initialization options.
|
|
371
|
+
*
|
|
372
|
+
* @remarks this is used is really particular cases, handle with care.
|
|
373
|
+
* */
|
|
374
|
+
options?: ScreebOptions;
|
|
375
|
+
} & Partial<ScreebProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useScreeb: () => import("./types").ScreebContextValues;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@screeb/sdk-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Screeb's browser sdk, optimized for React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"product discovery",
|
|
@@ -25,13 +25,8 @@
|
|
|
25
25
|
"author": "Screeb's frontend team",
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"type": "module",
|
|
28
|
-
"exports": {
|
|
29
|
-
"./package.json": "./package.json",
|
|
30
|
-
".": {
|
|
31
|
-
"import": "./dist/es/index.js"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
28
|
"module": "dist/es/index.js",
|
|
29
|
+
"main": "dist/cjs/index.js",
|
|
35
30
|
"types": "dist/es/index.d.ts",
|
|
36
31
|
"files": [
|
|
37
32
|
"dist",
|
|
@@ -46,12 +41,12 @@
|
|
|
46
41
|
"test": "echo '@TODO'"
|
|
47
42
|
},
|
|
48
43
|
"dependencies": {
|
|
49
|
-
"@screeb/sdk-browser": "^0.1.
|
|
44
|
+
"@screeb/sdk-browser": "^0.1.13"
|
|
50
45
|
},
|
|
51
46
|
"devDependencies": {
|
|
52
47
|
"@screeb/eslint-config": "^0.1.6",
|
|
53
48
|
"@screeb/sdk-browser": "^0.1.6",
|
|
54
|
-
"@screeb/typescript-config": "^0.1.
|
|
49
|
+
"@screeb/typescript-config": "^0.1.8",
|
|
55
50
|
"@types/jest": "^29.5.5",
|
|
56
51
|
"@types/node": "^20.8.4",
|
|
57
52
|
"@types/react": "^18.2.28",
|