@screeb/sdk-react 0.1.6 → 0.1.8
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/es/context.d.ts +4 -0
- package/dist/es/index.d.ts +3 -0
- package/dist/es/logger.d.ts +9 -0
- package/dist/es/provider.d.ts +4 -0
- package/dist/es/types.d.ts +375 -0
- package/dist/es/useScreeb.d.ts +1 -0
- package/dist/es/utils.d.ts +7 -0
- package/package.json +6 -20
- /package/dist/{context.d.ts → cjs/context.d.ts} +0 -0
- /package/dist/{index.cjs.js → cjs/index.cjs} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{logger.d.ts → cjs/logger.d.ts} +0 -0
- /package/dist/{provider.d.ts → cjs/provider.d.ts} +0 -0
- /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/dist/{useScreeb.d.ts → cjs/useScreeb.d.ts} +0 -0
- /package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
- /package/dist/{index.es.js → es/index.mjs} +0 -0
|
@@ -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.8",
|
|
4
4
|
"description": "Screeb's browser sdk, optimized for React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"product discovery",
|
|
@@ -25,23 +25,9 @@
|
|
|
25
25
|
"author": "Screeb's frontend team",
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"type": "module",
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"import": {
|
|
32
|
-
"types": "./dist/index.d.ts",
|
|
33
|
-
"default": "./dist/index.es.js"
|
|
34
|
-
},
|
|
35
|
-
"require": {
|
|
36
|
-
"types": "./dist/index.d.ts",
|
|
37
|
-
"default": "./dist/index.cjs.js"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"module": "dist/index.es.js",
|
|
42
|
-
"main": "dist/index.cjs.js",
|
|
43
|
-
"jsnext:main": "dist/index.es.js",
|
|
44
|
-
"types": "dist/index.d.ts",
|
|
28
|
+
"module": "dist/es/index.mjs",
|
|
29
|
+
"main": "dist/cjs/index.cjs",
|
|
30
|
+
"types": "dist/es/index.d.ts",
|
|
45
31
|
"files": [
|
|
46
32
|
"dist",
|
|
47
33
|
"docs",
|
|
@@ -55,12 +41,12 @@
|
|
|
55
41
|
"test": "echo '@TODO'"
|
|
56
42
|
},
|
|
57
43
|
"dependencies": {
|
|
58
|
-
"@screeb/sdk-browser": "^0.1.
|
|
44
|
+
"@screeb/sdk-browser": "^0.1.14"
|
|
59
45
|
},
|
|
60
46
|
"devDependencies": {
|
|
61
47
|
"@screeb/eslint-config": "^0.1.6",
|
|
62
48
|
"@screeb/sdk-browser": "^0.1.6",
|
|
63
|
-
"@screeb/typescript-config": "^0.1.
|
|
49
|
+
"@screeb/typescript-config": "^0.1.9",
|
|
64
50
|
"@types/jest": "^29.5.5",
|
|
65
51
|
"@types/node": "^20.8.4",
|
|
66
52
|
"@types/react": "^18.2.28",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|