@mparticle/web-rokt-kit 1.17.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.
@@ -416,10 +416,40 @@ var constructor = function () {
416
416
  attributes: selectPlacementsAttributes,
417
417
  });
418
418
 
419
- // Log custom event for selectPlacements call
420
- 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
+ }
421
451
 
422
- return self.launcher.selectPlacements(selectPlacementsOptions);
452
+ return selection;
423
453
  }
424
454
 
425
455
  /**
@@ -529,6 +559,25 @@ var constructor = function () {
529
559
  }
530
560
  }
531
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
+
532
581
  function onUserIdentified(filteredUser) {
533
582
  self.filters.filteredUser = filteredUser;
534
583
  self.userAttributes = filteredUser.getAllUserAttributes();
@@ -543,11 +592,19 @@ var constructor = function () {
543
592
  }
544
593
 
545
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
+
546
602
  var options = mergeObjects(
547
603
  {
548
604
  accountId: accountId,
549
605
  },
550
- launcherOptions || {}
606
+ launcherOptions || {},
607
+ mpSessionId ? { mpSessionId: mpSessionId } : {}
551
608
  );
552
609
 
553
610
  if (isPartnerInLocalLauncherTestGroup()) {
@@ -749,7 +806,7 @@ var constructor = function () {
749
806
 
750
807
  function generateIntegrationName(customIntegrationName) {
751
808
  var coreSdkVersion = window.mParticle.getVersion();
752
- var kitVersion = "1.17.0";
809
+ var kitVersion = "1.18.0";
753
810
  var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
754
811
 
755
812
  if (customIntegrationName) {
@@ -415,10 +415,40 @@ var RoktKit = (function (exports) {
415
415
  attributes: selectPlacementsAttributes,
416
416
  });
417
417
 
418
- // Log custom event for selectPlacements call
419
- 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
+ }
420
450
 
421
- return self.launcher.selectPlacements(selectPlacementsOptions);
451
+ return selection;
422
452
  }
423
453
 
424
454
  /**
@@ -528,6 +558,25 @@ var RoktKit = (function (exports) {
528
558
  }
529
559
  }
530
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
+
531
580
  function onUserIdentified(filteredUser) {
532
581
  self.filters.filteredUser = filteredUser;
533
582
  self.userAttributes = filteredUser.getAllUserAttributes();
@@ -542,11 +591,19 @@ var RoktKit = (function (exports) {
542
591
  }
543
592
 
544
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
+
545
601
  var options = mergeObjects(
546
602
  {
547
603
  accountId: accountId,
548
604
  },
549
- launcherOptions || {}
605
+ launcherOptions || {},
606
+ mpSessionId ? { mpSessionId: mpSessionId } : {}
550
607
  );
551
608
 
552
609
  if (isPartnerInLocalLauncherTestGroup()) {
@@ -748,7 +805,7 @@ var RoktKit = (function (exports) {
748
805
 
749
806
  function generateIntegrationName(customIntegrationName) {
750
807
  var coreSdkVersion = window.mParticle.getVersion();
751
- var kitVersion = "1.17.0";
808
+ var kitVersion = "1.18.0";
752
809
  var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
753
810
 
754
811
  if (customIntegrationName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-rokt-kit",
3
- "version": "1.17.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": [