Initialize currentEngagementURL to undefined, not location.href, refactor npm publish flow - #6573
Open
apata wants to merge 5 commits into
Open
Initialize currentEngagementURL to undefined, not location.href, refactor npm publish flow#6573apata wants to merge 5 commits into
apata wants to merge 5 commits into
Conversation
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
```
|
Analyzed 1026 tracker script variants for size changes. Main variants:
Important legacy variants:
Summary:
In total, 227 variants brotli size increased and 722 variants brotli size decreased. |
5 tasks
toofishes
approved these changes
Aug 4, 2026
toofishes
left a comment
There was a problem hiding this comment.
Looks good to me! Thanks for tackling this.
ukutaht
approved these changes
Aug 5, 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.
Tracker package readme is supportive of SSR, but the package accesses browser-only
locationobject on import, not on init / track.There isn't a reason to set this variable to location.href prior to
postPageviewTrackbeing 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: