@screeb/sdk-react 0.1.0

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.
@@ -0,0 +1,373 @@
1
+ import { 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
+ };
11
+ /**
12
+ * Shutdowns current Screeb session.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const { close } = useScreeb();
17
+ *
18
+ * close();
19
+ * ```
20
+ */
21
+ export type CloseFunction = () => Promise<void>;
22
+ /**
23
+ * Prints the actual state information of Screeb tag.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const { debug } = useScreeb();
28
+ *
29
+ * debug();
30
+ * // ******************* SCREEB SESSION DEBUG *********************
31
+ * // Screeb channel id: <UUID>
32
+ * // Screeb channel type: widget
33
+ * // Screeb respondent id: <UUID>
34
+ * // Screeb survey id: none
35
+ * // Screeb response id: none
36
+ * //
37
+ * // Screeb current session start: Thu May 04 2023 16:53:49 GMT+0200 (Central European Summer Time)
38
+ * // Screeb current session last activity: Thu May 04 2023 17:41:30 GMT+0200 (Central European Summer Time)
39
+ * //
40
+ * // Screeb targeting engine status: disabled
41
+ * // Screeb targeting engine: 3 surveys
42
+ * //
43
+ * // Detected platform: desktop
44
+ * // Detected locale: en-GB
45
+ * // Detected timezone: -120
46
+ * // **************************************************************
47
+ * ```
48
+ */
49
+ export type DebugFunction = () => Promise<unknown>;
50
+ /**
51
+ * Tracks a user event.
52
+ *
53
+ * @param eventName The event name.
54
+ * @param eventProperties The properties of your event.
55
+ * ```text Requirements:
56
+ * - Property names must be limited to 128 characters
57
+ * - No more than 1000 attributes
58
+ * - Supported types for values: string, number, boolean and Date.
59
+ * ```
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const { eventTrack } = useScreeb();
64
+ *
65
+ * eventTrack(
66
+ * "Product added to cart",
67
+ * {
68
+ * product_name: 'Red bike 2021',
69
+ * category: 'sport',
70
+ * color: 'red',
71
+ * price: 299,
72
+ * count: 1,
73
+ * reference: '2CF093TG1',
74
+ * delivery_method: 'UPS',
75
+ * user_logged: false,
76
+ * added_at: new Date(),
77
+ * }
78
+ * );
79
+ * ```
80
+ */
81
+ export type EventTrackFunction = (eventName: string, eventProperties?: PropertyRecord) => Promise<unknown>;
82
+ /**
83
+ * Change the current user identity.
84
+ * Warning: Running surveys will be closed.
85
+ *
86
+ * @param userId The unique identifier of your user.
87
+ * @param userProperties The properties of your user.
88
+ * ```text Requirements:
89
+ * - Property names must be limited to 128 characters
90
+ * - No more than 1000 attributes
91
+ * - Supported types for values: string, number, boolean and Date.
92
+ * ```
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * const { identity } = useScreeb();
97
+ *
98
+ * identity(
99
+ * "<your-user-id>",
100
+ * {
101
+ * firstname: '<user-firstname>',
102
+ * lastname: '<user-lastname>',
103
+ * plan: '<user-plan>',
104
+ * last_seen_at: new Date(),
105
+ * authenticated: true
106
+ * }
107
+ * );
108
+ * ```
109
+ */
110
+ export type IdentityFunction = (userId: string, userProperties?: PropertyRecord) => Promise<unknown>;
111
+ /**
112
+ * Retrieves the current user identity.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * const { identityGet } = useScreeb();
117
+ *
118
+ * console.log(await identityGet());
119
+ * // {
120
+ * // anonymous_id: "<UUID>",
121
+ * // user_id: "<UUID>",
122
+ * // session_id: "<UUID>",
123
+ * // session_start: "2023-05-04T16:30:15.882Z",
124
+ * // session_end: "2023-05-04T17:02:09.087Z",
125
+ * // channel_id: "<UUID>",
126
+ * // is_ready: true,
127
+ * // }
128
+ * ```
129
+ */
130
+ export type IdentityGetFunction = () => Promise<ScreebIdentityGetReturn>;
131
+ /**
132
+ * Assigns the current user to a group.
133
+ *
134
+ * @param groupName
135
+ * @param groupType
136
+ * @param groupProperties The properties of your user group.
137
+ * ```text Requirements:
138
+ * - Property names must be limited to 128 characters
139
+ * - No more than 1000 attributes
140
+ * - Supported types for values: string, number, boolean and Date.
141
+ * ```
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const { identityGroupAssign } = useScreeb();
146
+ *
147
+ * identityGroupAssign(
148
+ * 'company',
149
+ * 'Apple',
150
+ * {
151
+ * address_line_1: 'Apple Campus',
152
+ * address_line_2: '1 Infinite Loop',
153
+ * city: 'Cupertino',
154
+ * zipcode: 95014,
155
+ * state: 'California',
156
+ * country: 'United states',
157
+ * }
158
+ * );
159
+ * ```
160
+ */
161
+ export type IdentityGroupAssignFunction = (groupName: string, groupType?: string, groupProperties?: PropertyRecord) => Promise<unknown>;
162
+ /**
163
+ * Unassigns the current user to a group.
164
+ *
165
+ * @param groupName The name of your user group.
166
+ * @param groupType The type of your user group.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * const { identityGroupUnassign } = useScreeb();
171
+ *
172
+ * identityGroupUnassign('company', 'Apple');
173
+ * ```
174
+ */
175
+ export type IdentityGroupUnassignFunction = (groupName: string, groupType?: string) => Promise<unknown>;
176
+ /**
177
+ * Adds properties to the current user identity.
178
+ *
179
+ * @param userProperties The properties of your user.
180
+ * ```text Requirements:
181
+ * - Property names must be limited to 128 characters
182
+ * - No more than 1000 attributes
183
+ * - Supported types for values: string, number, boolean and Date.
184
+ * ```
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * const { identityProperties } = useScreeb();
189
+ *
190
+ * // Set user properties
191
+ * identityProperties(
192
+ * {
193
+ * firstname: '<user-firstname>',
194
+ * lastname: '<user-lastname>',
195
+ * plan: '<user-plan>',
196
+ * last_seen_at: new Date(),
197
+ * authenticated: true
198
+ * }
199
+ * );
200
+ *
201
+ * // Delete user property : set values to null
202
+ * identityProperties(
203
+ * {
204
+ * age: null,
205
+ * company: null,
206
+ * logged: true,
207
+ * }
208
+ * );
209
+ * ```
210
+ */
211
+ export type IdentityPropertiesFunction = (userProperties: PropertyRecord) => Promise<unknown>;
212
+ /**
213
+ * Resets the current user identity.
214
+ * Warning: This command must be called only once, since it creates a new identity on Screeb side.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * const { identityReset } = useScreeb();
219
+ *
220
+ * identityReset();
221
+ * ```
222
+ */
223
+ export type IdentityResetFunction = () => Promise<unknown>;
224
+ /**
225
+ * Initializes Screeb tag.
226
+ *
227
+ * @param websiteId Your website/channel id.
228
+ * @param userId The unique identifier of your user.
229
+ * @param userProperties The properties of your user.
230
+ * ```text Requirements:
231
+ * - Property names must be limited to 128 characters
232
+ * - No more than 1000 attributes
233
+ * - Supported types for values: string, number, boolean and Date
234
+ * ```
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * const { init } = useScreeb();
239
+ *
240
+ * init(
241
+ * "<your-website-id>",
242
+ * "<your-user-id>",
243
+ * {
244
+ * firstname: '<user-firstname>',
245
+ * lastname: '<user-lastname>',
246
+ * plan: '<user-plan>',
247
+ * last_seen_at: new Date(),
248
+ * authenticated: true
249
+ * }
250
+ * );
251
+ * ```
252
+ */
253
+ export type InitFunction = (websiteId: string, userId?: string, userProperties?: PropertyRecord) => Promise<void>;
254
+ /**
255
+ * Appends Screeb tag into your dom.
256
+ *
257
+ * @param options Screeb module options.
258
+ * @param options.window If you're running Screeb tag in an iframe, please set the inner window here.
259
+ * @param options.screebEndpoint Please don't do this.
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * const { load } = useScreeb();
264
+ *
265
+ * load();
266
+ * ```
267
+ */
268
+ export type LoadFunction = (options?: ScreebOptions) => Promise<void>;
269
+ /**
270
+ * Interrupts a running survey.
271
+ *
272
+ * @example
273
+ * ```ts
274
+ * const { surveyClose } = useScreeb();
275
+ *
276
+ * surveyClose();
277
+ * ```
278
+ */
279
+ export type SurveyCloseFunction = () => Promise<unknown>;
280
+ /**
281
+ * Starts a survey by its ID.
282
+ *
283
+ * @example
284
+ * ```ts
285
+ * const { surveyStart } = useScreeb();
286
+ *
287
+ * surveyStart(
288
+ * '<UUID>',
289
+ * false,
290
+ * {
291
+ * color: "green",
292
+ * article_id: 42
293
+ * }
294
+ * );
295
+ * ```
296
+ */
297
+ export type SurveyStartFunction = (surveyId: string, allowMultipleResponses: boolean, hiddenFields: PropertyRecord) => Promise<unknown>;
298
+ /**
299
+ * Forces a targeting check.
300
+ *
301
+ * @example
302
+ * ```ts
303
+ * const { targetingCheck } = useScreeb();
304
+ *
305
+ * targetingCheck();
306
+ * ```
307
+ */
308
+ export type TargetingCheckFunction = () => Promise<unknown>;
309
+ /**
310
+ * Prints the current state of the targeting engine.
311
+ *
312
+ * @example
313
+ * ```ts
314
+ * const { targetingDebug } = useScreeb();
315
+ *
316
+ * console.log(await targetingDebug());
317
+ * // targeting ************ SCREEB TARGETING RULES DEBUG **************
318
+ * // Disabled surveys are not listed here.
319
+ * //
320
+ * // Screeb channel id: <UUID>
321
+ * // Screeb respondent id: <UUID>
322
+ * //
323
+ * // Survey <UUID>:
324
+ * // https://admin.screeb.app/org/last/survey/<UUID>/share
325
+ * //
326
+ * // - Rule of type "Device type (desktop/mobile/tablet)": true 🟢
327
+ * // - Rule of type "Multiple display": true 🟢
328
+ * // - Rule of type "Capping per time between survey display on current respondent": true 🟢
329
+ * // - Rule of type "User event count": false 🔴
330
+ * // - Rule of type "Capping per respondent display count": false 🔴
331
+ * ```
332
+ */
333
+ export type TargetingDebugFunction = () => Promise<unknown>;
334
+ /** Screeb context API */
335
+ export type ScreebContextValues = {
336
+ close: CloseFunction;
337
+ debug: DebugFunction;
338
+ eventTrack: EventTrackFunction;
339
+ identity: IdentityFunction;
340
+ identityGet: IdentityGetFunction;
341
+ identityGroupAssign: IdentityGroupAssignFunction;
342
+ identityGroupUnassign: IdentityGroupUnassignFunction;
343
+ identityProperties: IdentityPropertiesFunction;
344
+ identityReset: IdentityResetFunction;
345
+ init: InitFunction;
346
+ load: LoadFunction;
347
+ surveyClose: SurveyCloseFunction;
348
+ surveyStart: SurveyStartFunction;
349
+ targetingCheck: TargetingCheckFunction;
350
+ targetingDebug: TargetingDebugFunction;
351
+ };
352
+ /** Properties of Screeb provider */
353
+ export type ScreebProviderProps = {
354
+ /**
355
+ * Indicates if Screeb should be automatically loaded.
356
+ * This will ping to the Screeb servers.
357
+ *
358
+ * @remarks if `true`, 'load' does not need to be called manually. Can be used for multistaged environments
359
+ */
360
+ shouldLoad?: boolean;
361
+ /**
362
+ * Indicates if Screeb should be automatically initialized.
363
+ *
364
+ * @remarks if `true`, 'init' does not need to be called manually
365
+ * */
366
+ autoInit?: boolean;
367
+ /**
368
+ * Screeb tag initialization options.
369
+ *
370
+ * @remarks this is used is really particular cases, handle with care.
371
+ * */
372
+ options?: ScreebOptions;
373
+ } & Partial<ScreebProps>;
@@ -0,0 +1 @@
1
+ export declare const useScreeb: () => import("./types").ScreebContextValues;
@@ -0,0 +1,7 @@
1
+ export declare const isSSR: boolean;
2
+ /**
3
+ * Removes object entries where the value equals to `undefined`
4
+ *
5
+ * @param obj
6
+ */
7
+ export declare const removeUndefined: (obj: never) => never;
package/docs/.nojekyll ADDED
@@ -0,0 +1 @@
1
+ TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.