Adding custom contextstore to the clientcontext | Community
Skip to main content
New Participant
October 16, 2015
Solved

Adding custom contextstore to the clientcontext

  • October 16, 2015
  • 7 replies
  • 2903 views

Hi,

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Scott_Brodersen

I haven't used that tutorial, but the AEM docs has information on creating stores and interacting with them:

http://docs.adobe.com/docs/en/aem/6-0/develop/personalization/client-context.html#Extending Client Context
http://docs.adobe.com/docs/en/aem/6-0/develop/personalization/client-context.html#Interacting%20with%20Session%20Stores

Javascript API reference: http://docs.adobe.com/docs/en/aem/6-0/develop/personalization/ccjsapi.html

hope that helps,
Scott

7 replies

Employee
October 16, 2015
Scott_Brodersen
Scott_BrodersenAccepted solution
New Participant
October 16, 2015
New Participant
October 16, 2015

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.

October 16, 2015

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.

New Participant
October 16, 2015

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.

October 16, 2015

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.

New Participant
October 16, 2015

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.