Previous posts have described Integrating Optimizely Full Stack with Episerver and Using Optimizely Full Stack in Episerver to experiment with a set of content changes in an Episerver Project. This post extends on this to describe audience definitions in Optimizely Full Stack.
Audience definition in Optimizely Full Stack based on user attributes from Episerver
Audiences in Optimizely allows users control who whether a person should participate in an experiment or see a feature. This specific post covers:
- Optimizely Full Stack audience attributes
- Populating audience attributes in Episerver
Optimizely Full Stack audience attributes
When defining audiences in Optimizely Full stack clients can build an audience based on anything Optimizely knows about an end user. To do this audience attributes are required. In order to set up an audience, attributes need to be created in the Optimizely Full Stack UI which match the names of the audience attributes being sent in code. Learn more about defining audience attributes here: https://docs.developers.optimizely.com/full-stack/docs/define-attributes. The following example shows how to set up some audience attributes that will be populated using code described in this post:
Populating audience attributes in Episerver
Through code its possible to set the user attributes that were created above. To do this it requires a set of user attributes and a user id. To help with this a IUserRetriever interface exists along with a default implementation called DefaultUserRetriever. This example implementation of IUserRetriever creates a cookie with a unique identifier which is used as part of the GetUserId method. This implementation can be overridden to use whatever unique identifier is being used in your solution.
It also has a GetUserAttributes method that is used to get user attributes which can be used in Optimizely to build audience definitions to further control who has access to a feature but also who participates in an experiment. The default implementation exposes the visitor groups for a user matches as well the groups they are assigned to and finally whether they are logged in or not.
Now clients can build audiences in Optimizely Full Stack based on attributes of users in Episerver. The attributes can be extended as required to ensure Optimizely audiences can be built to target the experiment to end users as appropriate.