Skip to content

Commit

Permalink
Change default tracker initialization parameters for JS/Browser v4
Browse files Browse the repository at this point in the history
  • Loading branch information
igneel64 committed Sep 13, 2023
1 parent 93a6b37 commit 7bbb74a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
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 @@ -238,11 +238,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 @@ -320,7 +321,7 @@ export function Tracker(
onSessionUpdateCallback = trackerConfiguration.onSessionUpdateCallback,
manualSessionUpdateCalled = false;

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 @@ -93,7 +93,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 @@ -172,7 +172,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 @@ -60,7 +60,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 @@ -72,7 +72,7 @@ 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;`;
}

export function createTracker(configuration?: TrackerConfiguration) {
Expand Down
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

0 comments on commit 7bbb74a

Please sign in to comment.