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