Skip to content

Respect the configured namespace for manual pageviews - #110

Merged
adriaandotcom merged 3 commits into
v12from
fix/v12-namespaced-pageviews
Oct 15, 2026
Merged

adriaandotcom merged 3 commits into
v12from
fix/v12-namespaced-pageviews

Conversation

@simple-analytics-ai

@simple-analytics-ai simple-analytics-ai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Summary

Closes #107

Manual page views were always exposed as window.sa_pageview, ignoring data-namespace. On a page with two trackers the second script overwrote the first script's manual function, so manual page views were sent to the other tracker's hostname.

src/default.js now assigns the manual page view function to window[namespace + "_pageview"], so a namespaced install gets ba_pageview and a second tracker can no longer take over the first one's function. The legacy sa_pageview global is kept as an alias, but only when it is still free when the script loads, so existing namespaced manual installations that call sa_pageview keep working while a default-namespace script on the same page always owns sa_pageview regardless of load order.

Rebuilt dist/ is included, as required for this repository. Current v12 was merged into this branch; the merge touched only generated distributions, which were rebuilt from source.

Changes:

  • Respect the configured namespace for manual pageviews - Requested in item 3: keep namespaced trackers from replacing another tracker manual pageview function. Reuse existing namespace and pageview text variables to reduce minified byte...
  • Retain the free legacy manual pageview alias - Address review of item 3: older namespaced installations still call sa_pageview. Keep that alias when free, without overwriting another tracker, and cover both function names in t...
  • Merge v12 into fix/v12-namespaced-pageviews - Requested: merge current v12 into PR Respect the configured namespace for manual pageviews #110. Preserve the namespaced manual pageview and legacy alias behavior, and rebuild conflicting distributions.

Security implications

Has security impact - described as: manual page views from a namespaced tracker could previously be routed to another tracker's configured hostname when several trackers coexisted on one page, which sent visitor page view data to the wrong destination.

Testing

Run by Claude on the merge commit 492f671, with Node.js 24.21.0 and pnpm 11.17.0 as declared in package.json:

  • pnpm install --frozen-lockfile — succeeded.
  • pnpm run build — succeeded, and git status is clean afterwards, so every committed file under dist/ reproduces exactly from the current source.
  • pnpm run test:unit — 41 passing, 0 failing, including exposes the pageview function under its configured namespace and keeps a default manual tracker separate from an automatic namespaced tracker.
  • Verified in the built output that dist/v12/app.js emits m[ct+"_"+b]=Yt; var Zt="sa_"+b; m[Zt]||(m[Zt]=Yt), so the namespaced global is always assigned and the sa_pageview alias is only taken when free. compile.js sets the build-time default namespace to sa for every target, including the custom and Cloudflare builds.

BrowserStack was not run locally; the full matrix is left to CI.

Checklist

  • Linked to an issue
  • Tested
  • Asked for a review

Requested in item 3: keep namespaced trackers from replacing another tracker manual pageview function. Reuse existing namespace and pageview text variables to reduce minified bytes.

Refs #107
Comment thread src/default.js
Comment thread test/unit/pageview.test.js Outdated
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Claude review checkpoint

Reviewed commit 492f67174b9b1e378b674c3ca7d8c250eb296371. This is used to keep later automated reviews focused on changes Claude has not checked yet.

@github-actions github-actions Bot added the change: needs review Changes affecting security, data protection, or system stability. label Oct 15, 2026
@github-actions

Copy link
Copy Markdown

SDLC label: change: needs review because Renaming the manual pageview global to a namespaced name removes the hardcoded window.sa_pageview that v10 and v11 shipped, which silently stops manual pageview collection for existing data-namespace installs once latest.js rolls to v12

Address review of item 3: older namespaced installations still call sa_pageview. Keep that alias when free, without overwriting another tracker, and cover both function names in the regression test.

Refs #107
@github-actions

Copy link
Copy Markdown

Documentation update

_docs/55_events/01_introduction.md

Location: ## The variable sa_event is already used — directly after the paragraph starting with "Do note that the namespace will also change other functions as well."

Copy and paste this into the documentation repository:

For backwards compatibility the script also keeps `sa_pageview` available as an alias for `ba_pageview`, but only when `window.sa_pageview` is still unused at the moment the script loads. Existing manual page view code that calls `sa_pageview` therefore keeps working after you add a namespace. When you run a second script without a namespace on the same page, that script owns `sa_pageview`, so call `ba_pageview` to send page views to the namespaced tracker.

@simple-analytics-ai

Copy link
Copy Markdown
Author

In response to #110 (comment):

Prepared a patch against current docs/master describing the legacy sa_pageview alias when free and explicit ba_pageview routing with a second tracker. Verified both behaviors in the current implementation.

The patch applies cleanly. There is no matching open docs PR to update. I have requested owner approval for a supporting docs PR because this automation is authorized to push to existing PR branches. Publication of these instructions must follow the relevant script PR and the v12 release; the patch remains local pending that approval.

Requested: merge current v12 into PR #110. Preserve the namespaced manual pageview and legacy alias behavior, and rebuild conflicting distributions.
@adriaandotcom
adriaandotcom merged commit 3395422 into v12 Oct 15, 2026
1 of 2 checks passed
@adriaandotcom
adriaandotcom deleted the fix/v12-namespaced-pageviews branch October 15, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change: needs review Changes affecting security, data protection, or system stability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant