How to set currentSession object attribute values like id, name, zipcode within javascript of my header file? | Community
Skip to main content
Level 2
October 3, 2022
Solved

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

  • October 3, 2022
  • 2 replies
  • 1531 views

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.

 

 

 

 

 

 

 

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 joerghoh

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.)

 

 

 

 

2 replies

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
October 3, 2022

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.)

 

 

 

 

arunpatidar
Community Advisor
Community Advisor
October 3, 2022

In addition to @joerghoh 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
M1093057Author
Level 2
October 4, 2022

Thank you @joerghoh  & @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.

 

 

 

 

arunpatidar
Community Advisor
Community Advisor
October 4, 2022

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