Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Unexpected behaviour of datastore events in ContextHub.

Avatar

Level 2

Hello,

I've started working on the new ContextHub feature recently for personalizing content. I'm achieving localization based on a territory hierarchy and personalizing the content based on what territory the end user belongs to. The OOTB GeoLocation data store doesn't satisfy my exact requirement as territory names in my project aren't standard and thus I have created a custom data store which fetches the current country from GeoLocation datastore and passes it to a back-end API which returns its corresponding territory name, which serves as selection criteria for my audiences. I also use Profile datastore to fetch more user related info like language preference and use it to personalize it further.

Problems:

  1. Since I'm dependent on two OOTB data stores, I'm updating my datastore if any of these two data stores get updated by utilizing the event 'ContextHub.Constants.EVENT_STORE_UPDATED' using the following syntax as given in documentation:

    var geostore = ContextHub.getStore("geolocation");
    geostore.eventing.on(ContextHub.Constants.EVENT_DATA_UPDATE,customUpdateHandler,"handleUpdate");

    But, binding this event to any data store seem to bind it to all the data stores available and any updation in a completely irrelevant store, like OrderHistory, causes the handler to be called. I expected the event to be binded with only the store whose reference is used to call the on() method. This is causing my handler to be called on initialization of every store too when I expected it to be called for just 2 data stores.
    Similar behavior was observed with ContextHub.Constants.EVENT_STORE_REGISTERED and ContextHub.Constants.EVENT_STORE_READY events too.
    I expected this behavior on registering the events via ContextHub.Utils.Eventing.on() where no particular datastore is specified.
    Can you please help me understand the reason for this behaviour if this was expected? Or is my understanding not correct? Can you suggest a better way to achieve this?

  2. I'm also initializing my data store once the other data stores are ready using the event, ContextHub.Constants.EVENT_ALL_STORES_READY, but the handler never seems to be called and thus I don't understand when does this event trigger. I expected it to be called after all stores have been initialized and become available.
    May be I don't seem to understand its correct usage. Can you let me know its correct usage or any other event that can serve this purpose?
    Are there any events, other than those mentioned in the documentation?

The custom data store that I created is a PersistedStore with the default local storage persistence.

Any help is appreciated.

Thank you.

3 Replies

Avatar

Level 10

Are you following an online doc to build your custom store? If so - provide the URL to see if your issue is reproducible.

Avatar

Level 2

smacdonald2008 I'm following the official documentation to create my custom data store: Extending ContextHub and ContextHub Javascript API Reference

Avatar

Administrator

I Would recommend seeing this webinar:- ATACE Sept 26 2017 - Context Hub

// This is about Best practices for working with ContextHub in Adobe Experience Manager

ContextHub is a framework for storing, manipulating, and presenting context data. The client-side JavaScript API enables you to access the data for personalizing content.

This will certainly help you create store, model and gets the personalization going.

~kautuk



Kautuk Sahni