Episerver has recently released Episerver Insight which is the user interface for viewing, filtering visitor profiles and creating segments. This relies on Episerver Profile store in order to store profile data.
This post describes how its possible to load a user profile and update some properties on it using the Episerver Profile Store API. As Episerver Profile store is a pure RESTful API it means developers can choose any way to interact with it. For this example RestSharp is used to connect to the API and uses Newtonsoft.Json to manipulate the data.
In this example I want to perform the following operations:
- Retrieve a profile in Episerver Profile store
- Update properties of a profile in Episerver Profile store
Retrieve the current profile
A profile in Episerver Profile store has a number of deviceids associated with it:
The device id itself is stored in the _madid cookie on the browser.
Next it's just a case of querying the profile store for profiles with a matching device ID. Example code for this is seen below:
Update the company name, website and mobile phone number
Now that the profile for the current user has been retrieved it’s possible to interact with it. In this example I am going to set the company name, mobile phone and website properties as shown in the Episerver Insight here:
Now the profile can be updated as follows:
The outcome of the code above is that the company name, website and mobile phone of the profile have been set and are visible in Episerver Insight UI:
The full code Episerver Profile store API example is available on Gist. It should be noted this is only example code to show how it's possible to access the profile and update in the Episerver Profile store. It isn’t meant to be best practice.
- Episerver Insight Developer Guide - https://world.episerver.com/documentation/developer-guides/insight/
- Episerver Profile Store Developer Guide - https://world.episerver.com/documentation/developer-guides/profile-store/
- Episerver Profile Store API - https://world.episerver.com/documentation/developer-guides/profile-store/profile-store-api/