@blotoutio/edgetag-sdk-js 0.7.2 → 0.8.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.
package/index.cjs CHANGED
@@ -211,6 +211,43 @@ const getUserAgent = () => {
211
211
  return '';
212
212
  }
213
213
  };
214
+ const getReferrer = () => {
215
+ let referrer = '';
216
+ try {
217
+ const referrerUrl = new URL(document.referrer);
218
+ if (referrerUrl.host !== window.location.host) {
219
+ referrer = referrerUrl.href;
220
+ }
221
+ return referrer;
222
+ }
223
+ catch (error) {
224
+ return referrer;
225
+ }
226
+ };
227
+ const getPageUrl = () => {
228
+ try {
229
+ return window.location.href;
230
+ }
231
+ catch (_a) {
232
+ return '';
233
+ }
234
+ };
235
+ const getSearch = () => {
236
+ try {
237
+ return window.location.search;
238
+ }
239
+ catch (_a) {
240
+ return '';
241
+ }
242
+ };
243
+ const getPageTitle = () => {
244
+ try {
245
+ return document.title;
246
+ }
247
+ catch (_a) {
248
+ return '';
249
+ }
250
+ };
214
251
  const isProviderIncluded = (providers, providerValue) => {
215
252
  return (providerValue || (providers['all'] === true && providerValue === undefined));
216
253
  };
@@ -283,29 +320,6 @@ const consentKey = 'consent';
283
320
  const keyPrefix = `_worker`;
284
321
 
285
322
  const initKey = `${keyPrefix}Store`;
286
- const getCookieValue = (key) => {
287
- try {
288
- if (!document || !document.cookie) {
289
- return '';
290
- }
291
- const name = `${key}=`;
292
- const decodedCookie = decodeURIComponent(document.cookie);
293
- const ca = decodedCookie.split(';');
294
- for (let i = 0; i < ca.length; i++) {
295
- let c = ca[i];
296
- while (c.charAt(0) === ' ') {
297
- c = c.substring(1);
298
- }
299
- if (c.indexOf(name) === 0) {
300
- return c.substring(name.length, c.length);
301
- }
302
- }
303
- return '';
304
- }
305
- catch (_a) {
306
- return '';
307
- }
308
- };
309
323
  const saveDataPerKey = (persistType, provider, value, key) => {
310
324
  const storage = getData$1(persistType);
311
325
  if (!storage['data']) {
@@ -409,6 +423,48 @@ const getSession = (key) => {
409
423
  }
410
424
  };
411
425
 
426
+ const encodeString = (name) => {
427
+ if (typeof btoa === 'undefined') {
428
+ return Buffer.from(name).toString('base64');
429
+ }
430
+ return btoa(name);
431
+ };
432
+ const generateEventId = (name) => {
433
+ let time = Date.now().toString();
434
+ if (typeof performance !== 'undefined' &&
435
+ typeof performance.now === 'function') {
436
+ const perf = performance.now();
437
+ if (perf) {
438
+ time = perf.toFixed(4);
439
+ }
440
+ }
441
+ return `${encodeString(name)}-${uuid.v4()}-${time}`;
442
+ };
443
+
444
+ const getCookieValue = (key) => {
445
+ try {
446
+ if (!document || !document.cookie) {
447
+ return '';
448
+ }
449
+ const name = `${key}=`;
450
+ const decodedCookie = decodeURIComponent(document.cookie);
451
+ const ca = decodedCookie.split(';');
452
+ for (let i = 0; i < ca.length; i++) {
453
+ let c = ca[i];
454
+ while (c.charAt(0) === ' ') {
455
+ c = c.substring(1);
456
+ }
457
+ if (c.indexOf(name) === 0) {
458
+ return c.substring(name.length, c.length);
459
+ }
460
+ }
461
+ return '';
462
+ }
463
+ catch (_a) {
464
+ return '';
465
+ }
466
+ };
467
+
412
468
  let initUserId = '';
413
469
  const handleGetUserId = () => {
414
470
  if (initUserId) {
@@ -498,14 +554,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
498
554
  });
499
555
  });
500
556
  const getStandardPayload = (payload) => {
501
- let pageUrl;
502
- try {
503
- pageUrl = window.location.href;
504
- }
505
- catch (_a) {
506
- pageUrl = '';
507
- }
508
- const data = Object.assign({ pageUrl, userAgent: getUserAgent() }, (payload || {}));
557
+ const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch() }, (payload || {}));
509
558
  let storage = {};
510
559
  const session = getData$1('session');
511
560
  if (session) {
@@ -567,24 +616,6 @@ const getConsent = () => {
567
616
  return memoryConsent;
568
617
  };
569
618
 
570
- const encodeString = (name) => {
571
- if (typeof btoa === 'undefined') {
572
- return Buffer.from(name).toString('base64');
573
- }
574
- return btoa(name);
575
- };
576
- const generateEventId = (name) => {
577
- let time = Date.now().toString();
578
- if (typeof performance !== 'undefined' &&
579
- typeof performance.now === 'function') {
580
- const perf = performance.now();
581
- if (perf) {
582
- time = perf.toFixed(4);
583
- }
584
- }
585
- return `${encodeString(name)}-${uuid.v4()}-${time}`;
586
- };
587
-
588
619
  const manifestVariables = {};
589
620
  const addProviderVariable = (name, variables) => {
590
621
  manifestVariables[name] = variables;
@@ -678,12 +709,25 @@ const handleTag = (eventName, data = {}, providers, options) => {
678
709
  });
679
710
  };
680
711
 
681
- const handleData = (data, options) => {
712
+ const handleData = (data, providers, options) => {
682
713
  if (!data || Object.keys(data).length === 0) {
683
714
  error('Provide data for data API.');
684
715
  return;
685
716
  }
686
717
  saveKV(data);
718
+ const providerPackages = getProvidersPackage();
719
+ const userId = handleGetUserId();
720
+ if (providerPackages) {
721
+ Object.values(providerPackages).forEach((pkg) => {
722
+ if (!pkg || !pkg.user || !allowProviderWithConsent(providers, pkg.name)) {
723
+ return;
724
+ }
725
+ pkg.user({
726
+ userId,
727
+ data,
728
+ });
729
+ });
730
+ }
687
731
  postRequest(getDataURL(), { data }, options).catch(error);
688
732
  };
689
733
 
@@ -769,6 +813,18 @@ const handleCapture = (provider, params) => {
769
813
  });
770
814
  };
771
815
 
816
+ const handleGetData = (keys, callback) => {
817
+ if (!keys || keys.length === 0) {
818
+ error('Provide keys for get data API.');
819
+ return;
820
+ }
821
+ getRequest(getGetDataURL(keys))
822
+ .then((result) => {
823
+ callback((result === null || result === void 0 ? void 0 : result.result) || {});
824
+ })
825
+ .catch(error);
826
+ };
827
+
772
828
  const handleManifest = (manifest) => {
773
829
  const providerPackages = getProvidersPackage();
774
830
  const userId = handleGetUserId();
@@ -788,7 +844,15 @@ const handleManifest = (manifest) => {
788
844
  if (providerPackages) {
789
845
  const pkg = providerPackages[provider.package];
790
846
  if (pkg && pkg.init && allowProvider(pkg.name)) {
791
- pkg.init({ userId, manifest: provider, sendTag });
847
+ const initData = {
848
+ userId,
849
+ manifest: provider,
850
+ sendTag,
851
+ sendEdgeData: handleData,
852
+ getEdgeData: handleGetData,
853
+ keyName: `${keyPrefix}Store`,
854
+ };
855
+ pkg.init(initData);
792
856
  }
793
857
  }
794
858
  });
@@ -824,7 +888,7 @@ const handleInit = (preferences) => {
824
888
  .catch(error);
825
889
  };
826
890
 
827
- const handleUser = (key, value, options) => {
891
+ const handleUser = (key, value, providers, options) => {
828
892
  if (!key || !value) {
829
893
  error('Key or Value is missing in user API.');
830
894
  return;
@@ -832,24 +896,25 @@ const handleUser = (key, value, options) => {
832
896
  saveKV({
833
897
  [key]: value,
834
898
  });
899
+ const providerPackages = getProvidersPackage();
900
+ const userId = handleGetUserId();
901
+ if (providerPackages) {
902
+ Object.values(providerPackages).forEach((pkg) => {
903
+ if (!pkg || !pkg.user || !allowProviderWithConsent(providers, pkg.name)) {
904
+ return;
905
+ }
906
+ pkg.user({
907
+ userId,
908
+ data: { [key]: value },
909
+ });
910
+ });
911
+ }
835
912
  postRequest(getUserURL(), {
836
913
  key,
837
914
  value,
838
915
  }, options).catch(error);
839
916
  };
840
917
 
841
- const handleGetData = (keys, callback) => {
842
- if (!keys || keys.length === 0) {
843
- error('Provide keys for get data API.');
844
- return;
845
- }
846
- getRequest(getGetDataURL(keys))
847
- .then((result) => {
848
- callback((result === null || result === void 0 ? void 0 : result.result) || {});
849
- })
850
- .catch(error);
851
- };
852
-
853
918
  const handleKeys = (callback) => {
854
919
  getRequest(getKeysURL())
855
920
  .then((result) => {
@@ -867,11 +932,11 @@ const tag = (name, data, providers, options) => {
867
932
  const consent = (consent) => {
868
933
  handleConsent(consent);
869
934
  };
870
- const user = (key, value, options) => {
871
- handleUser(key, value, options);
935
+ const user = (key, value, providers, options) => {
936
+ handleUser(key, value, providers, options);
872
937
  };
873
- const data = (data, options) => {
874
- handleData(data, options);
938
+ const data = (data, providers, options) => {
939
+ handleData(data, providers, options);
875
940
  };
876
941
  const getData = (keys, callback) => {
877
942
  handleGetData(keys, callback);
package/index.d.ts CHANGED
@@ -87,9 +87,18 @@ export declare const tag: (
87
87
 
88
88
  export declare const consent: (consent: Data) => void
89
89
 
90
- export declare const user: (key: UserKey, value: string) => void
90
+ export declare const user: (
91
+ key: UserKey,
92
+ value: string,
93
+ providers?: Data,
94
+ options?: EventOptions
95
+ ) => void
91
96
 
92
- export declare const data: (data: Record<string, string>) => void
97
+ export declare const data: (
98
+ data: Record<string, string>,
99
+ providers?: Data,
100
+ options?: EventOptions
101
+ ) => void
93
102
 
94
103
  export declare const getData: (
95
104
  keys: string[],
package/index.esm.js CHANGED
@@ -189,6 +189,43 @@ const getUserAgent = () => {
189
189
  return '';
190
190
  }
191
191
  };
192
+ const getReferrer = () => {
193
+ let referrer = '';
194
+ try {
195
+ const referrerUrl = new URL(document.referrer);
196
+ if (referrerUrl.host !== window.location.host) {
197
+ referrer = referrerUrl.href;
198
+ }
199
+ return referrer;
200
+ }
201
+ catch (error) {
202
+ return referrer;
203
+ }
204
+ };
205
+ const getPageUrl = () => {
206
+ try {
207
+ return window.location.href;
208
+ }
209
+ catch (_a) {
210
+ return '';
211
+ }
212
+ };
213
+ const getSearch = () => {
214
+ try {
215
+ return window.location.search;
216
+ }
217
+ catch (_a) {
218
+ return '';
219
+ }
220
+ };
221
+ const getPageTitle = () => {
222
+ try {
223
+ return document.title;
224
+ }
225
+ catch (_a) {
226
+ return '';
227
+ }
228
+ };
192
229
  const isProviderIncluded = (providers, providerValue) => {
193
230
  return (providerValue || (providers['all'] === true && providerValue === undefined));
194
231
  };
@@ -261,29 +298,6 @@ const consentKey = 'consent';
261
298
  const keyPrefix = `_worker`;
262
299
 
263
300
  const initKey = `${keyPrefix}Store`;
264
- const getCookieValue = (key) => {
265
- try {
266
- if (!document || !document.cookie) {
267
- return '';
268
- }
269
- const name = `${key}=`;
270
- const decodedCookie = decodeURIComponent(document.cookie);
271
- const ca = decodedCookie.split(';');
272
- for (let i = 0; i < ca.length; i++) {
273
- let c = ca[i];
274
- while (c.charAt(0) === ' ') {
275
- c = c.substring(1);
276
- }
277
- if (c.indexOf(name) === 0) {
278
- return c.substring(name.length, c.length);
279
- }
280
- }
281
- return '';
282
- }
283
- catch (_a) {
284
- return '';
285
- }
286
- };
287
301
  const saveDataPerKey = (persistType, provider, value, key) => {
288
302
  const storage = getData$1(persistType);
289
303
  if (!storage['data']) {
@@ -387,6 +401,48 @@ const getSession = (key) => {
387
401
  }
388
402
  };
389
403
 
404
+ const encodeString = (name) => {
405
+ if (typeof btoa === 'undefined') {
406
+ return Buffer.from(name).toString('base64');
407
+ }
408
+ return btoa(name);
409
+ };
410
+ const generateEventId = (name) => {
411
+ let time = Date.now().toString();
412
+ if (typeof performance !== 'undefined' &&
413
+ typeof performance.now === 'function') {
414
+ const perf = performance.now();
415
+ if (perf) {
416
+ time = perf.toFixed(4);
417
+ }
418
+ }
419
+ return `${encodeString(name)}-${v4()}-${time}`;
420
+ };
421
+
422
+ const getCookieValue = (key) => {
423
+ try {
424
+ if (!document || !document.cookie) {
425
+ return '';
426
+ }
427
+ const name = `${key}=`;
428
+ const decodedCookie = decodeURIComponent(document.cookie);
429
+ const ca = decodedCookie.split(';');
430
+ for (let i = 0; i < ca.length; i++) {
431
+ let c = ca[i];
432
+ while (c.charAt(0) === ' ') {
433
+ c = c.substring(1);
434
+ }
435
+ if (c.indexOf(name) === 0) {
436
+ return c.substring(name.length, c.length);
437
+ }
438
+ }
439
+ return '';
440
+ }
441
+ catch (_a) {
442
+ return '';
443
+ }
444
+ };
445
+
390
446
  let initUserId = '';
391
447
  const handleGetUserId = () => {
392
448
  if (initUserId) {
@@ -476,14 +532,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
476
532
  });
477
533
  });
478
534
  const getStandardPayload = (payload) => {
479
- let pageUrl;
480
- try {
481
- pageUrl = window.location.href;
482
- }
483
- catch (_a) {
484
- pageUrl = '';
485
- }
486
- const data = Object.assign({ pageUrl, userAgent: getUserAgent() }, (payload || {}));
535
+ const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch() }, (payload || {}));
487
536
  let storage = {};
488
537
  const session = getData$1('session');
489
538
  if (session) {
@@ -545,24 +594,6 @@ const getConsent = () => {
545
594
  return memoryConsent;
546
595
  };
547
596
 
548
- const encodeString = (name) => {
549
- if (typeof btoa === 'undefined') {
550
- return Buffer.from(name).toString('base64');
551
- }
552
- return btoa(name);
553
- };
554
- const generateEventId = (name) => {
555
- let time = Date.now().toString();
556
- if (typeof performance !== 'undefined' &&
557
- typeof performance.now === 'function') {
558
- const perf = performance.now();
559
- if (perf) {
560
- time = perf.toFixed(4);
561
- }
562
- }
563
- return `${encodeString(name)}-${v4()}-${time}`;
564
- };
565
-
566
597
  const manifestVariables = {};
567
598
  const addProviderVariable = (name, variables) => {
568
599
  manifestVariables[name] = variables;
@@ -656,12 +687,25 @@ const handleTag = (eventName, data = {}, providers, options) => {
656
687
  });
657
688
  };
658
689
 
659
- const handleData = (data, options) => {
690
+ const handleData = (data, providers, options) => {
660
691
  if (!data || Object.keys(data).length === 0) {
661
692
  error('Provide data for data API.');
662
693
  return;
663
694
  }
664
695
  saveKV(data);
696
+ const providerPackages = getProvidersPackage();
697
+ const userId = handleGetUserId();
698
+ if (providerPackages) {
699
+ Object.values(providerPackages).forEach((pkg) => {
700
+ if (!pkg || !pkg.user || !allowProviderWithConsent(providers, pkg.name)) {
701
+ return;
702
+ }
703
+ pkg.user({
704
+ userId,
705
+ data,
706
+ });
707
+ });
708
+ }
665
709
  postRequest(getDataURL(), { data }, options).catch(error);
666
710
  };
667
711
 
@@ -747,6 +791,18 @@ const handleCapture = (provider, params) => {
747
791
  });
748
792
  };
749
793
 
794
+ const handleGetData = (keys, callback) => {
795
+ if (!keys || keys.length === 0) {
796
+ error('Provide keys for get data API.');
797
+ return;
798
+ }
799
+ getRequest(getGetDataURL(keys))
800
+ .then((result) => {
801
+ callback((result === null || result === void 0 ? void 0 : result.result) || {});
802
+ })
803
+ .catch(error);
804
+ };
805
+
750
806
  const handleManifest = (manifest) => {
751
807
  const providerPackages = getProvidersPackage();
752
808
  const userId = handleGetUserId();
@@ -766,7 +822,15 @@ const handleManifest = (manifest) => {
766
822
  if (providerPackages) {
767
823
  const pkg = providerPackages[provider.package];
768
824
  if (pkg && pkg.init && allowProvider(pkg.name)) {
769
- pkg.init({ userId, manifest: provider, sendTag });
825
+ const initData = {
826
+ userId,
827
+ manifest: provider,
828
+ sendTag,
829
+ sendEdgeData: handleData,
830
+ getEdgeData: handleGetData,
831
+ keyName: `${keyPrefix}Store`,
832
+ };
833
+ pkg.init(initData);
770
834
  }
771
835
  }
772
836
  });
@@ -802,7 +866,7 @@ const handleInit = (preferences) => {
802
866
  .catch(error);
803
867
  };
804
868
 
805
- const handleUser = (key, value, options) => {
869
+ const handleUser = (key, value, providers, options) => {
806
870
  if (!key || !value) {
807
871
  error('Key or Value is missing in user API.');
808
872
  return;
@@ -810,24 +874,25 @@ const handleUser = (key, value, options) => {
810
874
  saveKV({
811
875
  [key]: value,
812
876
  });
877
+ const providerPackages = getProvidersPackage();
878
+ const userId = handleGetUserId();
879
+ if (providerPackages) {
880
+ Object.values(providerPackages).forEach((pkg) => {
881
+ if (!pkg || !pkg.user || !allowProviderWithConsent(providers, pkg.name)) {
882
+ return;
883
+ }
884
+ pkg.user({
885
+ userId,
886
+ data: { [key]: value },
887
+ });
888
+ });
889
+ }
813
890
  postRequest(getUserURL(), {
814
891
  key,
815
892
  value,
816
893
  }, options).catch(error);
817
894
  };
818
895
 
819
- const handleGetData = (keys, callback) => {
820
- if (!keys || keys.length === 0) {
821
- error('Provide keys for get data API.');
822
- return;
823
- }
824
- getRequest(getGetDataURL(keys))
825
- .then((result) => {
826
- callback((result === null || result === void 0 ? void 0 : result.result) || {});
827
- })
828
- .catch(error);
829
- };
830
-
831
896
  const handleKeys = (callback) => {
832
897
  getRequest(getKeysURL())
833
898
  .then((result) => {
@@ -845,11 +910,11 @@ const tag = (name, data, providers, options) => {
845
910
  const consent = (consent) => {
846
911
  handleConsent(consent);
847
912
  };
848
- const user = (key, value, options) => {
849
- handleUser(key, value, options);
913
+ const user = (key, value, providers, options) => {
914
+ handleUser(key, value, providers, options);
850
915
  };
851
- const data = (data, options) => {
852
- handleData(data, options);
916
+ const data = (data, providers, options) => {
917
+ handleData(data, providers, options);
853
918
  };
854
919
  const getData = (keys, callback) => {
855
920
  handleGetData(keys, callback);
package/internal.d.ts CHANGED
@@ -29,6 +29,9 @@ type DataPayload = {
29
29
 
30
30
  type PostPayload = {
31
31
  pageUrl: string
32
+ pageTitle: string
33
+ referrer: string
34
+ search: string
32
35
  userAgent: string
33
36
  data?: Data
34
37
  storage?: Data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",