From 0dc709062cdda4b250433993ee270083433d9a46 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 30 Jan 2026 15:04:34 -0600 Subject: [PATCH] Initialize currentEngagementURL to empty string, not location.href 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 { , Symbol(async_id_symbol): 103, Symbol(trigger_async_id_symbol): 6 } > Uncaught ReferenceError: location is not defined ``` --- tracker/src/engagement.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracker/src/engagement.js b/tracker/src/engagement.js index c4a6ab9e55c8..09e9e4625702 100644 --- a/tracker/src/engagement.js +++ b/tracker/src/engagement.js @@ -9,7 +9,7 @@ import { sendRequest } from './networking' var listeningOnEngagement = false var currentEngagementIgnored -var currentEngagementURL = location.href +var currentEngagementURL = '' var currentEngagementProps = {} var currentEngagementMaxScrollDepth = -1