Skip to main content
All CollectionsScenariosContexts
How to set up an advanced context with multiple custom values?
How to set up an advanced context with multiple custom values?

Discover how to use multiple custom variables when creating your contexts.

Flore Bayle avatar
Written by Flore Bayle
Updated over a week ago

Thanks to contexts, you can personalize the message addressed to your readers based on their browsing behavior. Various types of contexts are available in your Dashboard, all of which are described in this article.

The custom context allows you to use any data set in the code of your pages. We now offer the option to independently activate segmentation with multiple custom values sent in your configuration via the Dashboard.

By combining different values, you can easily refine your context and gain flexibility in configuring your scenarios.

How does it work technically?

On the code side, this involves sending an array of variables/values from the SDK configuration, using the following line:

access.config('context', ['value1', 'value2', 'value3']);

There is no limit to the number of values you can pass.

Here is the link to the technical documentation.

๐Ÿ’ก To ensure consistent tracking, the configuration must also be passed in the Audit script according to this documentation.

audit.config('context', ['value1', 'value2', 'value3']);

How to set it up in the Dashboard?

When you create an advanced context, choose "Custom Value" in "Context Type." At this point, you can select the relevant values for your context according to what is defined in your configuration.

Here is an example: I choose to create a context with the filters "football," "ligue 1," and "Paris Saint Germain" ๐Ÿ‘‡

And in terms of integration, the logic is as follows ๐Ÿ‘‡

const userContext = { favorite: 'football' }; // Extracted from the user const articleContext = { section: 'Ligue 1' }; // Extracted from the article 
const sportContext = { team: 'Paris Saint-Germain' }; // Extracted from the sport

// Context configuration with dynamic values
access.config('context', [userContext.favorite, articleContext.section, sportContext.team]);

Example of integration with dataLayer variables

Another example with dataLayer variables you want to use ๐Ÿ‘‡

Example of a dataLayer with dynamic information

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
user: {
favoris: 'football' // User's favorite sport
},
article: {
rubrique: 'Ligue 1' // Article section
},
sport: {
equipe: 'Paris Saint-Germain' // Concerned team
}
});

// Function to extract values from the dataLayer
function getDataLayerValue(path) { return path.split('.').reduce((prev, curr) => (prev ? prev[curr] : undefined), window.dataLayer[0]); }

// Context configuration with dynamic values
access.config('context', [ getDataLayerValue('user.favorite'), getDataLayerValue('article.section'), getDataLayerValue('sport.team') ]);

As you can see, the key to success lies in defining the custom values you want to activate.

๐ŸŒŸ We recommend defining all the custom values you will need in advance so they are correctly implemented in poool Access and Audit. Once this technical configuration is done, there is no need to touch it, and you can independently create your custom contexts!

Feel free to ask if you need further assistance!
โ€‹

Did this answer your question?