feat(rokt): send the current mParticle session id as a selectPlacements attribute - #1324
feat(rokt): send the current mParticle session id as a selectPlacements attribute#1324jamesnrokt wants to merge 5 commits into
Conversation
…ts attribute The kit read the mParticle session id once, when creating the launcher, and passed it through as the mpSessionId launcher option, which is no longer used. Send it as the mparticle_session_id attribute on each selectPlacements call instead. Reading it per call means a session that has rotated — on inactivity timeout, when another tab starts a new session, or after an explicit endSession() — is reflected on the next call, rather than being pinned to whatever was current when the launcher was created. Prefer SessionManager.getSessionId() over the deprecated getSession(), falling back only for core SDK versions that predate it. getSession() logs a deprecation warning and reports MP_DEPRECATED_METHOD_USAGE, so every launcher creation was emitting one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Calls mp() once instead of twice and reads more directly. No behaviour change: mp() returns window.mParticle, which may be undefined, and the following guard handles that case either way. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
PR SummaryMedium Risk Overview
Tests now assert the attribute on placement payloads (not on launcher options), cover rotation between calls and missing session APIs, and pin Reviewed by Cursor Bugbot for commit 3125de4. Bugbot is set up for automated code reviews on this repo. Configure here. |
…Function util The kit requires @mparticle/web-sdk ^2.62.0 and getSessionId() has shipped since v2.23.3, so the getSession() fallback was unreachable for every supported core version. Removing it also removes the last caller of a deprecated method. Adds an isFunction helper and uses it for all five typeof-function checks in the kit, rather than leaving the new one inconsistent with the rest. The standalone kit repo keeps this in src/utils.ts; this copy has no utils module, so it sits with the existing module-level helpers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d11c9e1. Configure here.
This copy has no utils module or utils spec, so isFunction is exposed through testHelpers alongside the other module-level helpers and covered in the kit spec. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…er facade readMpSessionId called mParticle.sessionManager.getSessionId(), which does not exist. The public facade exposes only getSession(); getSessionId() lives on the internal _SessionManager and has never been re-exported. Verified against the published bundles for core 2.62.0, 2.75.1 and 2.78.0 — all identical. isFunction(undefined) was therefore always false, readMpSessionId always returned undefined, and mparticle_session_id was never added to the selectPlacements attributes. Confirmed in production against the standalone kit 1.33.0 on core 2.78.0, where the attribute was absent from all 79,987 wsdk events in a sampled window. Read getSessionId if the facade exposes it and fall back to getSession, so this works on every supported core and picks up the non-deprecated name if one is ever added. An earlier revision of this branch dropped that fallback on the assumption that getSessionId() was public from v2.23.3; that holds for the internal _SessionManager but not for the public facade. The public getSession() is not deprecated and emits no warning: it calls _SessionManager.getSessionId() directly, bypassing the deprecated internal _SessionManager.getSession(). Widen the interface back to accept both accessors — it had been narrowed to an optional getSessionId, so TypeScript could not catch the absence. Move the test fixtures back to getSession so the suite exercises the real facade shape, and add coverage for the getSession-only shape, getSessionId preference, and the neither-accessor case. Mirrors mparticle-integrations/mparticle-javascript-integration-rokt#117. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|




Summary
Applies the same change as mparticle-integrations/mparticle-javascript-integration-rokt#116 to the in-repo copy of the Rokt kit, so the two do not drift while the monorepo migration is in progress.
The kit read the mParticle session id once, when creating the launcher, and passed it through as the
mpSessionIdlauncher option. That option is no longer used, and reading the value at launcher-creation time meant it went stale for the life of the page: mParticle mints a new session id on inactivity timeout (sessionTimeout, 30 minutes by default), when another tab starts a new session, and after an explicitendSession()/startNewSession(). None of that reached the launcher.This PR:
mparticle_session_idattribute on eachselectPlacementscall. Because it is read per call, a rotated session is reflected on the next call.mpSessionIdlauncher option fromattachLauncher.readMpSessionId(), which readsSessionManager.getSessionId()if the facade exposes it and otherwise falls back togetSession().Review follow-ups applied:
Reinstated the
getSession()fallback. An earlier revision dropped it on the assumption thatgetSessionId()was available from corev2.23.3; that is true of the internal_SessionManagerbut not of the publicmParticle.sessionManagerfacade, which exposes onlygetSession()in every published core through2.78.0:Dropping the fallback made the attribute silently absent —
isFunction(undefined)isfalse, soreadMpSessionId()always returnedundefined. Confirmed in production against the standalone kit1.33.0on core2.78.0, where the attribute was absent from all 79,987wsdkevents in a sampled window. The publicgetSession()is not deprecated and emits no warning: it calls_SessionManager.getSessionId()directly, bypassing the deprecated internal_SessionManager.getSession(). Only the internal method carries@deprecatedandlogDeprecatedMethodUsage.Widened the
sessionManagerinterface back to accept both accessors. It had been narrowed to an optionalgetSessionId?(), so TypeScript could not catch the absence.Added an
isFunctionhelper and used it for all fivetypeof x === 'function'checks in the kit rather than leaving the new one inconsistent with the rest.Testing Plan
kits/rokt: 237/237 tests pass;vite buildclean.New unit tests cover: the session id current at the time of each call (asserted across a rotation between two calls), the attribute being omitted when
sessionManageris unavailable, a facade exposing onlygetSession(the real shape) yielding the attribute,getSessionIdbeing preferred when both are present, the attribute being omitted when neither accessor exists, andcreateLauncherno longer receivingmpSessionId.35 existing full-payload
toEqualassertions were updated, since the attribute is present on every call. The#selectPlacementsbeforeEachnow pins a knownsessionManager; previously these tests depended on an earlier test deletingwindow.mParticle.sessionManagerwithout restoring it, which made results order-dependent.Test fixtures in
test/vitest.setup.tsandtests.spec.tsusegetSession, matching the real public facade. An earlier revision moved them togetSessionId, which is why the suite went green against a facade that does not exist.kits/rokt/distis intentionally not included. Note this copy has nosrc/utils.ts, soisFunctionsits with the existing module-level helpers rather than in a utils module.kits/rokthas 7,771 pre-existingprettier/prettierlint errors on a pristine tree (an indentation-width mismatch across all four files). This PR does not change that count materially and does not attempt to reformat the kit.Additional testing worth doing: confirm on a long-lived page that a session which times out is reflected on the next
selectPlacementscall, and that the offers request body carriesattributes.mparticle_session_id.Note for reviewers running tests locally:
kits/roktuses vitest 4, which needs Node 22. On Node 20 it fails withbad option: --no-experimental-webstorage.