Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize new session cookie synchronously to avoid overlapping sessions (close #1381) #1382

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

matus-tomlein
Copy link
Contributor

Issue #1381

The issue reported that after upgrading to v4, there is a higher number of very short sessions in very short sequences. The hypothesis was that this is due to the async cookie access introduced in v4.

I was able to reproduce the problem with a simple setup that I added to the integration tests – a single page that embeds 15 iframe pages. The iframes are loaded at the same time and each initializes a new tracker and tracks a page view. Since the iframes share the same cookies, we should only see a single session id across all tracked page views.

With this setup, I was getting multiple different session ids across the page views. It was usually around 10 different session IDs.

The change I made was to flush the cookies (write them synchronously) each time the session changes. That means the first session or every subsequent new session. When a new event is tracked without triggering a new session, the cookies are still updated async by default.

This fixed the problem in the iframe test setup. Now I am only getting a single session ID across all page views. Have kept this test in the integration tests so that we don't regress on the behaviour.

@matus-tomlein matus-tomlein force-pushed the issue/duplicate_sessions branch from 270cad3 to ab5dc9b Compare November 18, 2024 14:06
Copy link

bundlemon bot commented Nov 18, 2024

BundleMon

Files added (6)
Status Path Size Limits
trackers/javascript-tracker/dist/sp.js
+24.46KB 30KB / +10%
libraries/browser-tracker-core/dist/index.mod
ule.js
+23.48KB 25KB / +10%
libraries/tracker-core/dist/index.module.js
+19.42KB 20KB / +10%
trackers/browser-tracker/dist/index.umd.min.j
s
+17.37KB 20KB / +10%
trackers/javascript-tracker/dist/sp.lite.js
+17.31KB 20KB / +10%
trackers/browser-tracker/dist/index.module.js
+3.49KB 5KB / +10%

Total files change +105.53KB 0%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history

Copy link
Contributor

@jethron jethron left a comment

Choose a reason for hiding this comment

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

LGTM!

@matus-tomlein matus-tomlein changed the base branch from master to release/4.0.3 November 20, 2024 08:32
@matus-tomlein matus-tomlein merged commit b10f8d4 into release/4.0.3 Nov 20, 2024
3 checks passed
@matus-tomlein matus-tomlein deleted the issue/duplicate_sessions branch November 20, 2024 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants