@screeb/sdk-browser 0.1.12 → 0.1.13

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