feat: capture page views and surface as page_events in selectPlacements - #107
Closed
alexs-mparticle wants to merge 11 commits into
Closed
feat: capture page views and surface as page_events in selectPlacements#107alexs-mparticle wants to merge 11 commits into
alexs-mparticle wants to merge 11 commits into
Conversation
…eventAttributes per page view
…ents Derive a flat page_events array from stored page views at selectPlacements time. Each view's eventAttributes are exploded into attr_-namespaced keys; the title attribute is surfaced as page_name and EventName as event_name. The raw nested mpPageViews store is stripped so only the flattened copy is sent. Relax returnLocalSessionAttributes to no longer require a placement mapping. Restore the isKitReady guard in process() and remove debug logging.
Compute a timeOnPage field for each page_events entry at read time in buildPageEvents as the diff of consecutive activeTimeOnSite values — the active time a page was viewed before the next page view was logged. Emitted only when it is a genuine, non-negative number; omitted for the still-open last entry, negative diffs (clock skew, reset, out-of-order), and non-numeric activeTimeOnSite. Nothing new is persisted; StoredPageView is unchanged.
…iews # Conflicts: # dist/Rokt-Kit.common.js # dist/Rokt-Kit.common.js.map # dist/Rokt-Kit.esm.js.map # dist/Rokt-Kit.iife.js # dist/Rokt-Kit.iife.js.map
alexs-mparticle
commented
Jul 31, 2026
alexs-mparticle
commented
Jul 31, 2026
|
|
||
| private buildPageEvents(pageViews: StoredPageView[]): Record<string, unknown>[] { | ||
| return pageViews.map((pv, i) => { | ||
| const flat: Record<string, unknown> = {}; |
Collaborator
Author
There was a problem hiding this comment.
We should create an explicit type here for safety and it should include timeOnPage as optional.
alexs-mparticle
commented
Jul 31, 2026
| EventName: 'Browse', | ||
| EventCategory: EventType.Unknown, | ||
| EventDataType: MessageType.PageView, | ||
| EventDataType: MessageType.PageEvent, |
Collaborator
Author
There was a problem hiding this comment.
We shouldn't be changing these.
Add an explicit PageEvent return type for buildPageEvents (with timeOnPage optional) instead of Record<string, unknown>[]. Revert the legacy #processEvent attribute-mapping tests back to MessageType.PageView and strip the captured mpPageViews list from their exact-shape assertions via a helper, since processing a PageView now legitimately captures a page-view record.
Collaborator
Author
|
Superseded by #109 — branch renamed to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Records page-view events as they are logged, persists them durably to the Rokt local-session-attribute store, and surfaces them as a flat
page_eventsarray on the nextselectPlacementscall as targeting context.What's included
process): page views (EventDataType === 3) are appended to a persistedmpPageViewslist (max 25, oldest evicted), guarded so a malformed event can never throw out of the forwarder. CapturesEventName, fullpageUrl(window.location.href),SourceMessageId,timestamp,ActiveTimeOnSite, andEventAttributes.buildPageEvents): each stored view is flattened into apage_eventsentry —event_name,page_name(from thetitleattribute), andeventAttributesexploded intoattr_-namespaced keys so they can't clobber base fields. The raw nestedmpPageViewsstore is stripped so only the flat copy is sent.timeOnPage— the active time a page was viewed before the next page view was logged (diff of consecutiveactiveTimeOnSite). Emitted only when it's a genuine non-negative number; omitted for the still-open last entry, negative diffs, and non-numeric values. Derived at read time — nothing extra persisted.returnLocalSessionAttributes()so the store flows through whenever it's available and populated.Security note (per Rokt secure-coding policy)
pageUrl(full URL incl. query/fragment) andeventAttributesare stored verbatim and may contain PII; they are persisted to browser storage and sent to Rokt. Full-URL was an explicit product choice;sanitizeUrl()isolates the boundary so query/fragment stripping is a one-line change later. The SDK does not run kit user-attribute filters over page-viewEventAttributes. Design doc records this in full.Testing
mParticle.getInstance()._Store.getLocalSessionAttributes()in the dev console.Expected result:
Verify the expected payload when making a select placements call: