Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Adding custom contextstore to the clientcontext

Avatar

Level 4

Hi,

I am using AEM 6. How do I added a custom created contextstore to the clientcontext.

1 Accepted Solution

Avatar

Correct answer by
Level 8
7 Replies

Avatar

Correct answer by
Level 8

Avatar

Level 4

I am following the same tutorial and the issue I am facing is with session store. Here on the line 

var authorizableId = CQ_Analytics.ProfileDataMgr.getProperty("authorizableId");

The value of authorizableId is anonymous and I tried the have the output of CQ_Analytics.ProfileDataMgr.getProperty("authorizableId") on console using Console.log. Looks like the CQ_Analytics object is not getting instantiated. I added clientcontext under the body tag. So, I am thinking that maybe I will have to add custom contextstore to the clientcontext. But since this is not defined in the tutoral, I am confused.

Avatar

Former Community Member

AEM newbie wrote...

 

The value of authorizableId is anonymous ...

 

Did you try loading a profile into the client context? Once you load a profile into the client context, and refresh the page, you should get the value of the profile you loaded instead of anonymous.

Avatar

Level 4

Hey thanks for response and I am able to get the value of authorizableId now. But there are still two troublesome issues:

1) The value of CQ_Analytics.CustomStoreMgr.currentId which is not printing at all.

2) The value of CQ_Analytics.CustomStoreMgr.initialized which is false.

Any pointers would be really helpful.

Avatar

Former Community Member

I am glad to hear you got the value of authorizableId to work. Unfortunately, I have not been able to get their code to work right out of the box. I was able to get currentId, and CQ_Analytics.CustomStoreMgr.initialized to work by using this code in the customstore.js file:

// Create the session store called "customstore" if (!CQ_Analytics.CustomStoreMgr ) { // Create the session store as a JSONStore CQ_Analytics.CustomStoreMgr = CQ_Analytics.JSONStore.registerNewInstance("customstore"); var currentId = ""; // Function to load the data for the current user CQ_Analytics.CustomStoreMgr.loadData = function() { console.info("Loading CustomStoreMgr data"); var authorizableId = CQ_Analytics.ProfileDataMgr.getProperty("authorizableId"); var url = "/apps/customstore/components/loader.json"; url = CQ_Analytics.Utils.addParameter(url, "authorizableId", authorizableId); try { var object = CQ.shared.HTTP.eval(url); if (object) { this.data = object; } } catch(error) { console.log("Error", error); } currentId = authorizableId; }; }

Now if you view the page and run the loadData() function, you should be able to get these two things to work. If you call CQ_Analytics.CustomStoreMgr.initialized it should return a value of true, and if you call "currentId" instead of CQ_Analytics.CustomStoreMgr.currentId, it should return the value of the profile you loaded.

Avatar

Level 4

Hey thanks a lot for that. So just to confirm is this the only piece of code I need to get the code working ? Do I need to include this if check:

if ( (authorizableId !== CQ_Analytics.CustomStoreMgr.currentId) & CQ_Analytics.CustomStoreMgr.initialized ) {

Also, there are some listeners added in Step 7. Do we also need them ?

Thanks again.