Skip to content

feat: capture UTM params from page views and forward to selectPlacements - #129

Merged
alexs-mparticle merged 3 commits into
developmentfrom
feat/utm-param-capture
Aug 21, 2026
Merged

feat: capture UTM params from page views and forward to selectPlacements#129
alexs-mparticle merged 3 commits into
developmentfrom
feat/utm-param-capture

Conversation

@alexs-mparticle

@alexs-mparticle alexs-mparticle commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds captureUtmParams() to pageViewStorage.ts — reads the 5 standard UTM params (utm_source, utm_medium, utm_campaign, utm_term, utm_content) from window.location.search and stores them in localStorage under the mp-rokt-kit namespace (first-touch-wins)
  • Forwards captured UTMs to Rokt as page_view_attributes on every selectPlacements call; field is omitted entirely when no UTMs were seen this session
  • Clears stored UTMs on SESSION_END, consistent with how pageViews is cleared

Design decisions

  • First touch wins: UTMs are captured once per session and not overwritten, matching standard landing-page attribution behaviour
  • localStorage, not sessionStorage: session boundary is the mParticle session (cleared on SESSION_END), not the browser tab — consistent with existing page view storage
  • Kit-only: reads window.location.search directly; no core SDK changes required
  • page_view_attributes is a new contract: backend wiring is a follow-up; extra attributes are ignored by Rokt until then

Test plan

  • captureUtmParams stores present UTM keys on first call
  • Only stores keys that are present (partial set)
  • No-ops when URL has no UTM params
  • First touch wins — does not overwrite on subsequent calls
  • loadUtmParams returns null when nothing stored
  • clearUtmParams removes the field without affecting other namespace fields
  • Diagnostic logs emitted on capture success and write failure

@alexs-mparticle
alexs-mparticle changed the base branch from main to development August 20, 2026 20:41
Comment thread src/pageViewStorage.ts
}
loggingService?.log({
message: `Rokt Kit: Captured UTM params [${captured}]`,
code: 'UTM_CAPTURE_SUCCESS',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming this is just for the initial rollout verification and then we will remove?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I'll be removing these after the data has had time to soak.

Comment thread src/Rokt-Kit.ts Outdated
Comment thread src/Rokt-Kit.ts Outdated
@alexs-mparticle
alexs-mparticle merged commit e1f70d1 into development Aug 21, 2026
4 of 5 checks passed
github-actions Bot pushed a commit that referenced this pull request Aug 21, 2026
# [1.35.0](v1.34.1...v1.35.0) (2026-08-21)

### Features

* capture UTM params from page views and forward to selectPlacements ([#129](#129)) ([e1f70d1](e1f70d1))
@mparticle-automation

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.35.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants