User Profiles

Profiles are used to collect widget interactions, rewards, points, and other features inside a single identity. Profiles can be provisioned arbitrarily and can be used to extend your existing user account records. These profiles can either be local, allowing you to create anonymous experiences, or persisted in your user databases, allowing you to create profiles that persist across a user's devices.

When a profile is first created it is given a unique ID and a credential called an Access Token. It is also automatically given a nickname if one is not provided. Profiles will persist for as long as its credentials are stored and passed back to the SDKs & APIs.

Profile initialization

When a user loads the application for the first time, a profile will be generated and returned when initializing the SDK.
You can use the example provided below to save and load the token.

const clientId = "YOUR_CLIENT_ID"
const customId = "YOUR_CUSTOM_ID"

const [userToken, setUserToken] = useState("");

const userHandler = async () => {
  const user = await getUserFromYourDatabase();
  if (user) {
    if (user.emBetToken) {
      // Because user already have a token, userProfile is already updated
      setUserToken(user.emBetToken);
    }
  }
  isReady(true);
};

const tokenHandlerCallback = async (token) => {
  const user = await getUserFromYourDatabase();
  // if user have no token (it's his first SDK initialisation)
  // save the token in your DB for future use 
  // and to not update the profiles on each initialisation
  !user.emBetToken && (await saveUserTokenInYourDB(token));
};

useEffect(() => {
  userHandler();
}, []);

return (
  <View style={styles.container}>
    {isReady && (
      <EmBETWebView
        clientId={clientId}
        customId={customId}
        userToken={userToken}
        tokenHandler={tokenHandlerCallback}
      />
    )}
  </View>
);

getUserFromYourDatabase() function is a placeholder and you should provide your own implementation.

📘

Track your profiles!

While you can initialie the SDKs and create profiles arbitrarily, each new profile counts as a LiveLike user. If you want to keep your profile count in line with your own user count, ensure that each user in your system has only one LiveLike profile associated with them, and that they use the same profile each time they use your app.

📘

Initialization will create a profile if an access token is not provided

Take note that the init method will create a new profile if an accessToken option is not provided and already existing profile data is not available in localStorage. This can result in duplicate profiles being created if not managed carefully.