Setting and Getting User Data
This section describes how to set and get user data with Typecast.
Typecast offers a way to keep track of a users state with setUserData
and getUserData
. These functions allow you to send and retrieve data about the current user (passed in the initializeTypecast
function) in different parts of your code without needing to modify existing global state logic (i.e. redux).
Set User data
You can set user data to Typecast by using the setUserData
function. In the example below, we're trying to collect user state about a user clicking an ImportantButton
. We'll set importantButtonClicked
as true
if they have.
Note:
setUserData
will set/update user data for the userId passed ininitializeTypecast
.
In the case of duplicate keys
setUserData
will override value of the duplicate key where the last call tosetUserData
was made.
We can optionally specify to setUserData
if we'd like to persist that data to the Typecast platform or not using the optional persist
second parameter of setUserData
(default is true
). If persist
is false, data that is set will only store on the local machine of the current user.
Get User data
We can retrieve userData that we set, or that we have defined in our Typecast platform, using the getUserData
function.
Note: this function is
async
and returns aPromise
.
We can retrieve user data by specifiying the key
parameter to getUserData
, or get the userData
object by providing no parameter to getUserData
.
In this example, we want to determine if a user can see certain content based on if they have clicked the ImportantButton
or not.
Last updated