From 689b7bfddcdd3fe623abaa530d05697f8b74fa6f Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Sat, 11 Sep 2021 21:00:53 +0100 Subject: [PATCH 1/4] Log when respecting the Do-Not-Track header --- src/__tests__/LDClient-events-test.js | 1 + src/index.js | 13 ++++++++++++- src/messages.js | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/__tests__/LDClient-events-test.js b/src/__tests__/LDClient-events-test.js index f84c188..c5934de 100644 --- a/src/__tests__/LDClient-events-test.js +++ b/src/__tests__/LDClient-events-test.js @@ -274,6 +274,7 @@ describe('LDClient events', () => { await client.identify(user1); expect(ep.events.length).toEqual(0); + expect(platform.testing.logger.output.warn).toEqual([messages.doNotTrackEnabled()]) }); }); }); diff --git a/src/index.js b/src/index.js index 444d086..0b33d0e 100644 --- a/src/index.js +++ b/src/index.js @@ -61,6 +61,7 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef let inited = false; let closed = false; let firstEvent = true; + let hasLoggedDntWarning = false; // The "stateProvider" object is used in the Electron SDK, to allow one client instance to take partial // control of another. If present, it has the following contract: @@ -118,7 +119,17 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef } function shouldEnqueueEvent() { - return sendEvents && !closed && !platform.isDoNotTrack(); + if (!sendEvents || closed) { + return false; + } + if (platform.isDoNotTrack()) { + if (!hasLoggedDntWarning) { + logger.warn(messages.doNotTrackEnabled()); + hasLoggedDntWarning = true; + } + return false; + } + return true; } function enqueueEvent(event) { diff --git a/src/messages.js b/src/messages.js index 5c178dd..ba210c9 100644 --- a/src/messages.js +++ b/src/messages.js @@ -110,6 +110,10 @@ export const identifyDisabled = function() { return 'identify() has no effect here; it must be called on the main client instance'; }; +export const doNotTrackEnabled = function() { + return 'Not sending events to LaunchDarkly because Do Not Track is enabled.'; +}; + export const streamClosing = function() { return 'Closing stream connection'; }; From a99525c6579c8a06c45920e8d98a6dccd8ac1122 Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Mon, 13 Sep 2021 23:05:04 +0100 Subject: [PATCH 2/4] Update src/messages.js Co-authored-by: Ben Woskow <48036130+bwoskow-ld@users.noreply.github.com> --- src/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/messages.js b/src/messages.js index ba210c9..80bf5d7 100644 --- a/src/messages.js +++ b/src/messages.js @@ -111,7 +111,7 @@ export const identifyDisabled = function() { }; export const doNotTrackEnabled = function() { - return 'Not sending events to LaunchDarkly because Do Not Track is enabled.'; + return 'LaunchDarkly events will not be sent because this browser's Do Not Track setting is enabled.'; }; export const streamClosing = function() { From 496d970636285edc5eaffe2e77823fd42f4ab9b8 Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Mon, 13 Sep 2021 23:25:44 +0100 Subject: [PATCH 3/4] Fix syntax error --- src/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/messages.js b/src/messages.js index 80bf5d7..f26760d 100644 --- a/src/messages.js +++ b/src/messages.js @@ -111,7 +111,7 @@ export const identifyDisabled = function() { }; export const doNotTrackEnabled = function() { - return 'LaunchDarkly events will not be sent because this browser's Do Not Track setting is enabled.'; + return "LaunchDarkly events will not be sent because this browser's Do Not Track setting is enabled."; }; export const streamClosing = function() { From 88c0548b5b61ae340565f8392260f06c114814f2 Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Mon, 13 Sep 2021 23:26:00 +0100 Subject: [PATCH 4/4] Test that we only warn about do-not-track once --- src/__tests__/LDClient-events-test.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/__tests__/LDClient-events-test.js b/src/__tests__/LDClient-events-test.js index c5934de..7f1f3c5 100644 --- a/src/__tests__/LDClient-events-test.js +++ b/src/__tests__/LDClient-events-test.js @@ -274,7 +274,13 @@ describe('LDClient events', () => { await client.identify(user1); expect(ep.events.length).toEqual(0); - expect(platform.testing.logger.output.warn).toEqual([messages.doNotTrackEnabled()]) + expect(platform.testing.logger.output.warn).toEqual([messages.doNotTrackEnabled()]); + + // Subsequent calls after the first shouldn't trigger additional + // warnings. One is enough; more is just noise. + await client.identify(user1); + expect(ep.events.length).toEqual(0); + expect(platform.testing.logger.output.warn).toEqual([messages.doNotTrackEnabled()]); }); }); });