feat(rokt): expose terminate on the window.mParticle.Rokt interface - #1328
feat(rokt): expose terminate on the window.mParticle.Rokt interface#1328jamesnrokt wants to merge 1 commit into
Conversation
PR SummaryLow Risk Overview
Reviewed by Cursor Bugbot for commit b41570f. Bugbot is set up for automated code reviews on this repo. Configure here. |
82147f8 to
522f21e
Compare
Partners tearing down placements had no supported teardown path and were falling back to the undocumented `window.Rokt.currentLauncher?.terminate()`. `terminate` is already stubbed in the Rokt snippet, so a snippet-loaded page could queue the call and then fail to dispatch it. RoktManager.terminate() delegates to the kit, which forwards to the Rokt launcher. The kit method is optional on IRoktKit and guarded with isFunction because the Rokt Kit releases independently — a kit published before this change will not implement it. Unlike the other proxied methods a pre-ready call is not queued. Replaying a teardown against a launcher created later would tear down placements the caller never asked to remove; with no launcher there is nothing to terminate, so the call resolves as a no-op. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
522f21e to
b41570f
Compare
|
There was a problem hiding this comment.
This LGTM. @mattbodle's comment over at mparticle-integrations/mparticle-javascript-integration-rokt#122 shouldn't affect the implementation here, though I'm not 100% clear on the use case of creating a new launcher right after terminating. That seems unlkely?
Edit: Oh I see, for SPAs, so a customer may go back and make another purchase, right?



Summary
Adds
RoktManager.terminate(), exposingwindow.mParticle.Rokt.terminate()as a supported teardown path for partners who cannot simply destroy the container element — SPA route changes and confirmation pages in particular.Today partners reach for the undocumented
window.Rokt.currentLauncher?.terminate(). This routes the same call through the documented interface.Pairs with mparticle-integrations/mparticle-javascript-integration-rokt#122, which adds the
terminate()the manager delegates to. That PR should merge and release first — until a kit carrying it is on the page, this method logs that the attached kit version does not support terminate.Changes
RoktManager.terminate(): Promise<void>— delegates tothis.kit.terminate(), which forwards to the Rokt launcher.IRoktKit.terminateadded as optional, guarded at the call site withisFunction. The Rokt Kit releases on its own cadence, so a kit published before this change genuinely will not implement it — version skew is real rather than theoretical.IRoktLauncheris untouched: the manager only ever calls through the kit, and the kit owns the launcher-facing type.Behaviour
awaitskit.terminate()terminatekit.terminate()rejectsterminate()never rejects — teardown should not be something callers have to defend against.A pre-ready call is not queued
Every other proxied method uses
deferredCallwhen the kit isn't ready.terminatedeliberately does not. Replaying a teardown against a launcher created later would silently tear down placements the caller never asked to remove; with no launcher there is nothing to terminate, so the call resolves as a no-op instead. This asymmetry is called out in the method's doc comment and pinned by tests.Also fixes a latent snippet bug
terminateis already in the snippet'sroktMethodsstub list (snippet.js), so a snippet-loaded page could queueRokt.terminate()before init. At flush timeprocessPreloadedItemhit an undefined method, threw, andprocessReadyQueueloggedUnable to compute proper mParticle function. That path now dispatches correctly.getVersionhas the same latent gap — it is in the snippet stub list but has noRoktManagerimplementation. Left out of scope here; happy to add it in a follow-up if wanted.Not included
kits/rokt/in this repo is a stale vendored snapshot of the Rokt kit (missingstorage.ts,utils.ts,pageViewStorage.ts) and is not loaded by any build or test target, so it was intentionally left untouched. The live kit change is in the companion PR.Testing
npm run lint— passnpm run test:jest— 632/632 across 26 suites7 new
#terminatecases intest/jest/roktManager.spec.tscover each row of the behaviour table above, plus a case asserting the manager stays ready so repeat calls keep reaching the kit. The suite fails to compile againstdevelopmentwithout the source change.🤖 Generated with Claude Code