amplitude / Amplitude-JavaScript

JavaScript SDK for Amplitude
MIT License
315 stars 132 forks source link

How do you reinitialise amplitude if I want to change the original options? #560

Closed Melonbwead closed 1 year ago

Melonbwead commented 1 year ago

Summary

I want to toggle the option disableCookies inside the init call base on user actions, how do I reinitialise amplitude? or do i just call the init again ?

liuyang1520 commented 1 year ago

Hi @MelonBreadVR , could you explain more about "inside the init call base on user actions"? To update config, here are some options:

const client = amplitude.getInstance().init("apikey", null, {disableCookies: true})

client.options.storage = "none" // or
client.options.disableCookies = false
client.options.storage = "cookies" // Options are 'cookies', 'localStorage', 'sessionStorage', or `none`. Will override `disableCookies` option

// if you want to init a new one
client = amplitude.getInstance().init("apikey", null, {disableCookies: false})