@screeb/sdk-browser 0.1.2

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/docs/README.md ADDED
@@ -0,0 +1,604 @@
1
+ @screeb/sdk-browser
2
+
3
+ # @screeb/sdk-browser
4
+
5
+ ## Table of contents
6
+
7
+ ### Type Aliases
8
+
9
+ - [PropertyRecord](README.md#propertyrecord)
10
+ - [PropertyType](README.md#propertytype)
11
+ - [ScreebObject](README.md#screebobject)
12
+ - [ScreebOptions](README.md#screeboptions)
13
+
14
+ ### Functions
15
+
16
+ - [close](README.md#close)
17
+ - [debug](README.md#debug)
18
+ - [eventTrack](README.md#eventtrack)
19
+ - [identity](README.md#identity)
20
+ - [identityGet](README.md#identityget)
21
+ - [identityGroupAssign](README.md#identitygroupassign)
22
+ - [identityGroupUnassign](README.md#identitygroupunassign)
23
+ - [identityProperties](README.md#identityproperties)
24
+ - [identityReset](README.md#identityreset)
25
+ - [init](README.md#init)
26
+ - [isLoaded](README.md#isloaded)
27
+ - [load](README.md#load)
28
+ - [surveyClose](README.md#surveyclose)
29
+ - [surveyStart](README.md#surveystart)
30
+ - [targetingCheck](README.md#targetingcheck)
31
+ - [targetingDebug](README.md#targetingdebug)
32
+ - [targetingStart](README.md#targetingstart)
33
+ - [targetingStop](README.md#targetingstop)
34
+
35
+ ## Type Aliases
36
+
37
+ ### PropertyRecord
38
+
39
+ Ƭ **PropertyRecord**: `Object`
40
+
41
+ This is a property object that are supported by Screeb.
42
+
43
+ #### Index signature
44
+
45
+ ▪ [key: `string`]: [`PropertyType`](README.md#propertytype) \| [`PropertyType`](README.md#propertytype)[]
46
+
47
+ ___
48
+
49
+ ### PropertyType
50
+
51
+ Ƭ **PropertyType**: `number` \| `boolean` \| `string` \| `Date` \| [`PropertyRecord`](README.md#propertyrecord)
52
+
53
+ This is property types that are supported by Screeb.
54
+
55
+ ___
56
+
57
+ ### ScreebObject
58
+
59
+ Ƭ **ScreebObject**: `ScreebFunction` & { `q?`: `unknown`[][] }
60
+
61
+ ___
62
+
63
+ ### ScreebOptions
64
+
65
+ Ƭ **ScreebOptions**: `Object`
66
+
67
+ This is the Screeb tag options object.
68
+
69
+ #### Type declaration
70
+
71
+ | Name | Type | Description |
72
+ | :------ | :------ | :------ |
73
+ | `screebEndpoint?` | `string` | Please don't do this. |
74
+ | `window?` | `Window` | If you're running Screeb tag in an iframe, please set the inner window here. |
75
+
76
+ ## Functions
77
+
78
+ ### close
79
+
80
+ ▸ **close**(): `void` \| `Promise`<`unknown`\>
81
+
82
+ Shutdowns current Screeb session.
83
+
84
+ **`Example`**
85
+
86
+ ```ts
87
+ import * as Screeb from "@screeb/sdk-browser";
88
+
89
+ Screeb.close();
90
+ ```
91
+
92
+ #### Returns
93
+
94
+ `void` \| `Promise`<`unknown`\>
95
+
96
+ ___
97
+
98
+ ### debug
99
+
100
+ ▸ **debug**(): `void` \| `Promise`<`unknown`\>
101
+
102
+ Prints the actual state information of Screeb tag.
103
+
104
+ **`Example`**
105
+
106
+ ```ts
107
+ import * as Screeb from "@screeb/sdk-browser";
108
+
109
+ Screeb.debug();
110
+ // ******************* SCREEB SESSION DEBUG *********************
111
+ // Screeb channel id: <UUID>
112
+ // Screeb channel type: widget
113
+ // Screeb respondent id: <UUID>
114
+ // Screeb survey id: none
115
+ // Screeb response id: none
116
+ //
117
+ // Screeb current session start: Thu May 04 2023 16:53:49 GMT+0200 (Central European Summer Time)
118
+ // Screeb current session last activity: Thu May 04 2023 17:41:30 GMT+0200 (Central European Summer Time)
119
+ //
120
+ // Screeb targeting engine status: disabled
121
+ // Screeb targeting engine: 3 surveys
122
+ //
123
+ // Detected platform: desktop
124
+ // Detected locale: en-GB
125
+ // Detected timezone: -120
126
+ // **************************************************************
127
+ ```
128
+
129
+ #### Returns
130
+
131
+ `void` \| `Promise`<`unknown`\>
132
+
133
+ ___
134
+
135
+ ### eventTrack
136
+
137
+ ▸ **eventTrack**(`eventName`, `eventProperties?`): `void` \| `Promise`<`unknown`\>
138
+
139
+ Tracks a visitor event.
140
+
141
+ **`Example`**
142
+
143
+ ```ts
144
+ import * as Screeb from "@screeb/sdk-browser";
145
+
146
+ Screeb.init(
147
+ "event.track",
148
+ "Product added to cart",
149
+ {
150
+ product_name: 'Red bike 2021',
151
+ category: 'sport',
152
+ color: 'red',
153
+ price: 299,
154
+ count: 1,
155
+ reference: '2CF093TG1',
156
+ delivery_method: 'UPS',
157
+ user_logged: false,
158
+ added_at: new Date(),
159
+ }
160
+ );
161
+ ```
162
+
163
+ #### Parameters
164
+
165
+ | Name | Type | Description |
166
+ | :------ | :------ | :------ |
167
+ | `eventName` | `string` | The event name. |
168
+ | `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. ``` |
169
+
170
+ #### Returns
171
+
172
+ `void` \| `Promise`<`unknown`\>
173
+
174
+ ___
175
+
176
+ ### identity
177
+
178
+ ▸ **identity**(`visitorId`, `visitorProperties?`): `void` \| `Promise`<`unknown`\>
179
+
180
+ Change the current visitor identity.
181
+ Warning: Running surveys will be closed.
182
+
183
+ **`Example`**
184
+
185
+ ```ts
186
+ import * as Screeb from "@screeb/sdk-browser";
187
+
188
+ Screeb.identity(
189
+ "<your-visitor-id>",
190
+ {
191
+ firstname: '<user-firstname>',
192
+ lastname: '<user-lastname>',
193
+ plan: '<user-plan>',
194
+ last_seen_at: new Date(),
195
+ authenticated: true
196
+ }
197
+ );
198
+ ```
199
+
200
+ #### Parameters
201
+
202
+ | Name | Type | Description |
203
+ | :------ | :------ | :------ |
204
+ | `visitorId` | `string` | The unique identifier of your visitor. |
205
+ | `visitorProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your visitor. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
206
+
207
+ #### Returns
208
+
209
+ `void` \| `Promise`<`unknown`\>
210
+
211
+ ___
212
+
213
+ ### identityGet
214
+
215
+ ▸ **identityGet**(): `Promise`<`ScreebIdentityGetReturn`\>
216
+
217
+ Retrieves the current visitor identity.
218
+
219
+ **`Example`**
220
+
221
+ ```ts
222
+ import * as Screeb from "@screeb/sdk-browser";
223
+
224
+ console.log(await Screeb.identityGet());
225
+ // {
226
+ // anonymous_id: "<UUID>",
227
+ // user_id: "<UUID>",
228
+ // session_id: "<UUID>",
229
+ // session_start: "2023-05-04T16:30:15.882Z",
230
+ // session_end: "2023-05-04T17:02:09.087Z",
231
+ // channel_id: "<UUID>",
232
+ // is_ready: true,
233
+ // }
234
+ ```
235
+
236
+ #### Returns
237
+
238
+ `Promise`<`ScreebIdentityGetReturn`\>
239
+
240
+ ___
241
+
242
+ ### identityGroupAssign
243
+
244
+ ▸ **identityGroupAssign**(`groupName`, `groupType?`, `groupProperties?`): `void` \| `Promise`<`unknown`\>
245
+
246
+ Assigns the current visitor to a group.
247
+
248
+ **`Example`**
249
+
250
+ ```ts
251
+ import * as Screeb from "@screeb/sdk-browser";
252
+
253
+ Screeb.identityGroupAssign(
254
+ 'company',
255
+ 'Apple',
256
+ {
257
+ address_line_1: 'Apple Campus',
258
+ address_line_2: '1 Infinite Loop',
259
+ city: 'Cupertino',
260
+ zipcode: 95014,
261
+ state: 'California',
262
+ country: 'United states',
263
+ }
264
+ );
265
+ ```
266
+
267
+ #### Parameters
268
+
269
+ | Name | Type | Description |
270
+ | :------ | :------ | :------ |
271
+ | `groupName` | `string` | |
272
+ | `groupType?` | `string` | |
273
+ | `groupProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your visitor 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. ``` |
274
+
275
+ #### Returns
276
+
277
+ `void` \| `Promise`<`unknown`\>
278
+
279
+ ___
280
+
281
+ ### identityGroupUnassign
282
+
283
+ ▸ **identityGroupUnassign**(`groupName`, `groupType?`): `void` \| `Promise`<`unknown`\>
284
+
285
+ Unassigns the current visitor to a group.
286
+
287
+ **`Example`**
288
+
289
+ ```ts
290
+ import * as Screeb from "@screeb/sdk-browser";
291
+
292
+ Screeb.identityGroupUnassign('company', 'Apple');
293
+ ```
294
+
295
+ #### Parameters
296
+
297
+ | Name | Type | Description |
298
+ | :------ | :------ | :------ |
299
+ | `groupName` | `string` | The name of your visitor group. |
300
+ | `groupType?` | `string` | The type of your visitor group. |
301
+
302
+ #### Returns
303
+
304
+ `void` \| `Promise`<`unknown`\>
305
+
306
+ ___
307
+
308
+ ### identityProperties
309
+
310
+ ▸ **identityProperties**(`visitorProperties`): `void` \| `Promise`<`unknown`\>
311
+
312
+ Adds properties to the current visitor identity.
313
+
314
+ **`Example`**
315
+
316
+ ```ts
317
+ import * as Screeb from "@screeb/sdk-browser";
318
+
319
+ // Set visitor properties
320
+ Screeb.identityProperties(
321
+ {
322
+ firstname: '<user-firstname>',
323
+ lastname: '<user-lastname>',
324
+ plan: '<user-plan>',
325
+ last_seen_at: new Date(),
326
+ authenticated: true
327
+ }
328
+ );
329
+
330
+ // Delete visitor property : set values to null
331
+ Screeb.identityProperties(
332
+ {
333
+ age: null,
334
+ company: null,
335
+ logged: true,
336
+ }
337
+ );
338
+ ```
339
+
340
+ #### Parameters
341
+
342
+ | Name | Type | Description |
343
+ | :------ | :------ | :------ |
344
+ | `visitorProperties` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your visitor. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date. ``` |
345
+
346
+ #### Returns
347
+
348
+ `void` \| `Promise`<`unknown`\>
349
+
350
+ ___
351
+
352
+ ### identityReset
353
+
354
+ ▸ **identityReset**(): `void` \| `Promise`<`unknown`\>
355
+
356
+ Resets the current visitor identity.
357
+ Warning: This command must be called only once, since it creates a new identity on Screeb side.
358
+
359
+ **`Example`**
360
+
361
+ ```ts
362
+ import * as Screeb from "@screeb/sdk-browser";
363
+
364
+ Screeb.identityReset();
365
+ ```
366
+
367
+ #### Returns
368
+
369
+ `void` \| `Promise`<`unknown`\>
370
+
371
+ ___
372
+
373
+ ### init
374
+
375
+ ▸ **init**(`websiteId`, `visitorId?`, `visitorProperties?`): `void` \| `Promise`<`unknown`\>
376
+
377
+ Initializes Screeb tag.
378
+
379
+ **`Example`**
380
+
381
+ ```ts
382
+ import * as Screeb from "@screeb/sdk-browser";
383
+
384
+ Screeb.init(
385
+ "<your-website-id>",
386
+ "<your-visitor-id>",
387
+ {
388
+ firstname: '<user-firstname>',
389
+ lastname: '<user-lastname>',
390
+ plan: '<user-plan>',
391
+ last_seen_at: new Date(),
392
+ authenticated: true
393
+ }
394
+ );
395
+ ```
396
+
397
+ #### Parameters
398
+
399
+ | Name | Type | Description |
400
+ | :------ | :------ | :------ |
401
+ | `websiteId` | `string` | Your website/channel id. |
402
+ | `visitorId?` | `string` | The unique identifier of your visitor. |
403
+ | `visitorProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your visitor. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date ``` |
404
+
405
+ #### Returns
406
+
407
+ `void` \| `Promise`<`unknown`\>
408
+
409
+ ___
410
+
411
+ ### isLoaded
412
+
413
+ ▸ **isLoaded**(): `boolean`
414
+
415
+ Checks if Screeb tag has been loaded.
416
+
417
+ **`Example`**
418
+
419
+ ```ts
420
+ import * as Screeb from "@screeb/sdk-browser";
421
+
422
+ console.log(Screeb.isLoaded()); // false
423
+ Screeb.load();
424
+ console.log(Screeb.isLoaded()); // true
425
+ ```
426
+
427
+ #### Returns
428
+
429
+ `boolean`
430
+
431
+ ___
432
+
433
+ ### load
434
+
435
+ ▸ **load**(`options?`): `Promise`<`undefined`\>
436
+
437
+ Appends Screeb tag into your dom.
438
+
439
+ **`Example`**
440
+
441
+ ```ts
442
+ import * as Screeb from "@screeb/sdk-browser";
443
+
444
+ Screeb.load();
445
+ ```
446
+
447
+ #### Parameters
448
+
449
+ | Name | Type | Description |
450
+ | :------ | :------ | :------ |
451
+ | `options` | [`ScreebOptions`](README.md#screeboptions) | Screeb module options. |
452
+
453
+ #### Returns
454
+
455
+ `Promise`<`undefined`\>
456
+
457
+ ___
458
+
459
+ ### surveyClose
460
+
461
+ ▸ **surveyClose**(): `void` \| `Promise`<`unknown`\>
462
+
463
+ Interrupts a running survey.
464
+
465
+ **`Example`**
466
+
467
+ ```ts
468
+ import * as Screeb from "@screeb/sdk-browser";
469
+
470
+ Screeb.surveyClose();
471
+ ```
472
+
473
+ #### Returns
474
+
475
+ `void` \| `Promise`<`unknown`\>
476
+
477
+ ___
478
+
479
+ ### surveyStart
480
+
481
+ ▸ **surveyStart**(`surveyId`, `allowMultipleResponses?`, `hiddenFields?`): `void` \| `Promise`<`unknown`\>
482
+
483
+ Starts a survey by its ID.
484
+
485
+ **`Example`**
486
+
487
+ ```ts
488
+ import * as Screeb from "@screeb/sdk-browser";
489
+
490
+ Screeb.surveyStart(
491
+ '<UUID>',
492
+ false,
493
+ {
494
+ color: "green",
495
+ article_id: 42
496
+ }
497
+ );
498
+ ```
499
+
500
+ #### Parameters
501
+
502
+ | Name | Type | Default value |
503
+ | :------ | :------ | :------ |
504
+ | `surveyId` | `string` | `undefined` |
505
+ | `allowMultipleResponses` | `boolean` | `false` |
506
+ | `hiddenFields` | [`PropertyRecord`](README.md#propertyrecord) | `{}` |
507
+
508
+ #### Returns
509
+
510
+ `void` \| `Promise`<`unknown`\>
511
+
512
+ ___
513
+
514
+ ### targetingCheck
515
+
516
+ ▸ **targetingCheck**(): `void` \| `Promise`<`unknown`\>
517
+
518
+ Forces a targeting check.
519
+
520
+ **`Example`**
521
+
522
+ ```ts
523
+ import * as Screeb from "@screeb/sdk-browser";
524
+
525
+ Screeb.targetingCheck();
526
+ ```
527
+
528
+ #### Returns
529
+
530
+ `void` \| `Promise`<`unknown`\>
531
+
532
+ ___
533
+
534
+ ### targetingDebug
535
+
536
+ ▸ **targetingDebug**(): `void` \| `Promise`<`unknown`\>
537
+
538
+ Prints the current state of the targeting engine.
539
+
540
+ **`Example`**
541
+
542
+ ```ts
543
+ import * as Screeb from "@screeb/sdk-browser";
544
+
545
+ Screeb.targetingDebug();
546
+ // targeting ************ SCREEB TARGETING RULES DEBUG **************
547
+ // Disabled surveys are not listed here.
548
+ //
549
+ // Screeb channel id: <UUID>
550
+ // Screeb respondent id: <UUID>
551
+ //
552
+ // Survey <UUID>:
553
+ // https://admin.screeb.app/org/last/survey/<UUID>/share
554
+ //
555
+ // - Rule of type "Device type (desktop/mobile/tablet)": true 🟢
556
+ // - Rule of type "Multiple display": true 🟢
557
+ // - Rule of type "Capping per time between survey display on current respondent": true 🟢
558
+ // - Rule of type "User event count": false 🔴
559
+ // - Rule of type "Capping per respondent display count": false 🔴
560
+ ```
561
+
562
+ #### Returns
563
+
564
+ `void` \| `Promise`<`unknown`\>
565
+
566
+ ___
567
+
568
+ ### targetingStart
569
+
570
+ ▸ **targetingStart**(): `void` \| `Promise`<`unknown`\>
571
+
572
+ Starts the targeting engine.
573
+
574
+ **`Example`**
575
+
576
+ ```ts
577
+ import * as Screeb from "@screeb/sdk-browser";
578
+
579
+ Screeb.targetingStart();
580
+ ```
581
+
582
+ #### Returns
583
+
584
+ `void` \| `Promise`<`unknown`\>
585
+
586
+ ___
587
+
588
+ ### targetingStop
589
+
590
+ ▸ **targetingStop**(): `void` \| `Promise`<`unknown`\>
591
+
592
+ Stops the targeting engine.
593
+
594
+ **`Example`**
595
+
596
+ ```ts
597
+ import * as Screeb from "@screeb/sdk-browser";
598
+
599
+ Screeb.targetingStop();
600
+ ```
601
+
602
+ #### Returns
603
+
604
+ `void` \| `Promise`<`unknown`\>
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@screeb/sdk-browser",
3
+ "version": "0.1.2",
4
+ "author": "Screeb's frontend team",
5
+ "description": "Screeb's browser sdk.",
6
+ "license": "ISC",
7
+ "scripts": {
8
+ "lint": "eslint .",
9
+ "build": "rollup -c ./node_modules/@screeb/typescript-config/src/rollup.config.js",
10
+ "build:doc": "typedoc src/index.ts",
11
+ "clean": "rm -Rf dist",
12
+ "test": "jest"
13
+ },
14
+ "sideEffects": false,
15
+ "type": "module",
16
+ "module": "dist/es/index.js",
17
+ "types": "dist/es/index.d.ts",
18
+ "files": [
19
+ "dist",
20
+ "docs",
21
+ "README.md"
22
+ ],
23
+ "exports": {
24
+ "./package.json": "./package.json",
25
+ ".": {
26
+ "import": "./dist/es/index.js"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "@screeb/eslint-config": "^0.1.1",
31
+ "@screeb/typescript-config": "^0.1.1",
32
+ "@types/jest": "^29.5.1",
33
+ "@types/node": "^18.16.3",
34
+ "@typescript-eslint/eslint-plugin": "^5.59.2",
35
+ "eslint": "^8.39.0",
36
+ "eslint-plugin-import": "^2.27.5",
37
+ "eslint-plugin-jest": "^27.2.1",
38
+ "eslint-plugin-jsx-a11y": "^6.7.1",
39
+ "eslint-plugin-prettier": "^4.2.1",
40
+ "jest": "^29.5.0",
41
+ "jest-environment-jsdom": "^29.5.0",
42
+ "prettier": "^2.8.8",
43
+ "rollup": "^3.21.4",
44
+ "ts-jest": "^29.1.0",
45
+ "typedoc": "^0.24.6",
46
+ "typedoc-plugin-markdown": "^3.15.3"
47
+ }
48
+ }