Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to use information from JSONPStore on segments resolution

Avatar

Level 2

Hi, all.

I need to use information from a JSONP Store to resolve segments, but it seems that I am missing some important step. The steps I am following were taken from http://dev.day.com/docs/en/cq/current/developing/client_context_detail.html, but I have to confess that I got lost at some point.

Here are the steps:

[img]client-context-editing.png[/img]

  • Now, when I open the page, the information displayed on the JSONPStore is not equal to the information that was displayed on the client context edit (see that there's a "No Address/Continent" instead of the "South America").for the continent is blank.

[img]client-context-on-page.png[/img]

I do believe (maybe it's even obvious) that I am missing something before the last step. Should I have some code to load/refresh the information of the JSONP store on the page, or to register this store? Where can I find a sample? 

Once this information is loaded, I think I'll be able to use that to resolve my segments. But now I am stuck on this phase.

Any help will be greatly appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

If 5.6.1 there was a bug. Overlay [1] & line 30 replace to have [2]. If does not help file a daycare & will help you out.

[1]   /libs/cq/personalization/components/contextstores/jsonpstore/init.js.jsp

[2]     CQ_Analytics.JSONPStore.registerNewInstance("<%= xssAPI.getValidJSToken(store, "") %>", "<%= xssAPI.encodeForJSString(serviceURL, "") %>", {});

View solution in original post

7 Replies

Avatar

Level 8

Have you included the client context libraries in your page header? That should be all that you need to do if you are using an out-of-the-box client context component.

<cq:include path="clientcontext" resourceType="cq/personalization/components/clientcontext"/>

FYI, An example of using JSONP Store component is on this page:

https://dev.day.com/docs/en/cq/current/administering/client_context.html#Storing%20Data%20in%20Clien...

scott

Avatar

Correct answer by
Level 10

If 5.6.1 there was a bug. Overlay [1] & line 30 replace to have [2]. If does not help file a daycare & will help you out.

[1]   /libs/cq/personalization/components/contextstores/jsonpstore/init.js.jsp

[2]     CQ_Analytics.JSONPStore.registerNewInstance("<%= xssAPI.getValidJSToken(store, "") %>", "<%= xssAPI.encodeForJSString(serviceURL, "") %>", {});

Avatar

Level 10

I will walk through this doc and see if i can reduplicate the issue you encountered. It should work as written in the doc. 

Avatar

Level 10

Also -- there was a comment in the docs (See below). Did you add this code to your sample? 

By Asif - 10:09 PM on Feb 13, 2014   Reply
Anyone who is/was struggling with following the tutorial where geoloc data would not show up in the client context may want to try this.

There was one important line of code missed in step 2 of :RENDER THE GEOLOC SESSION STORE DATA" section

Make sure you add following line at the top of geloc.jsp before proceeding with step 2.

<%@taglib prefix="personalization" uri="http://www.day.com/taglibs/cq/personalization/1.0" %>

Avatar

Level 2

Hi, Sham HC.

Sorry for the long delay for posting back in here. Your suggestion worked perfectly, as I am using AEM 5.6.1. Thanks A LOT for ending my suffering :)

But the bad part is that for fixing it I'll need to change a core file of AEM.

Is this fix part of a hotfix or something like that?

Regards and thanks again.

EDIT - just to make it clear for someone that may read this topic in future: after applying the fiz on AEM code suggested above, I just needed to drag & drop a a) JSONPStore to the client context, b) configure it with the service URL and variables to be retrieved, and on the segments edit page c) drag & drop e Generic Properties component to the segment edit, d) find my store (note: the name that is generated automatically is not friendly, something like "localhost_4502", and I'd like to be able to edit it...) and work with its variables.

The only code I needed to include on my template was a line <cq:include path="clientcontext" resourceType="cq/personalization/components/clientcontext"/>, no custom JavaScript added to the page.

Avatar

Level 2

Hi, smacdonald2008.

Thanks for your help.

I included this taglib declaration on my JSPs and it didn't help, but from what I could understand the personalization: taglib is used for displaying store information on client context when we customize this information display.

But there may be a huge between my understanding and the actual role of this tag :)

Shouldn't I include some CQ_Analytics.<function call> on my pages to initialize/instantiate the store?

Avatar

Level 10

Yes -- the CQ_Analytics.<function> is used in this use case. This code is shown in the doc:

<%@page contentType="text/javascript;charset=utf-8" %><%
%><%@include file="/libs/foundation/global.jsp"%><%
log.info("***** initializing geolocstore ****");
String store = "locstore";
String jsonpurl = "http://api.wipmania.com/jsonp?callback=${callback}";
 
%>
var locstore = CQ_Analytics.StoreRegistry.getStore("<%= store %>");
if(!locstore){
    locstore = CQ_Analytics.JSONPStore.registerNewInstance("<%= store %>", "<%= jsonpurl %>",{});
}
<% log.info(" ***** done initializing geoloc ************"); %>