-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable cookie support after the SDK has been initialized #1091
Comments
Seems like a bug. Will get this in to next release (2.3.1) |
The fix did not make it into 2.3.1 as far as I can see. In the meantime, did anyone find a workaround for this, yet? Tried for two hours but failed miserably :) |
I managed to create a very hacky workaround. When using the following code, we seem to be able to activate cookies even after the SDK has been initialized. It only works by recreating a completely new app insights instance. like this:
|
Note: This workaround will break in the near future as we are planning on hiding all of the properties that start with "_" as they are considered to be private and should not be set directly. To fix this properly we will need to add a setter method to be able to set/reset this value. |
Hopefully you will not hide it without fixing the bug itself. But thanks for the heads up :) Maybe a reloadConfig method or so might help, in case other settings are also affected by that "set-once, change-never"-behavior. |
Noted. Also while looking at some other indirectly related code, I just tripped over another issue with the workaround, because the _canUseCookies is actual an internal global (on the CoreUtils). if someone else creates a new instance of AppInsights and also sets the isCookieUseDisabled to true this will reset the _canUseCookies back to false (via calling CoreUtils.disableCookies()). This means that all of the cookie functions become no-op... So this also means that by your instance setting this any other instances included on your app/page are also affected, even if they are only using the Utils.setCookie(), Utils.getCookie(), Utils.deleteCookie() and Utils.canUseCookies(). So in your case if you only have 1 AppInsights instance and you are not including any other components that create their own app insights instance then this workaround will currently work (until we fix the issue). But if not then there will be a race (initialization order) condition which could cause cookies to be unexpectedly disabled for any other instances. Notes for possible fix.
|
I think it is a good idea to remove global statics in general, except for maybe global defaults that can be changed on instance-basis. So +1 for removing those. I also think an enable/disableCookie Function makes it explicit that you can actually do that on an existing instance. I would probably prefer that. But it would just somehow make sense to avoid confusion with the existing isCookieUseDisabled flag on the config object. Because having both the config property and the enable/disable methods could confuse users. Maybe rename that config property as well to "enableCookies" and make it default to true? Just thinking out loud here... |
I just came across this as I have exactly the same problem with "cookie consent" scenario in a react application. Is the recommendation to load AI with |
@hiraldesai, there is no way to re-enable cookies after you have initialized AI with cookies disabled. You have to use the workaround I described above by completely re-initializing AI after getting consent. |
We worked with our privacy team and decided that we don't need this feature any more. Feel free to close if there are no other customers asking for it. |
Hello @MSNev , Due to the new Microsoft WCP Cookie Compliance banner, we are required to give the user the option to change their cookie preferences even after they had already consented to them. For example, the user might first consent to Telemetry cookies, but change their mind afterwards whilst using the website. In order to support that, we need to:
My questions are:
|
Hello @MSNev , Any updates on this? There is a compliance deadline date across the company. |
Sorry, was off yesterday, quick answers
|
Thank you for your replies! Is it ok to resort to manually delete the cookies? Would that break the calls to app insights? |
If you call disableCookies() first and then delete them that should not cause any issues |
Note: as per comment in #1463 investigate adding a new "cleanup cookies" function to remove any pre-existing cookies (even if cookie usage is disabled) to better support GDPR. |
Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code microsoft#1076 Also addresses - Disable Cookies microsoft#1125 - Ability to specify cookie Path so that AI works behind App Gateway microsoft#1434
* Enable cookie support after the SDK has been initialized #1091 Utils - Tree-Shaking enhancements Refactor code to provide better tree shaking and minification of generated code #1076 Also addresses - Disable Cookies #1125 - Ability to specify cookie Path so that AI works behind App Gateway #1434 * Update Documentation and Core Perf Tests - address circular dependencies * Add missing api exports
As part of the change that was just checked in, I've added some documentation on the readme but I thought here would also be a good location. I've added support for the existing _canUseCookies, but usage is problematic in ES3 environments (won't always work) and it's still also global, so if you share an environment with another instance using this will affect other users. And for backward compatibility, disabling via this will still disable globally -- even for instance based cookies |
if anyone else is looking for this method, it's located under the |
Oh, nice catch... I'll update the documentation (hopefully today) to hightlight this. |
OK added new issue #1512 to address this gap as this issue will get closed once the release is fully deployed to all CDN endpoints |
v2.6.0 is now fully deployed to all CDN endpoints |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
We have a home page
/
with a cookie banner. We are not allowed to write cookies until the user consents. We initialize the SDK withisCookieUseDisabled=true
. Once the user consents, we would like to immediately write the cookies so when they continue to the next page/sign-in
, same session ID is used there.We can call
appInsights.properties.context.sessionManager.update()
but there seems to be no way to setCoreUtils._canUseCookies
totrue
once the SDK has been initialized.The text was updated successfully, but these errors were encountered: