@screeb/sdk-angular 0.1.1 → 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/dist/es/index.js DELETED
@@ -1,653 +0,0 @@
1
- import { Injectable, Inject, NgModule } from '@angular/core';
2
- import * as _Screeb from '@screeb/sdk-browser';
3
-
4
- /******************************************************************************
5
- Copyright (c) Microsoft Corporation.
6
-
7
- Permission to use, copy, modify, and/or distribute this software for any
8
- purpose with or without fee is hereby granted.
9
-
10
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
- PERFORMANCE OF THIS SOFTWARE.
17
- ***************************************************************************** */
18
- /* global Reflect, Promise */
19
-
20
-
21
- function __decorate(decorators, target, key, desc) {
22
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
23
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
24
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
25
- return c > 3 && r && Object.defineProperty(target, key, r), r;
26
- }
27
-
28
- function __param(paramIndex, decorator) {
29
- return function (target, key) { decorator(target, key, paramIndex); }
30
- }
31
-
32
- function __metadata(metadataKey, metadataValue) {
33
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
34
- }
35
-
36
- function __awaiter(thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- }
45
-
46
- function __generator(thisArg, body) {
47
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
48
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
49
- function verb(n) { return function (v) { return step([n, v]); }; }
50
- function step(op) {
51
- if (f) throw new TypeError("Generator is already executing.");
52
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
53
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
54
- if (y = 0, t) op = [op[0] & 2, t.value];
55
- switch (op[0]) {
56
- case 0: case 1: t = op; break;
57
- case 4: _.label++; return { value: op[1], done: false };
58
- case 5: _.label++; y = op[1]; op = [0]; continue;
59
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
60
- default:
61
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
62
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
63
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
64
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
65
- if (t[2]) _.ops.pop();
66
- _.trys.pop(); continue;
67
- }
68
- op = body.call(thisArg, _);
69
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
70
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
71
- }
72
- }
73
-
74
- /**
75
- * Logs messages in the console with a corresponding urgency
76
- *
77
- * @param level the urgency of the message
78
- * @param message the message to log in the console
79
- */
80
- var log = function (level, message) {
81
- var packageName = "[@screeb/angular-sdk]";
82
- switch (level) {
83
- case "info":
84
- // eslint-disable-next-line no-console
85
- console.log("".concat(packageName, " ").concat(message));
86
- break;
87
- case "warn":
88
- // eslint-disable-next-line no-console
89
- console.warn("".concat(packageName, " ").concat(message));
90
- break;
91
- case "error":
92
- // eslint-disable-next-line no-console
93
- console.error("".concat(packageName, " ").concat(message));
94
- break;
95
- default:
96
- // eslint-disable-next-line no-console
97
- console.log("".concat(packageName, " ").concat(message));
98
- }
99
- };
100
-
101
- /** Configuration of Screeb module */
102
- var ScreebConfig = /** @class */ (function () {
103
- function ScreebConfig() {
104
- }
105
- ScreebConfig = __decorate([
106
- Injectable({ providedIn: "root" })
107
- ], ScreebConfig);
108
- return ScreebConfig;
109
- }());
110
-
111
- var Screeb = /** @class */ (function () {
112
- // eslint-disable-next-line no-unused-vars
113
- function Screeb(config) {
114
- this.config = config;
115
- this.isInitialized = false;
116
- }
117
- Screeb.prototype.ensureScreeb = function (functionName, onlyLoaded) {
118
- if (onlyLoaded === void 0) { onlyLoaded = false; }
119
- return __awaiter(this, void 0, void 0, function () {
120
- var message, message;
121
- return __generator(this, function (_a) {
122
- if (!_Screeb.isLoaded() && !this.config.shouldLoad) {
123
- message = "Screeb instance is not loaded because `shouldLoad` is set to `false` in `ScreebModule` configuration.";
124
- log("warn", message);
125
- return [2 /*return*/, Promise.reject(message)];
126
- }
127
- if (!this.isInitialized && !onlyLoaded) {
128
- message = [
129
- "\"".concat(functionName, "\" was called but Screeb has not been initialized yet. "),
130
- "Please call 'init' before calling '".concat(functionName, "' or "),
131
- "set 'autoInit' to true in the `ScreebModule` configuration.",
132
- ].join("");
133
- log("warn", message);
134
- return [2 /*return*/, Promise.reject(message)];
135
- }
136
- return [2 /*return*/, Promise.resolve()];
137
- });
138
- });
139
- };
140
- /**
141
- * Shutdowns current Screeb session.
142
- *
143
- * @example
144
- * ```ts
145
- * this.screeb.close();
146
- * ```
147
- */
148
- Screeb.prototype.close = function () {
149
- return __awaiter(this, void 0, void 0, function () {
150
- return __generator(this, function (_a) {
151
- switch (_a.label) {
152
- case 0: return [4 /*yield*/, this.ensureScreeb("close")];
153
- case 1:
154
- _a.sent();
155
- return [2 /*return*/, _Screeb.close()];
156
- }
157
- });
158
- });
159
- };
160
- /**
161
- * Prints the actual state information of Screeb tag.
162
- *
163
- * @example
164
- * ```ts
165
- * this.screeb.debug();
166
- * // ******************* SCREEB SESSION DEBUG *********************
167
- * // Screeb channel id: <UUID>
168
- * // Screeb channel type: widget
169
- * // Screeb respondent id: <UUID>
170
- * // Screeb survey id: none
171
- * // Screeb response id: none
172
- * //
173
- * // Screeb current session start: Thu May 04 2023 16:53:49 GMT+0200 (Central European Summer Time)
174
- * // Screeb current session last activity: Thu May 04 2023 17:41:30 GMT+0200 (Central European Summer Time)
175
- * //
176
- * // Screeb targeting engine status: disabled
177
- * // Screeb targeting engine: 3 surveys
178
- * //
179
- * // Detected platform: desktop
180
- * // Detected locale: en-GB
181
- * // Detected timezone: -120
182
- * // **************************************************************
183
- * ```
184
- */
185
- Screeb.prototype.debug = function () {
186
- return __awaiter(this, void 0, void 0, function () {
187
- return __generator(this, function (_a) {
188
- switch (_a.label) {
189
- case 0: return [4 /*yield*/, this.ensureScreeb("debug")];
190
- case 1:
191
- _a.sent();
192
- return [2 /*return*/, _Screeb.debug()];
193
- }
194
- });
195
- });
196
- };
197
- /**
198
- * Tracks a user event.
199
- *
200
- * @param eventName The event name.
201
- * @param eventProperties The properties of your event.
202
- * ```text Requirements:
203
- * - Property names must be limited to 128 characters
204
- * - No more than 1000 attributes
205
- * - Supported types for values: string, number, boolean and Date.
206
- * ```
207
- *
208
- * @example
209
- * ```ts
210
- * this.screeb.eventTrack(
211
- * "Product added to cart",
212
- * {
213
- * product_name: 'Red bike 2021',
214
- * category: 'sport',
215
- * color: 'red',
216
- * price: 299,
217
- * count: 1,
218
- * reference: '2CF093TG1',
219
- * delivery_method: 'UPS',
220
- * user_logged: false,
221
- * added_at: new Date(),
222
- * }
223
- * );
224
- * ```
225
- */
226
- Screeb.prototype.eventTrack = function (eventName, eventProperties) {
227
- return __awaiter(this, void 0, void 0, function () {
228
- return __generator(this, function (_a) {
229
- switch (_a.label) {
230
- case 0: return [4 /*yield*/, this.ensureScreeb("eventTrack")];
231
- case 1:
232
- _a.sent();
233
- return [2 /*return*/, _Screeb.eventTrack(eventName, eventProperties)];
234
- }
235
- });
236
- });
237
- };
238
- /**
239
- * Change the current user identity.
240
- * Warning: Running surveys will be closed.
241
- *
242
- * @param userId The unique identifier of your user.
243
- * @param userProperties The properties of your user.
244
- * ```text Requirements:
245
- * - Property names must be limited to 128 characters
246
- * - No more than 1000 attributes
247
- * - Supported types for values: string, number, boolean and Date.
248
- * ```
249
- *
250
- * @example
251
- * ```ts
252
- * this.screeb.identity(
253
- * "<your-user-id>",
254
- * {
255
- * firstname: '<user-firstname>',
256
- * lastname: '<user-lastname>',
257
- * plan: '<user-plan>',
258
- * last_seen_at: new Date(),
259
- * authenticated: true
260
- * }
261
- * );
262
- * ```
263
- */
264
- Screeb.prototype.identity = function (userId, userProperties) {
265
- return __awaiter(this, void 0, void 0, function () {
266
- return __generator(this, function (_a) {
267
- switch (_a.label) {
268
- case 0: return [4 /*yield*/, this.ensureScreeb("identity")];
269
- case 1:
270
- _a.sent();
271
- return [2 /*return*/, _Screeb.identity(userId, userProperties)];
272
- }
273
- });
274
- });
275
- };
276
- /**
277
- * Retrieves the current user identity.
278
- *
279
- * @example
280
- * ```ts
281
- * console.log(await this.screeb.identityGet());
282
- * // {
283
- * // anonymous_id: "<UUID>",
284
- * // user_id: "<UUID>",
285
- * // session_id: "<UUID>",
286
- * // session_start: "2023-05-04T16:30:15.882Z",
287
- * // session_end: "2023-05-04T17:02:09.087Z",
288
- * // channel_id: "<UUID>",
289
- * // is_ready: true,
290
- * // }
291
- * ```
292
- */
293
- Screeb.prototype.identityGet = function () {
294
- return __awaiter(this, void 0, void 0, function () {
295
- return __generator(this, function (_a) {
296
- switch (_a.label) {
297
- case 0: return [4 /*yield*/, this.ensureScreeb("identityGet")];
298
- case 1:
299
- _a.sent();
300
- return [2 /*return*/, _Screeb.identityGet()];
301
- }
302
- });
303
- });
304
- };
305
- /**
306
- * Assigns the current user to a group.
307
- *
308
- * @param groupName
309
- * @param groupType
310
- * @param groupProperties The properties of your user group.
311
- * ```text Requirements:
312
- * - Property names must be limited to 128 characters
313
- * - No more than 1000 attributes
314
- * - Supported types for values: string, number, boolean and Date.
315
- * ```
316
- *
317
- * @example
318
- * ```ts
319
- * this.screeb.identityGroupAssign(
320
- * 'company',
321
- * 'Apple',
322
- * {
323
- * address_line_1: 'Apple Campus',
324
- * address_line_2: '1 Infinite Loop',
325
- * city: 'Cupertino',
326
- * zipcode: 95014,
327
- * state: 'California',
328
- * country: 'United states',
329
- * }
330
- * );
331
- * ```
332
- */
333
- Screeb.prototype.identityGroupAssign = function (groupName, groupType, groupProperties) {
334
- return __awaiter(this, void 0, void 0, function () {
335
- return __generator(this, function (_a) {
336
- switch (_a.label) {
337
- case 0: return [4 /*yield*/, this.ensureScreeb("identityGroupAssign")];
338
- case 1:
339
- _a.sent();
340
- return [2 /*return*/, _Screeb.identityGroupAssign(groupName, groupType, groupProperties)];
341
- }
342
- });
343
- });
344
- };
345
- /**
346
- * Unassigns the current user to a group.
347
- *
348
- * @param groupName The name of your user group.
349
- * @param groupType The type of your user group.
350
- *
351
- * @example
352
- * ```ts
353
- * this.screeb.identityGroupUnassign('company', 'Apple');
354
- * ```
355
- */
356
- Screeb.prototype.identityGroupUnassign = function (groupName, groupType) {
357
- return __awaiter(this, void 0, void 0, function () {
358
- return __generator(this, function (_a) {
359
- switch (_a.label) {
360
- case 0: return [4 /*yield*/, this.ensureScreeb("identityGroupUnassign")];
361
- case 1:
362
- _a.sent();
363
- return [2 /*return*/, _Screeb.identityGroupUnassign(groupName, groupType)];
364
- }
365
- });
366
- });
367
- };
368
- /**
369
- * Adds properties to the current user identity.
370
- *
371
- * @param userProperties The properties of your user.
372
- * ```text Requirements:
373
- * - Property names must be limited to 128 characters
374
- * - No more than 1000 attributes
375
- * - Supported types for values: string, number, boolean and Date.
376
- * ```
377
- *
378
- * @example
379
- * ```ts
380
- * // Set user properties
381
- * this.screeb.identityProperties(
382
- * {
383
- * firstname: '<user-firstname>',
384
- * lastname: '<user-lastname>',
385
- * plan: '<user-plan>',
386
- * last_seen_at: new Date(),
387
- * authenticated: true
388
- * }
389
- * );
390
- *
391
- * // Delete user property : set values to null
392
- * this.screeb.identityProperties(
393
- * {
394
- * age: null,
395
- * company: null,
396
- * logged: true,
397
- * }
398
- * );
399
- * ```
400
- */
401
- Screeb.prototype.identityProperties = function (userProperties) {
402
- return __awaiter(this, void 0, void 0, function () {
403
- return __generator(this, function (_a) {
404
- switch (_a.label) {
405
- case 0: return [4 /*yield*/, this.ensureScreeb("identityProperties")];
406
- case 1:
407
- _a.sent();
408
- return [2 /*return*/, _Screeb.identityProperties(userProperties)];
409
- }
410
- });
411
- });
412
- };
413
- /**
414
- * Resets the current user identity.
415
- * Warning: This command must be called only once, since it creates a new identity on Screeb side.
416
- *
417
- * @example
418
- * ```ts
419
- * this.screeb.identityReset();
420
- * ```
421
- */
422
- Screeb.prototype.identityReset = function () {
423
- return __awaiter(this, void 0, void 0, function () {
424
- return __generator(this, function (_a) {
425
- switch (_a.label) {
426
- case 0: return [4 /*yield*/, this.ensureScreeb("identityReset")];
427
- case 1:
428
- _a.sent();
429
- return [2 /*return*/, _Screeb.identityReset()];
430
- }
431
- });
432
- });
433
- };
434
- /**
435
- * Interrupts a running survey.
436
- *
437
- * @example
438
- * ```ts
439
- * this.screeb.surveyClose();
440
- * ```
441
- */
442
- Screeb.prototype.surveyClose = function () {
443
- return __awaiter(this, void 0, void 0, function () {
444
- return __generator(this, function (_a) {
445
- switch (_a.label) {
446
- case 0: return [4 /*yield*/, this.ensureScreeb("surveyClose")];
447
- case 1:
448
- _a.sent();
449
- return [2 /*return*/, _Screeb.surveyClose()];
450
- }
451
- });
452
- });
453
- };
454
- /**
455
- * Starts a survey by its ID.
456
- *
457
- * @example
458
- * ```ts
459
- * this.screeb.surveyStart(
460
- * '<UUID>',
461
- * false,
462
- * {
463
- * color: "green",
464
- * article_id: 42
465
- * }
466
- * );
467
- * ```
468
- */
469
- Screeb.prototype.surveyStart = function (surveyId, allowMultipleResponses, hiddenFields) {
470
- return __awaiter(this, void 0, void 0, function () {
471
- return __generator(this, function (_a) {
472
- switch (_a.label) {
473
- case 0: return [4 /*yield*/, this.ensureScreeb("surveyStart")];
474
- case 1:
475
- _a.sent();
476
- return [2 /*return*/, _Screeb.surveyStart(surveyId, allowMultipleResponses, hiddenFields)];
477
- }
478
- });
479
- });
480
- };
481
- /**
482
- * Forces a targeting check.
483
- *
484
- * @example
485
- * ```ts
486
- * this.screeb.targetingCheck();
487
- * ```
488
- */
489
- Screeb.prototype.targetingCheck = function () {
490
- return __awaiter(this, void 0, void 0, function () {
491
- return __generator(this, function (_a) {
492
- switch (_a.label) {
493
- case 0: return [4 /*yield*/, this.ensureScreeb("targetingCheck")];
494
- case 1:
495
- _a.sent();
496
- return [2 /*return*/, _Screeb.targetingCheck()];
497
- }
498
- });
499
- });
500
- };
501
- /**
502
- * Prints the current state of the targeting engine.
503
- *
504
- * @example
505
- * ```ts
506
- * console.log(await this.screeb.targetingDebug());
507
- * // targeting ************ SCREEB TARGETING RULES DEBUG **************
508
- * // Disabled surveys are not listed here.
509
- * //
510
- * // Screeb channel id: <UUID>
511
- * // Screeb respondent id: <UUID>
512
- * //
513
- * // Survey <UUID>:
514
- * // https://admin.screeb.app/org/last/survey/<UUID>/share
515
- * //
516
- * // - Rule of type "Device type (desktop/mobile/tablet)": true 🟢
517
- * // - Rule of type "Multiple display": true 🟢
518
- * // - Rule of type "Capping per time between survey display on current respondent": true 🟢
519
- * // - Rule of type "User event count": false 🔴
520
- * // - Rule of type "Capping per respondent display count": false 🔴
521
- * ```
522
- */
523
- Screeb.prototype.targetingDebug = function () {
524
- return __awaiter(this, void 0, void 0, function () {
525
- return __generator(this, function (_a) {
526
- switch (_a.label) {
527
- case 0: return [4 /*yield*/, this.ensureScreeb("targetingDebug")];
528
- case 1:
529
- _a.sent();
530
- return [2 /*return*/, _Screeb.targetingDebug()];
531
- }
532
- });
533
- });
534
- };
535
- /**
536
- * Initializes Screeb tag.
537
- *
538
- * @param websiteId Your website/channel id.
539
- * @param userId The unique identifier of your user.
540
- * @param userProperties The properties of your user.
541
- * ```text Requirements:
542
- * - Property names must be limited to 128 characters
543
- * - No more than 1000 attributes
544
- * - Supported types for values: string, number, boolean and Date
545
- * ```
546
- *
547
- * @example
548
- * ```ts
549
- * this.screeb.init(
550
- * "<your-website-id>",
551
- * "<your-user-id>",
552
- * {
553
- * firstname: '<user-firstname>',
554
- * lastname: '<user-lastname>',
555
- * plan: '<user-plan>',
556
- * last_seen_at: new Date(),
557
- * authenticated: true
558
- * }
559
- * );
560
- * ```
561
- */
562
- Screeb.prototype.init = function (websiteId, userId, userProperties) {
563
- return __awaiter(this, void 0, void 0, function () {
564
- return __generator(this, function (_a) {
565
- switch (_a.label) {
566
- case 0: return [4 /*yield*/, this.ensureScreeb("init", true)];
567
- case 1:
568
- _a.sent();
569
- this.isInitialized = true;
570
- return [4 /*yield*/, _Screeb.init(websiteId, userId, userProperties)];
571
- case 2: return [2 /*return*/, _a.sent()];
572
- }
573
- });
574
- });
575
- };
576
- /**
577
- * Appends Screeb tag into your dom.
578
- *
579
- * @param options Screeb module options.
580
- * @param options.window If you're running Screeb tag in an iframe, please set the inner window here.
581
- * @param options.screebEndpoint Please don't do this.
582
- *
583
- * @example
584
- * ```ts
585
- * this.screeb.load();
586
- * ```
587
- */
588
- Screeb.prototype.load = function () {
589
- return __awaiter(this, void 0, void 0, function () {
590
- return __generator(this, function (_a) {
591
- return [2 /*return*/, _Screeb.load()];
592
- });
593
- });
594
- };
595
- Screeb = __decorate([
596
- Injectable({ providedIn: "root" }),
597
- __param(0, Inject(ScreebConfig)),
598
- __metadata("design:paramtypes", [ScreebConfig])
599
- ], Screeb);
600
- return Screeb;
601
- }());
602
-
603
- var ScreebModule = /** @class */ (function () {
604
- function ScreebModule(config, screeb) {
605
- var _a, _b;
606
- if ((_a = config.shouldLoad) !== null && _a !== void 0 ? _a : true) {
607
- screeb.load();
608
- }
609
- if (((_b = config.autoInit) !== null && _b !== void 0 ? _b : false) && config.websiteId) {
610
- screeb.init(config.websiteId, config.userId, config.userProperties);
611
- }
612
- }
613
- ScreebModule_1 = ScreebModule;
614
- /**
615
- * This is used to initialize Screeb at the top of your Angular application
616
- * @param config Configuration to pass to Screeb browser SDK
617
- *
618
- * @example
619
- * ```ts
620
- * ScreebModule.forRoot({
621
- * autoInit: true,
622
- * "<your-website-id>",
623
- * "<your-user-id>",
624
- * {
625
- * firstname: '<user-firstname>',
626
- * lastname: '<user-lastname>',
627
- * plan: '<user-plan>',
628
- * last_seen_at: new Date(),
629
- * authenticated: true
630
- * }
631
- * })
632
- * ```
633
- */
634
- ScreebModule.forRoot = function (config) {
635
- return {
636
- ngModule: ScreebModule_1,
637
- providers: [Screeb, { provide: ScreebConfig, useValue: config }],
638
- };
639
- };
640
- var ScreebModule_1;
641
- ScreebModule = ScreebModule_1 = __decorate([
642
- NgModule({
643
- providers: [Screeb, ScreebConfig],
644
- }),
645
- __param(0, Inject(ScreebConfig)),
646
- __param(1, Inject(Screeb)),
647
- __metadata("design:paramtypes", [ScreebConfig,
648
- Screeb])
649
- ], ScreebModule);
650
- return ScreebModule;
651
- }());
652
-
653
- export { Screeb, ScreebConfig, ScreebModule };
File without changes