You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a user has an Amplitude cookie with optOut: true and we initialize an Amplitude client with optOut: false as an option such that a new session is created, the client is initialized with optOut: false
Alternatively, an Amplitude client initialized with a new session always has its optOut determined by the same precedence rule of persisted cookie setting vs option, regardless of whether the cookie has optOut: true and the initialization option has optOut: false or the cookie has optOut: false and the initialization option has optOut: true
Alternatively, there is better documentation around this behavior
Current Behavior
We were using options to determine users' optOut settings. We made a change causing previously opted out users to be opted in. The optOut setting from the users' Amplitude cookies was true, and even though enough time had passed that Amplitude initialized with a new session, the persisted, old cookie value overrode the initialization option and the Amplitude client was initialized opted out.
Possible Solution
The fix depends on whether this is intended behavior, I've made some suggestions above. Also, we may want the initialization option to take precedence regardless of whether initialization starts a new session.
Steps to Reproduce
To confirm that the optOut setting in the cookie is unexpectedly (to me) persisted when true:
Ensure that the amp_xxxxxx cookie is deleted
Set code up to initialize the Amplitude client with { optOut: true, sessionTimeout: 60 * 1000 } (along with any other non-conflicting params needed for your environment). You can use a callback passed to init that takes instance as an argument and checks instance.isNewSession() and logs accordingly to confirm that a new session was started.
Go through a UI flow that will cause the Amplitude client to be initialized
Fire an Amplitude event with the initialized client
Inspect the amp_xxxxxx cookie and confirm that it has a '1' at index 2 when split on '.' reflecting that the optOut setting was persisted (and is truthy)
Confirm that the Amplitude event did not cause an Amplitude API call
Wait at least one minute so the session timeout expires and Amplitude will initialize with a new session
Change the code setting to optOut: false instead of optOut: true
Repeat steps 3 and 4 above
Inspect the amp_xxxxxx cookie and confirm that it still is set to optOut
Confirm that the Amplitude event did not cause an Amplitude API call
To confirm that the optOut setting in the cookie is not persisted when false:
Ensure that the amp_xxxxxx cookie is deleted
Set up code to initialize the Amplitude client with { optOut: false, sessionTimeout: 60 * 1000 } (along with any other non-conflicting params needed for your environment). You can use a callback passed to init that takes instance as an argument and checks instance.isNewSession() and logs accordingly to confirm that a new session was started.
Go through a UI flow that will cause the Amplitude client to be initialized
Fire an Amplitude event with the initialized client
Inspect the amp_xxxxxx cookie and confirm that it has '' at index 2 when split on '.', reflecting that the optOut setting was persisted (and is falsy)
Confirm that the Amplitude event caused an Amplitude API call
Wait at least one minute so the session timeout expires and Amplitude will initialize with a new session
Change the code setting to optOut: true instead of optOut: false
Repeat steps 3 and 4 from this section
Inspect the amp_xxxxxx cookie and confirm that it now indicates optOut: true
Confirm that the Amplitude event did not cause an Amplitude API call
Other
See this commit. The wording of the test that was added ('should favor the config optOut setting over cookie optOut if the config optOut is set to true') makes me think this could be intended behavior.
Using an init callback and calling instance.setOptOut(optOut) gives the client the correct optOut setting.
Environment
JS SDK Version: amplitude-js version 8.17.0
Installation Method: npm
Browser and Version: Chrome Version 102.0.5005.61 (Official Build) (x86_64)
The text was updated successfully, but these errors were encountered:
Expected Behavior
optOut: true
and we initialize an Amplitude client withoptOut: false
as anoption
such that a new session is created, the client is initialized withoptOut: false
optOut
determined by the same precedence rule of persisted cookie setting vs option, regardless of whether the cookie hasoptOut: true
and the initialization option hasoptOut: false
or the cookie hasoptOut: false
and the initialization option hasoptOut: true
Current Behavior
We were using
options
to determine users'optOut
settings. We made a change causing previously opted out users to be opted in. TheoptOut
setting from the users' Amplitude cookies wastrue
, and even though enough time had passed that Amplitude initialized with a new session, the persisted, old cookie value overrode the initialization option and the Amplitude client was initialized opted out.Possible Solution
The fix depends on whether this is intended behavior, I've made some suggestions above. Also, we may want the initialization option to take precedence regardless of whether initialization starts a new session.
Steps to Reproduce
To confirm that the
optOut
setting in the cookie is unexpectedly (to me) persisted whentrue
:amp_xxxxxx
cookie is deleted{ optOut: true, sessionTimeout: 60 * 1000 }
(along with any other non-conflicting params needed for your environment). You can use a callback passed toinit
that takesinstance
as an argument and checksinstance.isNewSession()
and logs accordingly to confirm that a new session was started.amp_xxxxxx
cookie and confirm that it has a '1' at index 2 when split on '.' reflecting that theoptOut
setting was persisted (and is truthy)optOut: false
instead ofoptOut: true
amp_xxxxxx
cookie and confirm that it still is set tooptOut
To confirm that the
optOut
setting in the cookie is not persisted whenfalse
:amp_xxxxxx
cookie is deleted{ optOut: false, sessionTimeout: 60 * 1000 }
(along with any other non-conflicting params needed for your environment). You can use a callback passed toinit
that takesinstance
as an argument and checksinstance.isNewSession()
and logs accordingly to confirm that a new session was started.amp_xxxxxx
cookie and confirm that it has '' at index 2 when split on '.', reflecting that theoptOut
setting was persisted (and is falsy)optOut: true
instead ofoptOut: false
amp_xxxxxx
cookie and confirm that it now indicatesoptOut: true
Other
See this commit. The wording of the test that was added ('should favor the config optOut setting over cookie optOut if the config optOut is set to true') makes me think this could be intended behavior.
Using an
init
callback and callinginstance.setOptOut(optOut)
gives the client the correctoptOut
setting.Environment
The text was updated successfully, but these errors were encountered: