@mparticle/web-rokt-kit 1.16.0 → 1.18.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.
@@ -259,6 +259,8 @@ var constructor = function () {
259
259
  );
260
260
  launcherOptions.integrationName = self.integrationName;
261
261
 
262
+ self.domain = domain;
263
+
262
264
  if (testMode) {
263
265
  self.testHelpers = {
264
266
  generateLauncherScript: generateLauncherScript,
@@ -268,6 +270,12 @@ var constructor = function () {
268
270
  generateMappedEventLookup: generateMappedEventLookup,
269
271
  generateMappedEventAttributeLookup:
270
272
  generateMappedEventAttributeLookup,
273
+ sendAdBlockMeasurementSignals: sendAdBlockMeasurementSignals,
274
+ createAutoRemovedIframe: createAutoRemovedIframe,
275
+ djb2: djb2,
276
+ setAllowedOriginHash: function (hash) {
277
+ _allowedOriginHash = hash;
278
+ },
271
279
  };
272
280
  attachLauncher(accountId, launcherOptions);
273
281
  return;
@@ -408,10 +416,40 @@ var constructor = function () {
408
416
  attributes: selectPlacementsAttributes,
409
417
  });
410
418
 
411
- // Log custom event for selectPlacements call
412
- logSelectPlacementsEvent(selectPlacementsAttributes);
419
+ var selection = self.launcher.selectPlacements(selectPlacementsOptions);
420
+
421
+ // After selection resolves, sync the Rokt session ID back to mParticle
422
+ // as an integration attribute so server-side integrations can link events.
423
+ // We log the custom event AFTER setting the attribute because
424
+ // setIntegrationAttribute alone doesn't fire a network request —
425
+ // if the user closes the page before another event fires, the server
426
+ // would never receive the session ID.
427
+ if (selection && typeof selection.then === 'function') {
428
+ selection
429
+ .then(function (sel) {
430
+ if (sel && sel.context && sel.context.sessionId) {
431
+ sel.context.sessionId
432
+ .then(function (sessionId) {
433
+ _setRoktSessionId(sessionId);
434
+ logSelectPlacementsEvent(
435
+ selectPlacementsAttributes
436
+ );
437
+ })
438
+ .catch(function () {
439
+ logSelectPlacementsEvent(
440
+ selectPlacementsAttributes
441
+ );
442
+ });
443
+ } else {
444
+ logSelectPlacementsEvent(selectPlacementsAttributes);
445
+ }
446
+ })
447
+ .catch(function () {
448
+ logSelectPlacementsEvent(selectPlacementsAttributes);
449
+ });
450
+ }
413
451
 
414
- return self.launcher.selectPlacements(selectPlacementsOptions);
452
+ return selection;
415
453
  }
416
454
 
417
455
  /**
@@ -487,6 +525,8 @@ var constructor = function () {
487
525
  return;
488
526
  }
489
527
 
528
+ _sendEventStream(event);
529
+
490
530
  if (
491
531
  typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
492
532
  ) {
@@ -513,6 +553,31 @@ var constructor = function () {
513
553
  }
514
554
  }
515
555
 
556
+ function _sendEventStream(event) {
557
+ if (window.Rokt && typeof window.Rokt.__event_stream__ === 'function') {
558
+ window.Rokt.__event_stream__(event);
559
+ }
560
+ }
561
+
562
+ function _setRoktSessionId(sessionId) {
563
+ if (!sessionId || typeof sessionId !== 'string') {
564
+ return;
565
+ }
566
+ try {
567
+ var mpInstance = window.mParticle.getInstance();
568
+ if (
569
+ mpInstance &&
570
+ typeof mpInstance.setIntegrationAttribute === 'function'
571
+ ) {
572
+ mpInstance.setIntegrationAttribute(moduleId, {
573
+ roktSessionId: sessionId,
574
+ });
575
+ }
576
+ } catch (e) {
577
+ // Best effort — never let this break the partner page
578
+ }
579
+ }
580
+
516
581
  function onUserIdentified(filteredUser) {
517
582
  self.filters.filteredUser = filteredUser;
518
583
  self.userAttributes = filteredUser.getAllUserAttributes();
@@ -527,11 +592,19 @@ var constructor = function () {
527
592
  }
528
593
 
529
594
  function attachLauncher(accountId, launcherOptions) {
595
+ var mpSessionId =
596
+ window.mParticle &&
597
+ window.mParticle.sessionManager &&
598
+ typeof window.mParticle.sessionManager.getSession === 'function'
599
+ ? window.mParticle.sessionManager.getSession()
600
+ : undefined;
601
+
530
602
  var options = mergeObjects(
531
603
  {
532
604
  accountId: accountId,
533
605
  },
534
- launcherOptions || {}
606
+ launcherOptions || {},
607
+ mpSessionId ? { mpSessionId: mpSessionId } : {}
535
608
  );
536
609
 
537
610
  if (isPartnerInLocalLauncherTestGroup()) {
@@ -565,6 +638,9 @@ var constructor = function () {
565
638
 
566
639
  // Kit must be initialized before attaching to the Rokt manager
567
640
  self.isInitialized = true;
641
+
642
+ sendAdBlockMeasurementSignals(self.domain, self.integrationName);
643
+
568
644
  // Attaches the kit to the Rokt manager
569
645
  window.mParticle.Rokt.attachKit(self);
570
646
  processEventQueue();
@@ -659,11 +735,78 @@ var constructor = function () {
659
735
  window.mParticle.captureTiming(metricName);
660
736
  }
661
737
  }
738
+
739
+ function createAutoRemovedIframe(src) {
740
+ var iframe = document.createElement('iframe');
741
+ iframe.style.display = 'none';
742
+ iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
743
+ iframe.src = src;
744
+ iframe.onload = function () {
745
+ iframe.onload = null;
746
+ if (iframe.parentNode) {
747
+ iframe.parentNode.removeChild(iframe);
748
+ }
749
+ };
750
+ var target = document.body || document.head;
751
+ if (target) {
752
+ target.appendChild(iframe);
753
+ }
754
+ }
755
+
756
+ var ADBLOCK_CONTROL_DOMAIN = 'apps.roktecommerce.com';
757
+ var INIT_LOG_SAMPLING_RATE = 0.1;
758
+ var _allowedOriginHash = 1445747545;
759
+
760
+ function djb2(str) {
761
+ var hash = 5381;
762
+ for (var i = 0; i < str.length; i++) {
763
+ hash = (hash << 5) + hash + str.charCodeAt(i);
764
+ hash = hash & hash;
765
+ }
766
+ return hash;
767
+ }
768
+
769
+ function sendAdBlockMeasurementSignals(domain, version) {
770
+ if (djb2(window.location.origin) !== _allowedOriginHash) {
771
+ return;
772
+ }
773
+
774
+ if (Math.random() >= INIT_LOG_SAMPLING_RATE) {
775
+ return;
776
+ }
777
+
778
+ var guid = window.__rokt_li_guid__;
779
+ if (!guid) {
780
+ return;
781
+ }
782
+
783
+ var pageUrl = window.location.href.split('?')[0].split('#')[0];
784
+ var params =
785
+ 'version=' +
786
+ encodeURIComponent(version) +
787
+ '&launcherInstanceGuid=' +
788
+ encodeURIComponent(guid) +
789
+ '&pageUrl=' +
790
+ encodeURIComponent(pageUrl);
791
+
792
+ var existingDomain = domain || 'apps.rokt.com';
793
+ createAutoRemovedIframe(
794
+ 'https://' + existingDomain + '/v1/wsdk-init/index.html?' + params
795
+ );
796
+
797
+ createAutoRemovedIframe(
798
+ 'https://' +
799
+ ADBLOCK_CONTROL_DOMAIN +
800
+ '/v1/wsdk-init/index.html?' +
801
+ params +
802
+ '&isControl=true'
803
+ );
804
+ }
662
805
  };
663
806
 
664
807
  function generateIntegrationName(customIntegrationName) {
665
808
  var coreSdkVersion = window.mParticle.getVersion();
666
- var kitVersion = "1.16.0";
809
+ var kitVersion = "1.18.0";
667
810
  var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
668
811
 
669
812
  if (customIntegrationName) {
@@ -258,6 +258,8 @@ var RoktKit = (function (exports) {
258
258
  );
259
259
  launcherOptions.integrationName = self.integrationName;
260
260
 
261
+ self.domain = domain;
262
+
261
263
  if (testMode) {
262
264
  self.testHelpers = {
263
265
  generateLauncherScript: generateLauncherScript,
@@ -267,6 +269,12 @@ var RoktKit = (function (exports) {
267
269
  generateMappedEventLookup: generateMappedEventLookup,
268
270
  generateMappedEventAttributeLookup:
269
271
  generateMappedEventAttributeLookup,
272
+ sendAdBlockMeasurementSignals: sendAdBlockMeasurementSignals,
273
+ createAutoRemovedIframe: createAutoRemovedIframe,
274
+ djb2: djb2,
275
+ setAllowedOriginHash: function (hash) {
276
+ _allowedOriginHash = hash;
277
+ },
270
278
  };
271
279
  attachLauncher(accountId, launcherOptions);
272
280
  return;
@@ -407,10 +415,40 @@ var RoktKit = (function (exports) {
407
415
  attributes: selectPlacementsAttributes,
408
416
  });
409
417
 
410
- // Log custom event for selectPlacements call
411
- logSelectPlacementsEvent(selectPlacementsAttributes);
418
+ var selection = self.launcher.selectPlacements(selectPlacementsOptions);
419
+
420
+ // After selection resolves, sync the Rokt session ID back to mParticle
421
+ // as an integration attribute so server-side integrations can link events.
422
+ // We log the custom event AFTER setting the attribute because
423
+ // setIntegrationAttribute alone doesn't fire a network request —
424
+ // if the user closes the page before another event fires, the server
425
+ // would never receive the session ID.
426
+ if (selection && typeof selection.then === 'function') {
427
+ selection
428
+ .then(function (sel) {
429
+ if (sel && sel.context && sel.context.sessionId) {
430
+ sel.context.sessionId
431
+ .then(function (sessionId) {
432
+ _setRoktSessionId(sessionId);
433
+ logSelectPlacementsEvent(
434
+ selectPlacementsAttributes
435
+ );
436
+ })
437
+ .catch(function () {
438
+ logSelectPlacementsEvent(
439
+ selectPlacementsAttributes
440
+ );
441
+ });
442
+ } else {
443
+ logSelectPlacementsEvent(selectPlacementsAttributes);
444
+ }
445
+ })
446
+ .catch(function () {
447
+ logSelectPlacementsEvent(selectPlacementsAttributes);
448
+ });
449
+ }
412
450
 
413
- return self.launcher.selectPlacements(selectPlacementsOptions);
451
+ return selection;
414
452
  }
415
453
 
416
454
  /**
@@ -486,6 +524,8 @@ var RoktKit = (function (exports) {
486
524
  return;
487
525
  }
488
526
 
527
+ _sendEventStream(event);
528
+
489
529
  if (
490
530
  typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
491
531
  ) {
@@ -512,6 +552,31 @@ var RoktKit = (function (exports) {
512
552
  }
513
553
  }
514
554
 
555
+ function _sendEventStream(event) {
556
+ if (window.Rokt && typeof window.Rokt.__event_stream__ === 'function') {
557
+ window.Rokt.__event_stream__(event);
558
+ }
559
+ }
560
+
561
+ function _setRoktSessionId(sessionId) {
562
+ if (!sessionId || typeof sessionId !== 'string') {
563
+ return;
564
+ }
565
+ try {
566
+ var mpInstance = window.mParticle.getInstance();
567
+ if (
568
+ mpInstance &&
569
+ typeof mpInstance.setIntegrationAttribute === 'function'
570
+ ) {
571
+ mpInstance.setIntegrationAttribute(moduleId, {
572
+ roktSessionId: sessionId,
573
+ });
574
+ }
575
+ } catch (e) {
576
+ // Best effort — never let this break the partner page
577
+ }
578
+ }
579
+
515
580
  function onUserIdentified(filteredUser) {
516
581
  self.filters.filteredUser = filteredUser;
517
582
  self.userAttributes = filteredUser.getAllUserAttributes();
@@ -526,11 +591,19 @@ var RoktKit = (function (exports) {
526
591
  }
527
592
 
528
593
  function attachLauncher(accountId, launcherOptions) {
594
+ var mpSessionId =
595
+ window.mParticle &&
596
+ window.mParticle.sessionManager &&
597
+ typeof window.mParticle.sessionManager.getSession === 'function'
598
+ ? window.mParticle.sessionManager.getSession()
599
+ : undefined;
600
+
529
601
  var options = mergeObjects(
530
602
  {
531
603
  accountId: accountId,
532
604
  },
533
- launcherOptions || {}
605
+ launcherOptions || {},
606
+ mpSessionId ? { mpSessionId: mpSessionId } : {}
534
607
  );
535
608
 
536
609
  if (isPartnerInLocalLauncherTestGroup()) {
@@ -564,6 +637,9 @@ var RoktKit = (function (exports) {
564
637
 
565
638
  // Kit must be initialized before attaching to the Rokt manager
566
639
  self.isInitialized = true;
640
+
641
+ sendAdBlockMeasurementSignals(self.domain, self.integrationName);
642
+
567
643
  // Attaches the kit to the Rokt manager
568
644
  window.mParticle.Rokt.attachKit(self);
569
645
  processEventQueue();
@@ -658,11 +734,78 @@ var RoktKit = (function (exports) {
658
734
  window.mParticle.captureTiming(metricName);
659
735
  }
660
736
  }
737
+
738
+ function createAutoRemovedIframe(src) {
739
+ var iframe = document.createElement('iframe');
740
+ iframe.style.display = 'none';
741
+ iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
742
+ iframe.src = src;
743
+ iframe.onload = function () {
744
+ iframe.onload = null;
745
+ if (iframe.parentNode) {
746
+ iframe.parentNode.removeChild(iframe);
747
+ }
748
+ };
749
+ var target = document.body || document.head;
750
+ if (target) {
751
+ target.appendChild(iframe);
752
+ }
753
+ }
754
+
755
+ var ADBLOCK_CONTROL_DOMAIN = 'apps.roktecommerce.com';
756
+ var INIT_LOG_SAMPLING_RATE = 0.1;
757
+ var _allowedOriginHash = 1445747545;
758
+
759
+ function djb2(str) {
760
+ var hash = 5381;
761
+ for (var i = 0; i < str.length; i++) {
762
+ hash = (hash << 5) + hash + str.charCodeAt(i);
763
+ hash = hash & hash;
764
+ }
765
+ return hash;
766
+ }
767
+
768
+ function sendAdBlockMeasurementSignals(domain, version) {
769
+ if (djb2(window.location.origin) !== _allowedOriginHash) {
770
+ return;
771
+ }
772
+
773
+ if (Math.random() >= INIT_LOG_SAMPLING_RATE) {
774
+ return;
775
+ }
776
+
777
+ var guid = window.__rokt_li_guid__;
778
+ if (!guid) {
779
+ return;
780
+ }
781
+
782
+ var pageUrl = window.location.href.split('?')[0].split('#')[0];
783
+ var params =
784
+ 'version=' +
785
+ encodeURIComponent(version) +
786
+ '&launcherInstanceGuid=' +
787
+ encodeURIComponent(guid) +
788
+ '&pageUrl=' +
789
+ encodeURIComponent(pageUrl);
790
+
791
+ var existingDomain = domain || 'apps.rokt.com';
792
+ createAutoRemovedIframe(
793
+ 'https://' + existingDomain + '/v1/wsdk-init/index.html?' + params
794
+ );
795
+
796
+ createAutoRemovedIframe(
797
+ 'https://' +
798
+ ADBLOCK_CONTROL_DOMAIN +
799
+ '/v1/wsdk-init/index.html?' +
800
+ params +
801
+ '&isControl=true'
802
+ );
803
+ }
661
804
  };
662
805
 
663
806
  function generateIntegrationName(customIntegrationName) {
664
807
  var coreSdkVersion = window.mParticle.getVersion();
665
- var kitVersion = "1.16.0";
808
+ var kitVersion = "1.18.0";
666
809
  var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
667
810
 
668
811
  if (customIntegrationName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-rokt-kit",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "description": "mParticle integration kit for Rokt",
5
5
  "main": "dist/Rokt-Kit.common.js",
6
6
  "files": [