Expand my Community achievements bar.

Conditionally loading CH libraries

Avatar

Level 4

Hello Community,

We're using contexthub in our project to personalize the content. Basically, I want to conditionally load the contexthub libraries only when the page (content) is configured with targeting. Whenever the component on the page is configured with targeting, I can see properties (accurateTargeting/location) being added as part of the component node, but I don't see any properties being added in the page's jcr:content. How can I check and load the libraries?


Also, I want to show the preview of the targeting (Persona) in the authoring environment. I can see the targeting resolution happening in the publish/Dispatcher environment, but I want to mimic the same behavior in the authoring environment(i.e selecting the options from the dropdown should resolve the segments and corresponding content should load it in the contexthub preview) so that the authors can preview the persona before publishing the page. Should I implement/introduce the clientlib and add it to the clientlib category (i.e. contexthub.module.sampleclient)? If so, can you share some custom implementation?

Additionally, I'm looking for an existing OOTB store that can detect the viewport of the end-users (i.e. Desktop/Tablet/Mobile). Do we have any existing stores we can leverage, or do we need to create a custom store for this use case?

1 Reply

Avatar

Community Advisor

Hi @test1234567 

For the first query you will probably have to come up with a script or a servlet call that will iterate through the content nodes and if it finds the specific property like accurate targeting/location then dynamically add the context hub libraries to the header via script .

For the last one i don't think we have any OOTB store to detect the viewport .

 

  • Create a custom ContextHub store that checks the window inner width and updates the store's state.
  • Configure the store to be included as part of your ContextHub configuration.

https://experienceleague.adobe.com/en/docs/experience-manager-65/content/implementing/developing/per...

 

Hope this helps