-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialize new session cookie synchronously to avoid overlapping sessi…
…ons (close #1381)
- Loading branch information
1 parent
e835323
commit 270cad3
Showing
12 changed files
with
154 additions
and
18 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@snowplow/browser-tracker-core/issue-duplicate_sessions_2024-11-18-13-57.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@snowplow/browser-tracker-core", | ||
"comment": "Serialize new session cookie synchronously to avoid overlapping sessions (#1381)", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@snowplow/browser-tracker-core" | ||
} |
10 changes: 10 additions & 0 deletions
10
common/changes/@snowplow/javascript-tracker/issue-duplicate_sessions_2024-11-18-13-57.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@snowplow/javascript-tracker", | ||
"comment": "Serialize new session cookie synchronously to avoid overlapping sessions (#1381)", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@snowplow/javascript-tracker" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. | ||
{ | ||
"pnpmShrinkwrapHash": "6693fc661ad5b6461d8a0fbbecf81c5f61d703bb", | ||
"pnpmShrinkwrapHash": "77e8d084b2ff087ff8f5dfa5df436f42dbaa623c", | ||
"preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f" | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
23 changes: 23 additions & 0 deletions
23
trackers/javascript-tracker/test/integration/cookies.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { fetchResults } from '../micro'; | ||
import { pageSetup } from './helpers'; | ||
|
||
describe('Tracker created domain cookies across multiple pages', () => { | ||
let log: Array<unknown> = []; | ||
let testIdentifier = ''; | ||
|
||
beforeAll(async () => { | ||
testIdentifier = await pageSetup(); | ||
await browser.url('/multi_page_cookies'); | ||
await browser.pause(5000); | ||
|
||
log = await browser.call(async () => await fetchResults()); | ||
}); | ||
|
||
it('all events should have the same session id', () => { | ||
expect(log.length).toBeGreaterThanOrEqual(15); | ||
|
||
const sessionIds = log.map((ev) => (ev as any).event.domain_sessionid); | ||
const uniqueSessionIds = Array.from(new Set(sessionIds)); | ||
expect(uniqueSessionIds.length).toBe(1); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
trackers/javascript-tracker/test/pages/multi_page_cookies/iframe.html
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Cookies iframe test page</title> | ||
</head> | ||
<body> | ||
<div id="init"></div> | ||
<div id="cookies"></div> | ||
<script> | ||
(function (p, l, o, w, i, n, g) { | ||
if (!p[i]) { | ||
p.GlobalSnowplowNamespace = p.GlobalSnowplowNamespace || []; | ||
p.GlobalSnowplowNamespace.push(i); | ||
p[i] = function () { | ||
(p[i].q = p[i].q || []).push(arguments); | ||
}; | ||
p[i].q = p[i].q || []; | ||
n = l.createElement(o); | ||
g = l.getElementsByTagName(o)[0]; | ||
n.async = 1; | ||
n.src = w; | ||
g.parentNode.insertBefore(n, g); | ||
} | ||
})(window, document, 'script', '../snowplow.js', 'snowplow'); | ||
|
||
const urlParams = new URLSearchParams(window.location.search); | ||
|
||
var testIdentifier = document.cookie.split('testIdentifier=')[1].split(';')[0].trim(); | ||
var collector_endpoint = document.cookie.split('container=')[1].split(';')[0]; | ||
|
||
snowplow('newTracker', 'sp0', collector_endpoint, { | ||
appId: 'cookies-iframe-' + testIdentifier, | ||
cookieName: urlParams.get('cookieName'), | ||
cookieSecure: false, | ||
}); | ||
snowplow('trackPageView'); | ||
|
||
snowplow(function () { | ||
document.getElementById('init').innerText = 'true'; | ||
}); | ||
|
||
setTimeout(function () { | ||
document.getElementById('cookies').innerText = document.cookie; | ||
}, 3000); // Wait 3 seconds so sp3 cookies expires | ||
</script> | ||
</body> | ||
</html> |
20 changes: 20 additions & 0 deletions
20
trackers/javascript-tracker/test/pages/multi_page_cookies/index.html
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Cookies test page</title> | ||
</head> | ||
<body> | ||
<script> | ||
const cookieId = Math.random().toString(36); | ||
|
||
for (let i = 0; i < 15; i++) { | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `/multi_page_cookies/iframe.html?cookieName=_sp_${cookieId}`; | ||
iframe.width = "600"; | ||
iframe.height = "400"; | ||
iframe.style.margin = "10px"; | ||
document.body.appendChild(iframe); | ||
} | ||
</script> | ||
</body> | ||
</html> |