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