Skip to content Skip to sidebar Skip to footer

How To Use LocalStorage To Store User Id

I want to use localStorage to store user id. Then fetch the user id if it exists and if it does not exist then create it using the google's analytics.js and store it. To get client

Solution 1:

to set your ClientID,

localStorage.setItem("clientId","someID")

to get,

if (localStorage.hasOwnProperty("clientId")) {
    cli_id = localStorage.getItem("clientId")
}
else {
    cli_id = localStorage.setItem("clientId","someID") // here someid from your google analytics fetch
}
console.log(cli_id)

Post a Comment for "How To Use LocalStorage To Store User Id"