feat: cap page-view storage by byte budget instead of fixed count - #114
Merged
Conversation
Replace the fixed PAGE_VIEWS_MAX_COUNT = 25 cap on persisted page views with a byte budget (PAGE_VIEWS_MAX_BYTES = 100 * 1024, measured as JSON string length). writePageViewsStorage now trims oldest-first to the budget so the kit stays a polite tenant in the shared origin localStorage regardless of free space, and wraps the write in a QuotaExceededError evict-and-retry loop that always keeps at least the newest record. If the write still fails, the error propagates to the existing capturePageView catch and reports PAGE_VIEW_CAPTURE_FAILED at INFO, so nothing is thrown into the host page. The selectPlacements send path (buildPageEvents) is intentionally unchanged; it is now naturally bounded by the storage budget.
alexs-mparticle
force-pushed
the
feat/page-view-byte-budget
branch
from
August 12, 2026 18:36
cc7f462 to
f9557ea
Compare
alexs-mparticle
commented
Aug 12, 2026
alexs-mparticle
force-pushed
the
feat/page-view-byte-budget
branch
from
August 12, 2026 20:13
88aa62b to
023be7d
Compare
Move page-view persistence (load/write/clear + legacy-key migration) out of Rokt-Kit.ts into src/pageViewStorage.ts, and generalize the byte-budget eviction loop into a reusable storage helper. Keeps Rokt-Kit.ts focused on kit lifecycle. Also drop the hand-maintained file manifest from AGENTS.md — it drifts as modules are added; the source tree is the source of truth.
alexs-mparticle
force-pushed
the
feat/page-view-byte-budget
branch
from
August 12, 2026 20:53
023be7d to
2c6a42d
Compare
Unify the duplicated isObject/isPlainObject guards and move isString and isEmpty into src/utils.ts with co-located tests. Share an evictOldest helper across the budget-shrink and write-retry loops in writeNamespacedFieldWithinBudget.
alexs-mparticle
marked this pull request as ready for review
August 13, 2026 14:00
Arrays are typeof 'object', so they were already handled by the object branch; the Array.isArray check was dead code.
rmi22186
reviewed
Aug 13, 2026
rmi22186
reviewed
Aug 13, 2026
rmi22186
approved these changes
Aug 13, 2026
crisryantan
approved these changes
Aug 13, 2026
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.
What & why
Persisted page-view history was capped at a fixed 25 records. This replaces that cap with a byte budget (~100 KB): we keep more history when there's room to spare — which improves targeting — while staying a considerate tenant in the customer's shared-origin
localStorageinstead of assuming the space is ours.Behaviour
The
selectPlacementssend path is unchanged — it's now naturally bounded by what's in storage.Tests
Byte-budget eviction (oldest-first, stays under budget), newest always retained, quota-exceeded → evict-and-retry, and the give-up path logs at INFO without throwing. Full suite, lint, and build pass.