Skip to content

Initialize currentEngagementURL to undefined, not location.href, refactor npm publish flow - #6573

Open
apata wants to merge 5 commits into
masterfrom
contributor/location-import-issue
Open

Initialize currentEngagementURL to undefined, not location.href, refactor npm publish flow#6573
apata wants to merge 5 commits into
masterfrom
contributor/location-import-issue

Conversation

@apata

@apata apata commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Tracker package readme is supportive of SSR, but the package accesses browser-only location object on import, not on init / track.

There isn't a reason to set this variable to location.href prior to postPageviewTrack being called, as we won't use it until engagements are registered, in which case, we will have set the URL from the payload.

This PR fixes it. Also, it

Picks up #6039, see those comments.

TODO:

toofishes and others added 3 commits August 4, 2026 12:41
For use in a server-side rendered environment, it is important we don't access
browser variables before `init` or `track` are called, that might not exist in
Node/Bun/etc.

There isn't much reason to set this variable to location.href prior to
`postPageviewTrack` being called, as we won't use it until engagements are
registered, in which case, we will have set the URL from the payload.

This is the current error when importing (but not running) the code in Node:

```
Welcome to Node.js v25.4.0.
Type ".help" for more information.
> import('@plausible-analytics/tracker/plausible.js')
Promise {
  <pending>,
  Symbol(async_id_symbol): 103,
  Symbol(trigger_async_id_symbol): 6
}
> Uncaught ReferenceError: location is not defined
```
@apata apata added the tracker-release: patch Releases a new version of the tracker NPM package label Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Analyzed 1026 tracker script variants for size changes.
The following tables summarize the results, with comparison with the baseline version in parentheses.

Main variants:

Brotli Gzip Uncompressed
npm_package/plausible.js (new variant) 2356B 2696B 6434B
plausible-web.js 2174B (-5B / -0.2%) 2494B (-8B / -0.3%) 5926B (-14B / -0.2%)

Important legacy variants:

Brotli Gzip Uncompressed
plausible.js 1123B (+4B / +0.4%) 1300B (-7B / -0.5%) 2841B (-14B / -0.5%)
plausible.hash.js 1088B (-4B / -0.4%) 1265B (-5B / -0.4%) 2720B (-14B / -0.5%)
plausible.pageview-props.tagged-events.js 1659B (-4B / -0.2%) 1925B (-11B / -0.6%) 4372B (-14B / -0.3%)
plausible.file-downloads.hash.pageview-props.revenue.js 1515B (-2B / -0.1%) 1787B (-4B / -0.2%) 3768B (-14B / -0.4%)
plausible.compat.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js 2297B (-2B / -0.1%) 2709B (-9B / -0.3%) 6178B (-14B / -0.2%)

Summary:

Brotli Gzip Uncompressed
Largest variant (plausible.compat.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js) 2297B (-2B / -0.1%) 2709B (-9B / -0.3%) 6178B (-14B / -0.2%)
Max change (plausible.manual.outbound-links.revenue.tagged-events.js) 1582B (+13B / +0.8%) 1851B (-13B / -0.7%) 4053B (-14B / -0.3%)
Min change (plausible.exclusions.manual.outbound-links.js) 1302B (-18B / -1.4%) 1554B (-4B / -0.3%) 3150B (-14B / -0.4%)
Median change 1636B (-3B / -0.2%) 1937B (-8B / -0.4%) 4200B (-14B / -0.3%)

In total, 227 variants brotli size increased and 722 variants brotli size decreased.

@CLAassistant

CLAassistant commented Aug 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@apata apata changed the title Initialize currentEngagementURL to undefined, not location.href Initialize currentEngagementURL to undefined, not location.href, refactor npm publish flow Aug 4, 2026
@apata
apata requested a review from a team August 4, 2026 14:33

@toofishes toofishes left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me! Thanks for tackling this.

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

Labels

tracker-release: patch Releases a new version of the tracker NPM package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants