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 in the init method. You can use this to save the access_token property to your existing user's profile.
// No saved access token yet, save it for next time
const emBETProfile = await embet.init({clientId: "client-id"});
saveTokenToUserProfile(emBETProfile.access_token)saveTokenToUserProfile() function is a placeholder and you should provide your own implementation.
If you already have an access token for an emBET Profile, loading this profile will allow you to pass the access_token property to the init function, which will initialize the application with that user profile, allowing for persistent profiles across devices.
fetchSavedUserProfile().then((savedUserProfile) => {
const savedAccessToken = savedUserProfile.access_token;
embet.init({
clientId: "client-id",
accessToken: savedAccessToken
}).then((emBETProfile) => {
console.log("Initialized", emBETProfile);
});
});
Track your profiles!While you can initialize the SDK and create profiles arbitrarily, each new profile counts as a new 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 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 providedTake note that the
initmethod will create a new profile if anaccessTokenoption is not provided and already existing profile data is not available inlocalStorage. This can result in duplicate profiles being created if not managed carefully.
Getting initialized Profile
You can get the user profile manually, after initialisation, using the userProfile property.
const initializedUserProfile = embet.userProfile;Updating Profile
The profile's nickname or custom data can be updated with the updateUserProfile method. This method is passed the profile's accessToken, and optionally an options object containing either a nickname property, a custom_data property, or both. This method returns the updated profile object.
embet.updateUserProfile({
accessToken: "<Access token>",
options: {
nickname: "<New Nickname>",
custom_data: JSON.stringify({ custom: 'data' })
}
}).then((profile) => {
console.log(profile);
});Updated 30 days ago
