AEM ContextHub: Setup, Segments and Personalization
Add ContextHub to an AEM page component, configure stores and UI modules, build segments, target components in Targeting mode, and where Adobe Target fits.
Rewritten in November 2026 for AEM as a Cloud Service and AEM 6.5, checked against Adobe's ContextHub, segmentation and targeting documentation.
On this page
ContextHub is AEM's built-in framework for collecting data about the current visitor in the browser and personalizing pages with it. It has three parts: stores that hold context data such as location, device or profile on the client, a segmentation engine that works out which segments the visitor belongs to, and a toolbar that lets authors preview a page as different personas. Adobe lists it as one of two targeting engines in AEM, next to Adobe Target. Setting it up for a site takes four steps: include the component, pick a configuration, build segments, target content.
How ContextHub works
Adobe describes ContextHub as a framework for storing, manipulating, and presenting context data. The stores persist data in the visitor's browser, a JavaScript API reads and changes it, and segments are resolved against whatever the stores currently hold.
On author, the same machinery drives the ContextHub toolbar. In Preview mode an author opens it, switches the persona or edits store values, and watches the targeted parts of the page change. Adobe's page on previewing pages with ContextHub data says the toolbar is available only on author instances, and only when an administrator has enabled it.
How do you set up ContextHub on an AEM site?
Start in code. The page component has to include the contexthub component in the head of the page, which loads ContextHub's JavaScript libraries and its configuration. Adobe gives the line in adding ContextHub to pages. In a project built on the Core Components page, the place for it is your page component's customheaderlibs.html, which the Core page's head.html includes inside <head>:
<!--/* ui.apps/.../components/page/customheaderlibs.html */-->
<!--/* ContextHub: stores, segment engine, author toolbar */-->
<sly data-sly-resource="${'contexthub' @ resourceType='granite/contexthub/components/contexthub'}"/>
The include is a plain data-sly-resource with a forced resource type, so no contexthub node needs to exist under the page.
Then point the site at a configuration. In the site root's Page Properties, Personalization tab, set ContextHub Path to the ContextHub configuration and Segments Path to the folder that holds your segments. The Brand field on the same tab scopes Targeting mode and needs membership in the Target Administrators group.
ContextHub configurations under /conf
A configuration decides which stores and UI modules a site gets. Manage it under Tools > Sites > ContextHub. On AEM as a Cloud Service you choose a configuration container there, and the configurations themselves live in /conf/global/settings/cloudsettings or in your site's own /conf/<site>/settings/cloudsettings. AEM 6.5 also has a legacy configuration at /libs/settings/cloudsettings/legacy/contexthub, which is where its debug and disable settings live.
These settings matter on a live site. Per configuration, Disable ContextHub stops it loading its JavaScript and CSS at all, and Debug turns on console logging. Globally, the OSGi service com.adobe.granite.contexthub.impl.ContextHubImpl controls the toolbar and debugging for every site. A run-mode-specific config in your ui.config module keeps the toolbar on author:
// ui.config/src/main/content/jcr_root/apps/wknd/osgiconfig/config.author/
// com.adobe.granite.contexthub.impl.ContextHubImpl.cfg.json
{
"com.adobe.granite.contexthub.show_ui": true,
"com.adobe.granite.contexthub.debug": false
}
For publish, the same configuration page recommends silent mode, which suppresses all debug information and overrides the debug setting of every configuration.
Stores and UI modules
A store is an instance of a store candidate, and a UI module is the toolbar widget that shows a store. These are the samples AEM ships:
| UI module type | Store it shows | Store candidate |
|---|---|---|
contexthub.location | geolocation | contexthub.geolocation |
contexthub.browserinfo | surferinfo | contexthub.surferinfo |
contexthub.screen-orientation | emulators | granite.emulators |
granite.profile | profile | granite.profile |
contexthub.datetime | datetime | contexthub.datetime |
contexthub.tagcloud | tagcloud | contexthub.tagcloud |
contexthub.base | Any, set by its storeMapping property | None |
The table comes from Adobe's list of sample UI module types. Two more candidates have no module of their own: aem.segmentation, which loads your segments, and contexthub.generic-jsonp, which fetches data from a JSONP service. Custom stores extend one of the four base store types: PersistedStore, SessionStore, JSONPStore and PersistedJSONPStore.
Your own scripts read stores through the ContextHub JavaScript API. This client library snippet shows the visitor's latitude in an element and refreshes it whenever the store updates:
(function () {
'use strict';
var geo = ContextHub.getStore('geolocation');
if (!geo) {
return; // store not in this site's configuration
}
function showLatitude() {
var el = document.querySelector('.wknd-latitude');
if (el) {
el.textContent = geo.getItem('latitude') || '';
}
}
geo.eventing.on(ContextHub.Constants.EVENT_STORE_UPDATED, showLatitude, 'wknd-latitude');
showLatitude();
}());
The third argument to on() names your handler.
Segments and audiences
A segment is a rule over store data. First allow segments for the site: the Adobe tutorial on setting up ContextHub enables ContextHub Segments for the configuration in the Configuration Browser. Then build them in the Audiences console:
- Go to Navigation > Personalization > Audiences and select your site's configuration.
- Select Create, then give the segment a title and, optionally, a boost between 0 and 1000000, which Adobe calls a weighting factor.
- In the segment editor, drag in AND and OR containers, comparisons and references to other segments or scripts. Give every comparison a data type. Untyped comparisons follow JavaScript's loose rules, and Adobe's segmentation page warns that the results of such loosely typed checks can be misleading.
- Open a page in Preview, open the ContextHub toolbar, switch personas and check that the segment resolves.
The segment editor doesn't detect circular references. Segment A referencing B, which references A, saves without complaint, so keep references one level deep where you can.
Targeting a component in Targeting mode
With segments in place, authors decide what each audience sees. Adobe's steps for authoring targeted content, shortened:
- Open the page and choose Targeting from the mode menu in the toolbar.
- Pick a Brand, then select + next to Activity and name the activity. As targeting engine choose ContextHub (AEM).
- Select Start Targeting. You need to be in the Target Activity Authors group for this.
- In the Audiences pane, use + Add Experience Targeting to add an experience for each segment.
- Select a component on the page and choose the Target icon. Its current content becomes the default experience. Switch to each other experience and change the content there.
- Under Goals & Settings, set when the activity starts and ends and its priority (Low, Normal or High).
If the same block of targeted content appears on many pages, build it once as an Experience Fragment and target that instead.
ContextHub with Adobe Target
The targeting engine is chosen per activity. With Adobe Target selected, AEM sends visit data to Target, audiences come from Target, and you can run A/B tests with traffic splits and goal metrics, which ContextHub activities don't have. If a page has an Adobe Target cloud configuration, AEM preselects Target. One rule from Adobe's personalization overview shapes the plan: a single page can't use both engines at once, though different pages of one site can.
For rules over data the browser already has, such as location or device, ContextHub works without any integration. For A/B testing, goal reporting and audiences managed in Target, use Target, and treat ContextHub as the author's preview tool.
Is ContextHub supported in AEM as a Cloud Service?
Yes. Adobe's ContextHub pages (configuration, adding it to pages, the API, segmentation) all apply to AEM as a Cloud Service, and the personalization overview still presents ContextHub as AEM's built-in engine without a deprecation note. The setup above is the same on Cloud Service and AEM 6.5, apart from the configuration paths.
Edge Delivery Services pages aren't rendered by AEM page components, so the HTL include above has nowhere to go. For audiences and experiments on Edge Delivery, Adobe publishes the aem-experimentation plugin, where an audience is a JavaScript function evaluated in the browser, and a tutorial on using Adobe Target audiences in Edge Delivery Services. If you haven't picked a delivery model yet, see how Edge Delivery and classic AEM Sites fit together in the AEM as a Cloud Service guide.
More in The wider Adobe stack
- What Is AEP? Adobe Experience Platform FAQ
What Adobe Experience Platform is, how it's built, and which of its application services connect to AEM.
- Understanding Adobe Workfront and Its Use with AEM
What Adobe Workfront is, its capabilities, its AEM Assets integration, licenses and access levels, SSO, third-party integrations, the API and Workfront Fusion.
- Adobe InDesign vs FrameMaker vs AEM Guides (XML Documentation)
InDesign, FrameMaker and AEM Guides compared on authoring, formats, scale, review and AEM integration.