@blotoutio/edgetag-sdk-browser 0.10.1 → 0.10.2-beta.1

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.
Files changed (2) hide show
  1. package/index.js +40 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -13,29 +13,29 @@
13
13
  get getUserId () { return getUserId; }
14
14
  });
15
15
 
16
- /******************************************************************************
17
- Copyright (c) Microsoft Corporation.
18
-
19
- Permission to use, copy, modify, and/or distribute this software for any
20
- purpose with or without fee is hereby granted.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
- PERFORMANCE OF THIS SOFTWARE.
29
- ***************************************************************************** */
30
-
31
- function __awaiter(thisArg, _arguments, P, generator) {
32
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
- return new (P || (P = Promise))(function (resolve, reject) {
34
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
- step((generator = generator.apply(thisArg, _arguments || [])).next());
38
- });
16
+ /******************************************************************************
17
+ Copyright (c) Microsoft Corporation.
18
+
19
+ Permission to use, copy, modify, and/or distribute this software for any
20
+ purpose with or without fee is hereby granted.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
+ PERFORMANCE OF THIS SOFTWARE.
29
+ ***************************************************************************** */
30
+
31
+ function __awaiter(thisArg, _arguments, P, generator) {
32
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
+ return new (P || (P = Promise))(function (resolve, reject) {
34
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
38
+ });
39
39
  }
40
40
 
41
41
  const getMessage = (error) => {
@@ -295,6 +295,8 @@
295
295
  const tagStorage = 'edgeTag';
296
296
  const consentKey = 'consent';
297
297
  const keyPrefix = `_worker`;
298
+ const backupCookieKey = `cookieId`;
299
+ const cookieKey = 'tag_user_id';
298
300
 
299
301
  const initKey = `${keyPrefix}Store`;
300
302
  const saveDataPerKey = (persistType, provider, value, key) => {
@@ -473,7 +475,11 @@
473
475
  if (initUserId) {
474
476
  return initUserId;
475
477
  }
476
- return getCookieValue('tag_user_id');
478
+ const data = getDataPerKey('local', tagStorage, backupCookieKey);
479
+ if (!data || data.length < 10) {
480
+ return getCookieValue('tag_user_id');
481
+ }
482
+ return data;
477
483
  };
478
484
  const setUserId = (userId) => {
479
485
  initUserId = userId;
@@ -484,6 +490,13 @@
484
490
  Accept: 'application/json; charset=utf-8',
485
491
  EdgeTagUserId: handleGetUserId(),
486
492
  });
493
+ const cookieIdFallback = () => {
494
+ const data = getDataPerKey('local', tagStorage, backupCookieKey);
495
+ if (data) {
496
+ return;
497
+ }
498
+ savePerKey('local', tagStorage, getCookieValue(cookieKey), backupCookieKey);
499
+ };
487
500
  const beacon = (url, payload) => {
488
501
  try {
489
502
  let blob;
@@ -505,6 +518,7 @@
505
518
  return new Promise((resolve, reject) => {
506
519
  const req = https.request(url, options, (res) => {
507
520
  res.on('data', (data) => {
521
+ cookieIdFallback();
508
522
  try {
509
523
  data = JSON.parse(data);
510
524
  }
@@ -550,6 +564,7 @@
550
564
  if (data.status < 200 || data.status >= 300) {
551
565
  return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
552
566
  }
567
+ cookieIdFallback();
553
568
  return Promise.resolve(data.body);
554
569
  })
555
570
  .catch((error) => {
@@ -557,7 +572,7 @@
557
572
  });
558
573
  });
559
574
  const getStandardPayload = (payload) => {
560
- const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.1" }, (payload || {}));
575
+ const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.2-beta.1" }, (payload || {}));
561
576
  let storage = {};
562
577
  const session = getData$1('session');
563
578
  if (session) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.10.1",
3
+ "version": "0.10.2-beta.1",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",