Expand my Community achievements bar.

SOLVED

How to set currentSession object attribute values like id, name, zipcode within javascript of my header file?

Avatar

Level 2

I am planning to use currentSession HTL Global object to get user related information. And pass that to analytic javascript  file included within my customheader file.

1. I wanted to know how can I setup currentSessoin object attribute value like (id, name, zipcode) in javascript before I actually passed it to analytic script?

 2. Also how to retrieve the same set of attributes in javascript for setting up & passing to analytic array object.

 

currently i am getting values only for this method

alert('${currentSession.attributeNames @ context="scriptString"}');

output is: ip,oak.bound-principals,oak.relaxed-locking,referer,useragent

 

 

 

 

 

I have one more query regarding, how can i Overlay my files form /libs folder to my project folder under /apps.

If I do rightclick & do overlay then it moves inside /app/core. but I wanted to move that into /app/project folder structure. If I copy & move these files under my specific project folder inside apps, will it work? 

 

Kindly share any inputs on above mentioned queries.

 

 

 

 

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

If you want to follow that approach, you have 2 aspects to consider:

 

  1. You have that data in your AEM repository. Do you really want to have that? In many cases this data is considered PII and with it comes a ton of work to protect it ...
  2. You render this information into the resulting output. That means that this data is always rendered by AEM and the page can never be cached. Depending on the scale of your application this can be a serious problem, because that approach won't scale at all.

 

If you just want to collect that information for Analytics purposes, why don't you capture and keep all that potentially sensitive information on the client side in the browser?

 

(To answer the question: On publish side the users are normally anonymous and are not logged in. There is no data stored for them. In your case you would require all users to authenticate and have the datapoints like name and zipcode stored in the repository. Then the session is personalized and you could fetch that information from the profile. But as already outlined above, I don't think that this is worth to implement just for analytics.)

 

 

 

 

View solution in original post

6 Replies

Avatar

Correct answer by
Employee Advisor

If you want to follow that approach, you have 2 aspects to consider:

 

  1. You have that data in your AEM repository. Do you really want to have that? In many cases this data is considered PII and with it comes a ton of work to protect it ...
  2. You render this information into the resulting output. That means that this data is always rendered by AEM and the page can never be cached. Depending on the scale of your application this can be a serious problem, because that approach won't scale at all.

 

If you just want to collect that information for Analytics purposes, why don't you capture and keep all that potentially sensitive information on the client side in the browser?

 

(To answer the question: On publish side the users are normally anonymous and are not logged in. There is no data stored for them. In your case you would require all users to authenticate and have the datapoints like name and zipcode stored in the repository. Then the session is personalized and you could fetch that information from the profile. But as already outlined above, I don't think that this is worth to implement just for analytics.)

 

 

 

 

Avatar

Community Advisor

In addition to @Jörg_Hoh point.

 

If you have a dispatcher and pages are cached (which should be the case), then data will only be available for the first user.

You can implement a service/api that isn't cached and brings you the user data from AEM/Other systems. You can use it for analytics or display the data on pages etc.



Arun Patidar

Avatar

Level 2

Thank you @Jörg_Hoh  & @arunpatidar for the response.

Actually the data will be fetch from third party database at backend through API call ( java servlet) & then will be set in currentSessoin object at backend.

Now its requested to get that data at front end through sightly HTL object. We need to encode that data & pass it on to analytic.

 

As of now at backend/java end functionality is not ready with currentSession object values.

So its requested to set currentSession object attribute encoded value temporary at sightly end (inside javascript) & pass it to analytic.

 

So I was looking for some inputs on how to set these currentSession attribute values inside sightly javascript . And then fetch the same to pass into analytic.

 

 

 

 

Avatar

Community Advisor

Hi @M1093057 
Do not set this value in Sightly. The reason is once you request a page the page get cached at dispatcher with the user details and get served for all the other users for subsequent requests.



Arun Patidar

Avatar

Level 2

@arunpatidar : Yes. I have tried to explore multiple option but nothing is working to set data in sightly (temporary purpose). I guess I will have to set data into model & pass that to sightly. Hope this code will work.

 

 

 

Model code:
@Model(adaptables = SlingHttpServletRequest.class)
public SessionModel {

@ScriptVariable
private Session currentSession;

public String getMySessionAttribute() {
return this.currentSession.getAttribute("attributeName");
}
}

 

sightly page code:

<div data-sly-use.sessionModel="com.mypackage.SessionModel"> ${sessionModel.mySessionAttribute}
</div>

 

Avatar

Employee Advisor

when you use the term "currentSession", what do you mean with it? Is it a JCR session? Or is it a HTTPSession?