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

Ability to add custom identity storage provider in @amplitude/analytics-browser@v2.0.0 #448

Open
williamrobertson13 opened this issue Jun 20, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@williamrobertson13
Copy link

williamrobertson13 commented Jun 20, 2023

Summary

The cookieStorageProvider property was removed in v2.0.0 of the Browser SDK, so this blocks us from being able to specify a custom storage provider for GDPR compliance purposes. It would be amazing if the SDK provided this type of functionality out of the box (e.g. switchIdentityStorage) or added a custom option to identityStorage so folks can provide custom storage providers again.

Motivations

For GDPR compliance, we would like to track users using memory storage and then switch to cookies only after users have provided their consent to use tracking cookies. We were able to do this in @amplitude/analytics-browser@v1.0.0 by creating a custom Storage instance (https://github.com/MystenLabs/sui/blob/main/apps/core/src/utils/persistableStorage.ts) and using that for the cookieStorageProvider property. We're aware of the default recommended solution of deferring the initialization of Amplitude until users have provided consent, but that isn't quite the same and we miss out on potentially useful insights.

@williamrobertson13 williamrobertson13 added the enhancement New feature or request label Jun 20, 2023
@kevinpagtakhan
Copy link
Collaborator

Hi @williamrobertson13, thank you for choosing Amplitude. We like hearing from our customers so we really appreciate sharing this with us. I'm more than happy to find the best path forward for you. Before anything else, I'd like to hear more.

but that isn't quite the same and we miss out on potentially useful insights

Can you elaborate on this point more? I'd also like to explore opportunities on how to improve our deferred initialization logic, even if end up moving forward with a different solution for you.

@williamrobertson13
Copy link
Author

williamrobertson13 commented Jun 20, 2023

Hey @kevinpagtakhan! Thanks for the quick response. So to elaborate on the problem with deferred initialization - a lot of folks don't accept or reject consent to use tracking cookies when prompted with consent banners on websites. With the current solution of deferred initialization, a user could go to a site -> do all sorts of actions without ever accepting/rejecting consent -> leave the site and Amplitude won't ever initialize and log events. As one alternative solution, I suppose maybe you could add a pagehide listener and initialize Amplitude with the transport type to beacon and the identity storage to none for this particular use case? AFAIK pagehide isn't the most reliable though hence the custom Storage provider route we're experimenting with.

@jnthns
Copy link

jnthns commented Jun 27, 2023

hey @williamrobertson13 you can set identityStorage to None on init, like this:
amplitude.init(apiKey, { identityStorage: 'none' });

This stores everything in memoryStorage, which is wiped when the user abandons the website. You can reinitialize like this once the user consents to cookies:
amplitude.init(apiKey, { identityStorage: 'cookie' });

@RubenZx
Copy link

RubenZx commented Jan 4, 2024

hey @williamrobertson13 you can set identityStorage to None on init, like this: amplitude.init(apiKey, { identityStorage: 'none' });

This stores everything in memoryStorage, which is wiped when the user abandons the website. You can reinitialize like this once the user consents to cookies: amplitude.init(apiKey, { identityStorage: 'cookie' });

Hey, is it correct to call init twice to change the indentityStorage? Do you know if there is any helper to do that?

@gabrielwallin
Copy link

I'm wondering about the same thing as @RubenZx ,
we would like to achieve the following process (in order to maintain tracking across multiple apps on the same domain):

pageload: init with sessionStorage
consent: init with cookieStorage
revoke consent: init with sessionStorage again

@michal-filip
Copy link
Contributor

I share the same interest. From what some of our testing has shown, custom plugins do not work after re-initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants