Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/browser-tracker-core",
"comment": "Change default tracker initialization params (discoverRootDomain, cookieSameSite)",
"type": "none"
}
],
"packageName": "@snowplow/browser-tracker-core"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/javascript-tracker",
"comment": "",
"type": "none"
}
],
"packageName": "@snowplow/javascript-tracker"
}
5 changes: 3 additions & 2 deletions libraries/browser-tracker-core/src/tracker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ export function Tracker(
// First-party cookie domain
// User agent defaults to origin hostname
configCookieDomain = trackerConfiguration.cookieDomain ?? undefined,
discoverRootDomain = trackerConfiguration.discoverRootDomain || true,
// First-party cookie path
// Default is user agent defined.
configCookiePath = '/',
// First-party cookie samesite attribute
configCookieSameSite = trackerConfiguration.cookieSameSite ?? 'None',
configCookieSameSite = trackerConfiguration.cookieSameSite ?? 'Lax',
// First-party cookie secure attribute
configCookieSecure = trackerConfiguration.cookieSecure ?? true,
// Do Not Track browser feature
Expand Down Expand Up @@ -308,7 +309,7 @@ export function Tracker(
configSessionContext = trackerConfiguration.contexts?.session ?? false,
toOptoutByCookie: string | boolean;

if (trackerConfiguration.hasOwnProperty('discoverRootDomain') && trackerConfiguration.discoverRootDomain) {
if (discoverRootDomain && !configCookieDomain) {
configCookieDomain = findRootDomain(configCookieSameSite, configCookieSecure);
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/browser-tracker-core/src/tracker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export type TrackerConfiguration = {
/**
* The SameSite value for the cookie
* {@link https://snowplowanalytics.com/blog/2020/09/07/pipeline-configuration-for-complete-and-accurate-data/}
* @defaultValue None
* @defaultValue Lax
*/
cookieSameSite?: CookieSameSite;
/**
Expand Down Expand Up @@ -170,7 +170,7 @@ export type TrackerConfiguration = {
*
* This sets cookies to try to determine the root domain, and some cookies may
* fail to save. This is expected behavior.
* @defaultValue false
* @defaultValue true
*/
discoverRootDomain?: boolean;
/**
Expand Down
4 changes: 2 additions & 2 deletions libraries/browser-tracker-core/test/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function createTestIdCookie(params: Partial<CreateTestIdCookie>) {
const { domainHash } = cookieParams;
// @ts-expect-error
delete cookieParams.domainHash;
return `_sp_id.${domainHash}=${Object.values(cookieParams).join('.')}; Expires=; Path=/; SameSite=None; Secure;`;
return `_sp_id.${domainHash}=${Object.values(cookieParams).join('.')}; Expires=; Path=/; SameSite=Lax; Secure;`;
}

interface CreateTestSessionIdCookie {
Expand All @@ -70,5 +70,5 @@ interface CreateTestSessionIdCookie {
*/
export function createTestSessionIdCookie(params?: CreateTestSessionIdCookie) {
const domainHash = DEFAULT_DOMAIN_HASH || params?.domainHash;
return `_sp_ses.${domainHash}=*; Expires=; Path=/; SameSite=None; Secure;`;
return `_sp_ses.${domainHash}=*; Expires=; Path=/; SameSite=Lax; Secure;`;
}
6 changes: 0 additions & 6 deletions trackers/javascript-tracker/test/pages/cookies.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

snowplow('newTracker', 'sp1', 'snowplow-js-tracker.local:9090', {
cookieName: '_sp_1',
cookieSameSite: 'Lax',
cookieSecure: false,
});

Expand All @@ -49,36 +48,31 @@

snowplow('newTracker', 'sp3', 'snowplow-js-tracker.local:9090', {
cookieName: '_sp_3',
cookieSameSite: 'Lax',
cookieSecure: false,
sessionCookieTimeout: 1,
cookieLifetime: 1,
});

snowplow('newTracker', 'sp4', 'snowplow-js-tracker.local:9090', {
cookieName: '_sp_4',
cookieSameSite: 'Lax',
cookieSecure: false,
anonymousTracking: true,
});

snowplow('newTracker', 'sp5', 'snowplow-js-tracker.local:9090', {
cookieName: '_sp_5',
cookieSameSite: 'Lax',
cookieSecure: false,
stateStorageStrategy: 'localStorage',
});

snowplow('newTracker', 'sp6', 'snowplow-js-tracker.local:9090', {
cookieName: '_sp_6',
cookieSameSite: 'Lax',
cookieSecure: false,
stateStorageStrategy: 'cookie',
});

snowplow('newTracker', 'sp7', 'snowplow-js-tracker.local:9090', {
cookieName: '_sp_7',
cookieSameSite: 'Lax',
cookieSecure: false,
cookieDomain: '.google.com',
});
Expand Down