Skip to content
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

Toggle cookies using getCookieMgr().setEnabled(false/true) behaviour #1848

Closed
ceejayw opened this issue May 29, 2022 · 2 comments
Closed

Toggle cookies using getCookieMgr().setEnabled(false/true) behaviour #1848

ceejayw opened this issue May 29, 2022 · 2 comments

Comments

@ceejayw
Copy link

ceejayw commented May 29, 2022

I have a requirement for users of our site to be able to toggle non-essential cookies on / off for GDPR purposes. I have been looking at how to achieve this with Application Insights for a couple of days now.

I have been using appInsights.getCookieMgr().setEnabled(false/true) to try and solve this. However it seems there could be some issues, or perhaps I'm misunderstanding something! I'm using Angular for development.

It seems that setEnabled(false/true) does not always delete/re-create the cookies. I'm thinking that perhaps instead it blocks/un-blocks the cookies being used - is this correct? If so, this might be an ok solution. However, if Application Insights is initiated with disableCookiesUsage: true, then setEnabled(true), will never create any cookies. I did read in an issue (#1585) and associated PR (#1628), that we should use appInsights.context.user.update(), this does create the ai_user cookie, but ai_session does not get created for me, is there a separate way to do this?

I did think the easiest way to achieve the requirement might be to simply reinitialise Application Insights on user toggle, changing disableCookiesUsage: false/true accordingly. However I'm concerned this could cause unwanted side effects and/or lots of uneccerserry noise in the logs if a user toggles multiple times.

I'm not sure where to go next on this, or if there's a really simple way to achieve what I need that I'm missing, any help with this flow would be really appreciated.

@ceejayw
Copy link
Author

ceejayw commented May 31, 2022

Follow up on this. Our policy page where the cookie toggle exists opens in the new browser tab, when setting setEnabled(true) in this tab, then the ai_user cookie gets created, but ai_session cookie does not. To work round this I needed to send a message from the cookie policy tab to the original tab where AI was initialised to trigger setEnabled(true) and the ai_session cookie will now appear (after around 60 seconds).

I do wonder if the ai_session not being created is a bug, but have found a work around to what was causing much of the confusion above, so am closing this.

@ceejayw ceejayw closed this as completed May 31, 2022
@github-actions
Copy link

github-actions bot commented Jun 1, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant