@screeb/sdk-browser 0.1.8 → 0.1.10

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,81 @@
1
+ export type ChannelType = "widget" | "ios" | "android";
2
+ export type Channel = {
3
+ id: string;
4
+ type: ChannelType;
5
+ };
6
+ export type User = {
7
+ anonymous_id: string;
8
+ userId?: string;
9
+ };
10
+ export type SurveyFormat = "conversationnal" | "cards";
11
+ export type SurveySize = 25 | 50 | 75 | 100 | 125 | 150;
12
+ export type SurveyPosition = "center-left" | "center-center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right";
13
+ export type Survey = {
14
+ id: string;
15
+ survey_position: SurveyPosition;
16
+ survey_format: SurveyFormat;
17
+ survey_size: 100;
18
+ };
19
+ export type ResponseStatus = "displayed" | "started" | "ended" | "closed" | "interrupted";
20
+ export type ResponseItemQuestion = {
21
+ id: string;
22
+ title: string;
23
+ type: "text" | "video";
24
+ url?: string;
25
+ };
26
+ export type ResponseItemAnswer = {
27
+ replied_at?: string;
28
+ fields?: {
29
+ type: "string" | "number" | "boolean" | "none" | "time" | "file";
30
+ text?: string;
31
+ number?: number;
32
+ boolean?: boolean;
33
+ time?: string;
34
+ }[];
35
+ };
36
+ export type ResponseItem = {
37
+ question: ResponseItemQuestion;
38
+ answer: ResponseItemAnswer;
39
+ };
40
+ export type HookCommonProperties = {
41
+ channel: Channel;
42
+ user: User;
43
+ survey: Survey;
44
+ };
45
+ export type HookOnReady = (data: {
46
+ channel: Channel;
47
+ user: User;
48
+ }) => void;
49
+ export type HookOnSurveyShowed = (data: HookCommonProperties & {
50
+ response: {
51
+ id: string;
52
+ items: ResponseItem[];
53
+ };
54
+ }) => void;
55
+ export type HookOnSurveyStarted = (data: HookCommonProperties & {
56
+ response: {
57
+ id: string;
58
+ };
59
+ }) => void;
60
+ export type HookOnQuestionReplied = (data: HookCommonProperties & {
61
+ response: {
62
+ id: string;
63
+ status: null;
64
+ question: ResponseItemQuestion;
65
+ answer: ResponseItemAnswer;
66
+ items: ResponseItem[];
67
+ };
68
+ }) => void;
69
+ export type HookOnSurveyCompleted = (data: HookCommonProperties & {
70
+ response: {
71
+ id: string;
72
+ items: ResponseItem[];
73
+ };
74
+ }) => void;
75
+ export type HookOnSurveyHidden = (data: HookCommonProperties & {
76
+ response: {
77
+ id: string;
78
+ items: ResponseItem[];
79
+ hide_reason: ResponseStatus;
80
+ };
81
+ }) => void;
@@ -1,38 +1,5 @@
1
- /** This is property types that are supported by Screeb. */
2
- export type PropertyType = number | boolean | string | Date | PropertyRecord;
3
- /** This is a property object that are supported by Screeb. */
4
- export type PropertyRecord = {
5
- [key: string]: PropertyType | PropertyType[];
6
- };
7
- /** This is the Screeb tag options object. */
8
- export type ScreebOptions = {
9
- /** If you're running Screeb tag in an iframe, please set the inner window here. */
10
- window?: Window;
11
- /** Please don't do this. */
12
- screebEndpoint?: string;
13
- };
14
- type ScreebFunction = (..._: unknown[]) => void | Promise<unknown>;
15
- /** This is the Screeb object publicly exposed in browser `window`. */
16
- export type ScreebObject = ScreebFunction & {
17
- q?: unknown[][];
18
- };
19
- /** This is the object returned by the function `identityGet()`. */
20
- export type ScreebIdentityGetReturn = {
21
- /** Anonymous id given to each user */
22
- anonymous_id: string;
23
- /** The authenticated id assigned to the user. */
24
- user_id: string;
25
- /** The current user session id */
26
- session_id: string;
27
- /** The current user session start time */
28
- session_start: string;
29
- /** The current user session end time */
30
- session_end: string;
31
- /** The current channel id with which the tag was initialized */
32
- channel_id: string;
33
- /** `true` if the tag us loaded, initialized and ready to rock */
34
- is_ready: boolean;
35
- };
1
+ import { Hooks, PropertyRecord, ScreebIdentityGetReturn, ScreebOptions } from "./types";
2
+ export * from "./types";
36
3
  /**
37
4
  * Appends Screeb tag into your dom.
38
5
  *
@@ -59,6 +26,8 @@ export declare const load: (options?: ScreebOptions) => Promise<undefined>;
59
26
  * - No more than 1000 attributes
60
27
  * - Supported types for values: string, number, boolean and Date
61
28
  * ```
29
+ * @param hooks Hooks to be called when SDK is ready or a survey is showed, started, completed, hidden
30
+ * or when a question is replied.
62
31
  *
63
32
  * @example
64
33
  * ```ts
@@ -73,11 +42,15 @@ export declare const load: (options?: ScreebOptions) => Promise<undefined>;
73
42
  * plan: '<user-plan>',
74
43
  * last_seen_at: new Date(),
75
44
  * authenticated: true
76
- * }
45
+ * },
46
+ * {
47
+ * version: "1.0.0",
48
+ * onReady: (payload) => console.log("Screeb SDK is ready!", payload),
49
+ * },
77
50
  * );
78
51
  * ```
79
52
  */
80
- export declare const init: (websiteId: string, userId?: string, userProperties?: PropertyRecord) => void | Promise<unknown>;
53
+ export declare const init: (websiteId: string, userId?: string, userProperties?: PropertyRecord, hooks?: Hooks) => void | Promise<unknown>;
81
54
  /**
82
55
  * Checks if Screeb tag has been loaded.
83
56
  *
@@ -328,11 +301,15 @@ export declare const surveyClose: () => void | Promise<unknown>;
328
301
  * {
329
302
  * color: "green",
330
303
  * article_id: 42
331
- * }
304
+ * },
305
+ * {
306
+ * version: "1.0.0",
307
+ * onSurveyShowed: (payload) => console.log("Survey showed", payload),
308
+ * },
332
309
  * );
333
310
  * ```
334
311
  */
335
- export declare const surveyStart: (surveyId: string, allowMultipleResponses?: boolean, hiddenFields?: PropertyRecord) => void | Promise<unknown>;
312
+ export declare const surveyStart: (surveyId: string, allowMultipleResponses?: boolean, hiddenFields?: PropertyRecord, hooks?: Hooks) => void | Promise<unknown>;
336
313
  /**
337
314
  * Forces a targeting check.
338
315
  *
@@ -369,4 +346,3 @@ export declare const targetingCheck: () => void | Promise<unknown>;
369
346
  * ```
370
347
  */
371
348
  export declare const targetingDebug: () => void | Promise<unknown>;
372
- export {};
package/dist/es/index.js CHANGED
@@ -36,14 +36,22 @@ var load = function (options) {
36
36
  scriptElement.addEventListener("error", reject);
37
37
  _window.$screeb =
38
38
  (_c = _window.$screeb) !== null && _c !== void 0 ? _c : function () {
39
- var _a;
40
39
  var args = [];
41
40
  for (var _i = 0; _i < arguments.length; _i++) {
42
41
  args[_i] = arguments[_i];
43
42
  }
44
- if (_window.$screeb) {
45
- (_window.$screeb.q = (_a = _window.$screeb.q) !== null && _a !== void 0 ? _a : []).push(args);
46
- }
43
+ return new Promise(function (a, b) {
44
+ var _a;
45
+ if (_window.$screeb) {
46
+ return (_window.$screeb.q = (_a = _window.$screeb.q) !== null && _a !== void 0 ? _a : []).push({
47
+ args: args,
48
+ ko: b,
49
+ ok: a,
50
+ v: 1,
51
+ });
52
+ }
53
+ return 0;
54
+ });
47
55
  };
48
56
  _window.document.head.appendChild(scriptElement);
49
57
  });
@@ -59,6 +67,8 @@ var load = function (options) {
59
67
  * - No more than 1000 attributes
60
68
  * - Supported types for values: string, number, boolean and Date
61
69
  * ```
70
+ * @param hooks Hooks to be called when SDK is ready or a survey is showed, started, completed, hidden
71
+ * or when a question is replied.
62
72
  *
63
73
  * @example
64
74
  * ```ts
@@ -73,14 +83,19 @@ var load = function (options) {
73
83
  * plan: '<user-plan>',
74
84
  * last_seen_at: new Date(),
75
85
  * authenticated: true
76
- * }
86
+ * },
87
+ * {
88
+ * version: "1.0.0",
89
+ * onReady: (payload) => console.log("Screeb SDK is ready!", payload),
90
+ * },
77
91
  * );
78
92
  * ```
79
93
  */
80
- var init = function (websiteId, userId, userProperties) {
94
+ var init = function (websiteId, userId, userProperties, hooks) {
81
95
  var identityObject;
82
96
  if (userId || userProperties) {
83
97
  identityObject = {
98
+ hooks: hooks,
84
99
  identity: {
85
100
  id: userId,
86
101
  properties: userProperties,
@@ -351,16 +366,21 @@ var surveyClose = function () { return callScreebCommand("survey.close"); };
351
366
  * {
352
367
  * color: "green",
353
368
  * article_id: 42
354
- * }
369
+ * },
370
+ * {
371
+ * version: "1.0.0",
372
+ * onSurveyShowed: (payload) => console.log("Survey showed", payload),
373
+ * },
355
374
  * );
356
375
  * ```
357
376
  */
358
- var surveyStart = function (surveyId, allowMultipleResponses, hiddenFields) {
377
+ var surveyStart = function (surveyId, allowMultipleResponses, hiddenFields, hooks) {
359
378
  if (allowMultipleResponses === void 0) { allowMultipleResponses = true; }
360
379
  if (hiddenFields === void 0) { hiddenFields = {}; }
361
380
  return callScreebCommand("survey.start", surveyId, {
362
381
  allow_multiple_responses: allowMultipleResponses,
363
382
  hidden_fields: hiddenFields,
383
+ hooks: hooks,
364
384
  });
365
385
  };
366
386
  /**
@@ -0,0 +1,58 @@
1
+ import { HookOnQuestionReplied, HookOnReady, HookOnSurveyCompleted, HookOnSurveyHidden, HookOnSurveyShowed, HookOnSurveyStarted } from "./hooks.types";
2
+ /** This is property types that are supported by Screeb. */
3
+ export type PropertyType = number | boolean | string | Date | PropertyRecord;
4
+ /** This is a property object that are supported by Screeb. */
5
+ export type PropertyRecord = {
6
+ [key: string]: PropertyType | PropertyType[];
7
+ };
8
+ /** This is the Screeb tag options object. */
9
+ export type ScreebOptions = {
10
+ /** If you're running Screeb tag in an iframe, please set the inner window here. */
11
+ window?: Window;
12
+ /** Please don't do this. */
13
+ screebEndpoint?: string;
14
+ };
15
+ export type ScreebFunction = (..._: unknown[]) => void | Promise<unknown>;
16
+ /** This is the Screeb object publicly exposed in browser `window`. */
17
+ export type ScreebObject = ScreebFunction & {
18
+ q?: {
19
+ args: unknown[];
20
+ ko: (reason?: unknown) => void;
21
+ ok: (value?: unknown) => void;
22
+ v: number;
23
+ }[];
24
+ };
25
+ /** This is the object returned by the function `identityGet()`. */
26
+ export type ScreebIdentityGetReturn = {
27
+ /** Anonymous id given to each user */
28
+ anonymous_id: string;
29
+ /** The authenticated id assigned to the user. */
30
+ user_id: string;
31
+ /** The current user session id */
32
+ session_id: string;
33
+ /** The current user session start time */
34
+ session_start: string;
35
+ /** The current user session end time */
36
+ session_end: string;
37
+ /** The current channel id with which the tag was initialized */
38
+ channel_id: string;
39
+ /** `true` if the tag is loaded, initialized and ready to rock */
40
+ is_ready: boolean;
41
+ };
42
+ /** This is the Screeb tag hooks object. */
43
+ export type Hooks = {
44
+ /** This defines the version of hooks and their data */
45
+ version: string;
46
+ /** This hook is triggered when Screeb SD is loaded, initialized and ready to rock */
47
+ onReady?: HookOnReady;
48
+ /** This hook is triggered when a survey is displayed on screen (also triggered when page is reloaded) */
49
+ onSurveyShowed?: HookOnSurveyShowed;
50
+ /** This hook is triggered when a survey is started */
51
+ onSurveyStarted?: HookOnSurveyStarted;
52
+ /** This hook is triggered when a question is answered */
53
+ onQuestionReplied?: HookOnQuestionReplied;
54
+ /** This hook is triggered when a survey is completed */
55
+ onSurveyCompleted?: HookOnSurveyCompleted;
56
+ /** This hook is triggered when a survey is hidden */
57
+ onSurveyHidden?: HookOnSurveyHidden;
58
+ };
package/docs/README.md CHANGED
@@ -6,8 +6,10 @@
6
6
 
7
7
  ### Type Aliases
8
8
 
9
+ - [Hooks](README.md#hooks)
9
10
  - [PropertyRecord](README.md#propertyrecord)
10
11
  - [PropertyType](README.md#propertytype)
12
+ - [ScreebFunction](README.md#screebfunction)
11
13
  - [ScreebIdentityGetReturn](README.md#screebidentitygetreturn)
12
14
  - [ScreebObject](README.md#screebobject)
13
15
  - [ScreebOptions](README.md#screeboptions)
@@ -33,6 +35,26 @@
33
35
 
34
36
  ## Type Aliases
35
37
 
38
+ ### Hooks
39
+
40
+ Ƭ **Hooks**: `Object`
41
+
42
+ This is the Screeb tag hooks object.
43
+
44
+ #### Type declaration
45
+
46
+ | Name | Type | Description |
47
+ | :------ | :------ | :------ |
48
+ | `onQuestionReplied?` | `HookOnQuestionReplied` | This hook is triggered when a question is answered |
49
+ | `onReady?` | `HookOnReady` | This hook is triggered when Screeb SD is loaded, initialized and ready to rock |
50
+ | `onSurveyCompleted?` | `HookOnSurveyCompleted` | This hook is triggered when a survey is completed |
51
+ | `onSurveyHidden?` | `HookOnSurveyHidden` | This hook is triggered when a survey is hidden |
52
+ | `onSurveyShowed?` | `HookOnSurveyShowed` | This hook is triggered when a survey is displayed on screen (also triggered when page is reloaded) |
53
+ | `onSurveyStarted?` | `HookOnSurveyStarted` | This hook is triggered when a survey is started |
54
+ | `version` | `string` | This defines the version of hooks and their data |
55
+
56
+ ___
57
+
36
58
  ### PropertyRecord
37
59
 
38
60
  Ƭ **PropertyRecord**: `Object`
@@ -53,6 +75,26 @@ This is property types that are supported by Screeb.
53
75
 
54
76
  ___
55
77
 
78
+ ### ScreebFunction
79
+
80
+ Ƭ **ScreebFunction**: (...`_`: `unknown`[]) => `void` \| `Promise`<`unknown`\>
81
+
82
+ #### Type declaration
83
+
84
+ ▸ (`..._`): `void` \| `Promise`<`unknown`\>
85
+
86
+ ##### Parameters
87
+
88
+ | Name | Type |
89
+ | :------ | :------ |
90
+ | `..._` | `unknown`[] |
91
+
92
+ ##### Returns
93
+
94
+ `void` \| `Promise`<`unknown`\>
95
+
96
+ ___
97
+
56
98
  ### ScreebIdentityGetReturn
57
99
 
58
100
  Ƭ **ScreebIdentityGetReturn**: `Object`
@@ -65,7 +107,7 @@ This is the object returned by the function `identityGet()`.
65
107
  | :------ | :------ | :------ |
66
108
  | `anonymous_id` | `string` | Anonymous id given to each user |
67
109
  | `channel_id` | `string` | The current channel id with which the tag was initialized |
68
- | `is_ready` | `boolean` | `true` if the tag us loaded, initialized and ready to rock |
110
+ | `is_ready` | `boolean` | `true` if the tag is loaded, initialized and ready to rock |
69
111
  | `session_end` | `string` | The current user session end time |
70
112
  | `session_id` | `string` | The current user session id |
71
113
  | `session_start` | `string` | The current user session start time |
@@ -75,7 +117,7 @@ ___
75
117
 
76
118
  ### ScreebObject
77
119
 
78
- Ƭ **ScreebObject**: `ScreebFunction` & { `q?`: `unknown`[][] }
120
+ Ƭ **ScreebObject**: [`ScreebFunction`](README.md#screebfunction) & { `q?`: { `args`: `unknown`[] ; `ko`: (`reason?`: `unknown`) => `void` ; `ok`: (`value?`: `unknown`) => `void` ; `v`: `number` }[] }
79
121
 
80
122
  This is the Screeb object publicly exposed in browser `window`.
81
123
 
@@ -102,6 +144,10 @@ This is the Screeb tag options object.
102
144
 
103
145
  Shutdowns current Screeb session.
104
146
 
147
+ #### Returns
148
+
149
+ `void` \| `Promise`<`unknown`\>
150
+
105
151
  **`Example`**
106
152
 
107
153
  ```ts
@@ -110,10 +156,6 @@ import * as Screeb from "@screeb/sdk-browser";
110
156
  Screeb.close();
111
157
  ```
112
158
 
113
- #### Returns
114
-
115
- `void` \| `Promise`<`unknown`\>
116
-
117
159
  ___
118
160
 
119
161
  ### debug
@@ -122,6 +164,10 @@ ___
122
164
 
123
165
  Prints the actual state information of Screeb tag.
124
166
 
167
+ #### Returns
168
+
169
+ `void` \| `Promise`<`unknown`\>
170
+
125
171
  **`Example`**
126
172
 
127
173
  ```ts
@@ -147,10 +193,6 @@ Screeb.debug();
147
193
  // **************************************************************
148
194
  ```
149
195
 
150
- #### Returns
151
-
152
- `void` \| `Promise`<`unknown`\>
153
-
154
196
  ___
155
197
 
156
198
  ### eventTrack
@@ -159,6 +201,17 @@ ___
159
201
 
160
202
  Tracks a user event.
161
203
 
204
+ #### Parameters
205
+
206
+ | Name | Type | Description |
207
+ | :------ | :------ | :------ |
208
+ | `eventName` | `string` | The event name. |
209
+ | `eventProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your event. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
210
+
211
+ #### Returns
212
+
213
+ `void` \| `Promise`<`unknown`\>
214
+
162
215
  **`Example`**
163
216
 
164
217
  ```ts
@@ -180,17 +233,6 @@ Screeb.eventTrack(
180
233
  );
181
234
  ```
182
235
 
183
- #### Parameters
184
-
185
- | Name | Type | Description |
186
- | :------ | :------ | :------ |
187
- | `eventName` | `string` | The event name. |
188
- | `eventProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your event. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
189
-
190
- #### Returns
191
-
192
- `void` \| `Promise`<`unknown`\>
193
-
194
236
  ___
195
237
 
196
238
  ### identity
@@ -200,6 +242,17 @@ ___
200
242
  Change the current user identity.
201
243
  Warning: Running surveys will be closed.
202
244
 
245
+ #### Parameters
246
+
247
+ | Name | Type | Description |
248
+ | :------ | :------ | :------ |
249
+ | `userId` | `string` | The unique identifier of your user. |
250
+ | `userProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
251
+
252
+ #### Returns
253
+
254
+ `void` \| `Promise`<`unknown`\>
255
+
203
256
  **`Example`**
204
257
 
205
258
  ```ts
@@ -217,17 +270,6 @@ Screeb.identity(
217
270
  );
218
271
  ```
219
272
 
220
- #### Parameters
221
-
222
- | Name | Type | Description |
223
- | :------ | :------ | :------ |
224
- | `userId` | `string` | The unique identifier of your user. |
225
- | `userProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
226
-
227
- #### Returns
228
-
229
- `void` \| `Promise`<`unknown`\>
230
-
231
273
  ___
232
274
 
233
275
  ### identityGet
@@ -236,6 +278,10 @@ ___
236
278
 
237
279
  Retrieves the current user identity.
238
280
 
281
+ #### Returns
282
+
283
+ `Promise`<[`ScreebIdentityGetReturn`](README.md#screebidentitygetreturn)\>
284
+
239
285
  **`Example`**
240
286
 
241
287
  ```ts
@@ -253,10 +299,6 @@ console.log(await Screeb.identityGet());
253
299
  // }
254
300
  ```
255
301
 
256
- #### Returns
257
-
258
- `Promise`<[`ScreebIdentityGetReturn`](README.md#screebidentitygetreturn)\>
259
-
260
302
  ___
261
303
 
262
304
  ### identityGroupAssign
@@ -265,6 +307,18 @@ ___
265
307
 
266
308
  Assigns the current user to a group.
267
309
 
310
+ #### Parameters
311
+
312
+ | Name | Type | Description |
313
+ | :------ | :------ | :------ |
314
+ | `groupName` | `string` | |
315
+ | `groupType?` | `string` | |
316
+ | `groupProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user group. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
317
+
318
+ #### Returns
319
+
320
+ `void` \| `Promise`<`unknown`\>
321
+
268
322
  **`Example`**
269
323
 
270
324
  ```ts
@@ -284,18 +338,6 @@ Screeb.identityGroupAssign(
284
338
  );
285
339
  ```
286
340
 
287
- #### Parameters
288
-
289
- | Name | Type | Description |
290
- | :------ | :------ | :------ |
291
- | `groupName` | `string` | |
292
- | `groupType?` | `string` | |
293
- | `groupProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user group. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
294
-
295
- #### Returns
296
-
297
- `void` \| `Promise`<`unknown`\>
298
-
299
341
  ___
300
342
 
301
343
  ### identityGroupUnassign
@@ -304,14 +346,6 @@ ___
304
346
 
305
347
  Unassigns the current user to a group.
306
348
 
307
- **`Example`**
308
-
309
- ```ts
310
- import * as Screeb from "@screeb/sdk-browser";
311
-
312
- Screeb.identityGroupUnassign('company', 'Apple');
313
- ```
314
-
315
349
  #### Parameters
316
350
 
317
351
  | Name | Type | Description |
@@ -323,6 +357,14 @@ Screeb.identityGroupUnassign('company', 'Apple');
323
357
 
324
358
  `void` \| `Promise`<`unknown`\>
325
359
 
360
+ **`Example`**
361
+
362
+ ```ts
363
+ import * as Screeb from "@screeb/sdk-browser";
364
+
365
+ Screeb.identityGroupUnassign('company', 'Apple');
366
+ ```
367
+
326
368
  ___
327
369
 
328
370
  ### identityProperties
@@ -331,6 +373,16 @@ ___
331
373
 
332
374
  Adds properties to the current user identity.
333
375
 
376
+ #### Parameters
377
+
378
+ | Name | Type | Description |
379
+ | :------ | :------ | :------ |
380
+ | `userProperties` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
381
+
382
+ #### Returns
383
+
384
+ `void` \| `Promise`<`unknown`\>
385
+
334
386
  **`Example`**
335
387
 
336
388
  ```ts
@@ -357,16 +409,6 @@ Screeb.identityProperties(
357
409
  );
358
410
  ```
359
411
 
360
- #### Parameters
361
-
362
- | Name | Type | Description |
363
- | :------ | :------ | :------ |
364
- | `userProperties` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
365
-
366
- #### Returns
367
-
368
- `void` \| `Promise`<`unknown`\>
369
-
370
412
  ___
371
413
 
372
414
  ### identityReset
@@ -376,6 +418,10 @@ ___
376
418
  Resets the current user identity.
377
419
  Warning: This command must be called only once, since it creates a new identity on Screeb side.
378
420
 
421
+ #### Returns
422
+
423
+ `void` \| `Promise`<`unknown`\>
424
+
379
425
  **`Example`**
380
426
 
381
427
  ```ts
@@ -384,18 +430,27 @@ import * as Screeb from "@screeb/sdk-browser";
384
430
  Screeb.identityReset();
385
431
  ```
386
432
 
387
- #### Returns
388
-
389
- `void` \| `Promise`<`unknown`\>
390
-
391
433
  ___
392
434
 
393
435
  ### init
394
436
 
395
- ▸ **init**(`websiteId`, `userId?`, `userProperties?`): `void` \| `Promise`<`unknown`\>
437
+ ▸ **init**(`websiteId`, `userId?`, `userProperties?`, `hooks?`): `void` \| `Promise`<`unknown`\>
396
438
 
397
439
  Initializes Screeb tag.
398
440
 
441
+ #### Parameters
442
+
443
+ | Name | Type | Description |
444
+ | :------ | :------ | :------ |
445
+ | `websiteId` | `string` | Your website/channel id. |
446
+ | `userId?` | `string` | The unique identifier of your user. |
447
+ | `userProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date ``` |
448
+ | `hooks?` | [`Hooks`](README.md#hooks) | Hooks to be called when SDK is ready or a survey is showed, started, completed, hidden or when a question is replied. |
449
+
450
+ #### Returns
451
+
452
+ `void` \| `Promise`<`unknown`\>
453
+
399
454
  **`Example`**
400
455
 
401
456
  ```ts
@@ -410,22 +465,14 @@ Screeb.init(
410
465
  plan: '<user-plan>',
411
466
  last_seen_at: new Date(),
412
467
  authenticated: true
413
- }
468
+ },
469
+ {
470
+ version: "1.0.0",
471
+ onReady: (payload) => console.log("Screeb SDK is ready!", payload),
472
+ },
414
473
  );
415
474
  ```
416
475
 
417
- #### Parameters
418
-
419
- | Name | Type | Description |
420
- | :------ | :------ | :------ |
421
- | `websiteId` | `string` | Your website/channel id. |
422
- | `userId?` | `string` | The unique identifier of your user. |
423
- | `userProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date ``` |
424
-
425
- #### Returns
426
-
427
- `void` \| `Promise`<`unknown`\>
428
-
429
476
  ___
430
477
 
431
478
  ### isLoaded
@@ -434,6 +481,10 @@ ___
434
481
 
435
482
  Checks if Screeb tag has been loaded.
436
483
 
484
+ #### Returns
485
+
486
+ `boolean`
487
+
437
488
  **`Example`**
438
489
 
439
490
  ```ts
@@ -444,10 +495,6 @@ Screeb.load();
444
495
  console.log(Screeb.isLoaded()); // true
445
496
  ```
446
497
 
447
- #### Returns
448
-
449
- `boolean`
450
-
451
498
  ___
452
499
 
453
500
  ### load
@@ -456,14 +503,6 @@ ___
456
503
 
457
504
  Appends Screeb tag into your dom.
458
505
 
459
- **`Example`**
460
-
461
- ```ts
462
- import * as Screeb from "@screeb/sdk-browser";
463
-
464
- Screeb.load();
465
- ```
466
-
467
506
  #### Parameters
468
507
 
469
508
  | Name | Type | Description |
@@ -474,6 +513,14 @@ Screeb.load();
474
513
 
475
514
  `Promise`<`undefined`\>
476
515
 
516
+ **`Example`**
517
+
518
+ ```ts
519
+ import * as Screeb from "@screeb/sdk-browser";
520
+
521
+ Screeb.load();
522
+ ```
523
+
477
524
  ___
478
525
 
479
526
  ### surveyClose
@@ -482,6 +529,10 @@ ___
482
529
 
483
530
  Interrupts a running survey.
484
531
 
532
+ #### Returns
533
+
534
+ `void` \| `Promise`<`unknown`\>
535
+
485
536
  **`Example`**
486
537
 
487
538
  ```ts
@@ -490,18 +541,27 @@ import * as Screeb from "@screeb/sdk-browser";
490
541
  Screeb.surveyClose();
491
542
  ```
492
543
 
493
- #### Returns
494
-
495
- `void` \| `Promise`<`unknown`\>
496
-
497
544
  ___
498
545
 
499
546
  ### surveyStart
500
547
 
501
- ▸ **surveyStart**(`surveyId`, `allowMultipleResponses?`, `hiddenFields?`): `void` \| `Promise`<`unknown`\>
548
+ ▸ **surveyStart**(`surveyId`, `allowMultipleResponses?`, `hiddenFields?`, `hooks?`): `void` \| `Promise`<`unknown`\>
502
549
 
503
550
  Starts a survey by its ID.
504
551
 
552
+ #### Parameters
553
+
554
+ | Name | Type | Default value |
555
+ | :------ | :------ | :------ |
556
+ | `surveyId` | `string` | `undefined` |
557
+ | `allowMultipleResponses` | `boolean` | `true` |
558
+ | `hiddenFields` | [`PropertyRecord`](README.md#propertyrecord) | `{}` |
559
+ | `hooks?` | [`Hooks`](README.md#hooks) | `undefined` |
560
+
561
+ #### Returns
562
+
563
+ `void` \| `Promise`<`unknown`\>
564
+
505
565
  **`Example`**
506
566
 
507
567
  ```ts
@@ -513,22 +573,14 @@ Screeb.surveyStart(
513
573
  {
514
574
  color: "green",
515
575
  article_id: 42
516
- }
576
+ },
577
+ {
578
+ version: "1.0.0",
579
+ onSurveyShowed: (payload) => console.log("Survey showed", payload),
580
+ },
517
581
  );
518
582
  ```
519
583
 
520
- #### Parameters
521
-
522
- | Name | Type | Default value |
523
- | :------ | :------ | :------ |
524
- | `surveyId` | `string` | `undefined` |
525
- | `allowMultipleResponses` | `boolean` | `true` |
526
- | `hiddenFields` | [`PropertyRecord`](README.md#propertyrecord) | `{}` |
527
-
528
- #### Returns
529
-
530
- `void` \| `Promise`<`unknown`\>
531
-
532
584
  ___
533
585
 
534
586
  ### targetingCheck
@@ -537,6 +589,10 @@ ___
537
589
 
538
590
  Forces a targeting check.
539
591
 
592
+ #### Returns
593
+
594
+ `void` \| `Promise`<`unknown`\>
595
+
540
596
  **`Example`**
541
597
 
542
598
  ```ts
@@ -545,10 +601,6 @@ import * as Screeb from "@screeb/sdk-browser";
545
601
  Screeb.targetingCheck();
546
602
  ```
547
603
 
548
- #### Returns
549
-
550
- `void` \| `Promise`<`unknown`\>
551
-
552
604
  ___
553
605
 
554
606
  ### targetingDebug
@@ -557,6 +609,10 @@ ___
557
609
 
558
610
  Prints the current state of the targeting engine.
559
611
 
612
+ #### Returns
613
+
614
+ `void` \| `Promise`<`unknown`\>
615
+
560
616
  **`Example`**
561
617
 
562
618
  ```ts
@@ -578,7 +634,3 @@ console.log(await Screeb.targetingDebug());
578
634
  // - Rule of type "User event count": false 🔴
579
635
  // - Rule of type "Capping per respondent display count": false 🔴
580
636
  ```
581
-
582
- #### Returns
583
-
584
- `void` \| `Promise`<`unknown`\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@screeb/sdk-browser",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Screeb's browser sdk.",
5
5
  "keywords": [
6
6
  "product discovery",
@@ -39,30 +39,30 @@
39
39
  "README.md"
40
40
  ],
41
41
  "scripts": {
42
- "build": "rollup -c ./node_modules/@screeb/typescript-config/src/rollup.config.js",
42
+ "build": "rollup -c ../../node_modules/@screeb/typescript-config/src/rollup.config.js",
43
43
  "build:doc": "typedoc src/index.ts",
44
44
  "clean": "rm -Rf dist",
45
45
  "lint": "eslint .",
46
46
  "test": "jest"
47
47
  },
48
48
  "devDependencies": {
49
- "@screeb/eslint-config": "^0.1.5",
50
- "@screeb/typescript-config": "^0.1.5",
51
- "@types/jest": "^29.5.1",
52
- "@types/node": "^18.16.3",
53
- "@typescript-eslint/eslint-plugin": "^5.59.6",
54
- "eslint": "^8.41.0",
55
- "eslint-plugin-import": "^2.27.5",
56
- "eslint-plugin-jest": "^27.2.1",
49
+ "@screeb/eslint-config": "^0.1.6",
50
+ "@screeb/typescript-config": "^0.1.6",
51
+ "@types/jest": "^29.5.5",
52
+ "@types/node": "^20.8.4",
53
+ "@typescript-eslint/eslint-plugin": "^6.7.5",
54
+ "eslint": "^8.51.0",
55
+ "eslint-plugin-import": "^2.28.1",
56
+ "eslint-plugin-jest": "^27.4.2",
57
57
  "eslint-plugin-jsx-a11y": "^6.7.1",
58
- "eslint-plugin-prettier": "^4.2.1",
59
- "jest": "^29.5.0",
60
- "jest-environment-jsdom": "^29.5.0",
61
- "prettier": "^2.8.8",
62
- "rollup": "^3.23.0",
63
- "ts-jest": "^29.1.0",
64
- "typedoc": "^0.24.7",
65
- "typedoc-plugin-markdown": "^3.15.3"
58
+ "eslint-plugin-prettier": "^5.0.1",
59
+ "jest": "^29.7.0",
60
+ "jest-environment-jsdom": "^29.7.0",
61
+ "prettier": "^3.0.3",
62
+ "rollup": "^4.0.2",
63
+ "ts-jest": "^29.1.1",
64
+ "typedoc": "^0.25.2",
65
+ "typedoc-plugin-markdown": "^3.16.0"
66
66
  },
67
67
  "publishConfig": {
68
68
  "access": "public"