feat: capture page title and canonical URL in page view events - #112
Open
alexs-mparticle wants to merge 1 commit into
Open
feat: capture page title and canonical URL in page view events#112alexs-mparticle wants to merge 1 commit into
alexs-mparticle wants to merge 1 commit into
Conversation
Add optional pageTitle and canonicalUrl fields to captured page-view records so they surface in the page_events attribute sent to selectPlacements. - pageTitle is read from document.title - canonicalUrl is read from <link rel="canonical"> and sanitized through the same helper as pageUrl (query string stripped, hash fragment retained) Both fields are omitted when unavailable, matching the existing activeTimeOnSite handling.
alexs-mparticle
force-pushed
the
feat/page-view-title-canonical
branch
from
August 7, 2026 02:29
313de18 to
8997f87
Compare
rmi22186
reviewed
Aug 7, 2026
| timestamp: event.Timestamp, | ||
| }; | ||
|
|
||
| const pageTitle = document.title; |
Collaborator
There was a problem hiding this comment.
nit: Should this come from event since it shoudl be there already in the edge case small chance it's different from document.title?
Suggested change
| const pageTitle = document.title; | |
| const pageTitle = event.EventAttributes?.title || document.title; |
rmi22186
requested changes
Aug 7, 2026
rmi22186
left a comment
Collaborator
There was a problem hiding this comment.
Adding the pageTitle and canonicalUrl will only make that error we were seeing for quota limit in setting local storage worse. I wouldn't merge this without including the fix for resolving reducing the rate we see the error.
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
Extends the auto page-view capture feature (added in #109) to also record the page title and canonical URL on each page-view event.
Both fields are nested inside each
page_eventsrecord — alongside the existingpageUrl,sourceMessageId,timestamp, etc. — and surface in thepage_eventsattribute sent toselectPlacements. No new top-level attributes are introduced.Changes
pageTitleandcanonicalUrlto thePageEventinterface.capturePageView()readsdocument.titleand<link rel="canonical">.readCanonicalUrl()helper resolves the canonical href to absolute and sanitizes it through the samesanitizeUrl()used forpageUrl(query string stripped, hash fragment retained) — keeping canonical handling consistent withpageUrl.buildPageEvents()carries both fields through to the transmitted payload.activeTimeOnSiteis handled.Example
page_eventsrecord{ "pageUrl": "https://example.com/checkout#section", "sourceMessageId": "...", "timestamp": 1712345678000, "pageTitle": "Checkout", "canonicalUrl": "https://example.com/canonical#section", "activeTimeOnSite": 4200 }Tests
Three new tests: captures title + canonical, omits both when absent, and carries them through
selectPlacements. Full suite: 231/231 passing. Lint and build clean.Note on sanitization
canonicalUrlreusessanitizeUrl()for consistency withpageUrl, which strips the query string but retains the hash fragment (per the existingpageUrlbehavior/tests). If we'd prefer to strip the fragment from canonical too, that's a small follow-up but would diverge frompageUrlhandling.🤖 Generated with Claude Code