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

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 +16 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -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) => {
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.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",