Amplitude-TypeScript icon indicating copy to clipboard operation
Amplitude-TypeScript copied to clipboard

Ability to add custom identity storage provider in @amplitude/[email protected]

Open williamrobertson13 opened this issue 2 years ago • 6 comments

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/[email protected] 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 avatar Jun 20 '23 16:06 williamrobertson13

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.

kevinpagtakhan avatar Jun 20 '23 19:06 kevinpagtakhan

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.

williamrobertson13 avatar Jun 20 '23 20:06 williamrobertson13

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' });

jnthns avatar Jun 27 '23 21:06 jnthns

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?

RubenZx avatar Jan 04 '24 08:01 RubenZx

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

gabrielwallin avatar Mar 25 '24 14:03 gabrielwallin

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

michal-filip avatar Jun 24 '24 08:06 michal-filip