@affiliateo/web 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/provider.js +21 -1
  2. package/package.json +1 -1
package/dist/provider.js CHANGED
@@ -248,13 +248,33 @@ export function AffiliateoProvider({ campaignId, apiUrl, children, }) {
248
248
  ended = true;
249
249
  beacon({ type: 'session_end', campaign_id: campaignIdRef.current, visitor_id: vid, ref: ref || lsGet(LS_REF) || '' });
250
250
  }
251
+ // Server-side session window. Matches STALE_VISITOR_MS in the
252
+ // tracking Durable Object — after this much idle time the server
253
+ // treats the visitor as a new session, rotates session_id, and
254
+ // expects a fresh pageview to anchor the new visit in
255
+ // campaign_events. Without that anchor, funnel steps starting on
256
+ // `page` matches (e.g. the homepage `/`) silently get skipped for
257
+ // visitors who keep a tab open and come back.
258
+ const SESSION_REFIRE_MS = 10 * 60 * 1000;
251
259
  function onVisibilityChange() {
252
260
  if (document.visibilityState === 'hidden') {
253
261
  sendEnd();
254
262
  }
255
263
  else {
264
+ // Tab becomes visible again.
256
265
  ended = false;
257
- } // reset if they come back (tab switch)
266
+ // If the SDK's last pageview was longer ago than the server's
267
+ // 10-min session window, the server has already rolled the
268
+ // visitor over to a new session_id. Refire pageview so the new
269
+ // session has a proper anchor — otherwise the next scroll /
270
+ // click / custom event arrives orphaned and the funnel overlay
271
+ // sees the visitor enter "mid-funnel" (e.g. on a scroll step)
272
+ // without ever passing through the page-step that should
273
+ // bracket the visit.
274
+ if (Date.now() - lastSendTime > SESSION_REFIRE_MS) {
275
+ sendPageview();
276
+ }
277
+ }
258
278
  }
259
279
  // Send pageview on mount
260
280
  if (!sentRef.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affiliateo/web",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "Affiliateo web SDK — affiliate attribution and tracking for web apps",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",