Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

delivering a different response based on region

prohira
Level 4
Level 4

We have a multi-national website. We want to load two JS files let's say test1.js and test2.js on our website based on the user location. The user location is being detected using Akamai EdgeScape headers. Let's say if the user location is China, we want to load test1.js otherwise test2.js should load on the page. The requirement is to load these JS files on server-side, not client-side. These JS files will be included at template level so that they are present in every page on the website.

The problem is: Let's say a user in Country A requests a page /abc.html, the page is served; cached at dispatcher and cached at Akamai edge server (near to user's location) with test2.js present in page source. Now another user requests the same page /abc.html, from China. The page is not available in Akamai edge server (near to user's location i.e. China), so Akamai edge server is going to fetch the page from dispatcher and dispatcher is going to serve the cached page which has test2.js in cache and this defeats the whole purpose.

Points:

1) We can't disable caching pages at dispatcher because it is not one page we are talking about, it's whole site.

2) The file can't be loaded on the client-side because of some purpose.

Thanks in advance!!

1 Accepted Solution
kautuk_sahni
Correct answer by
Community Manager
Community Manager

It is recommended to Embed 1 code per website with different rules/logic inside of that.Any sort of wrapper with conditional logic to decide which DTM embed code to use would 1) introduce

Any sort of wrapper with conditional logic to decide which DTM embed code to use would

1) introduce delays in the process

2) technically not supported

~kautuk

View solution in original post

9 Replies
smacdonald2008
Level 10
Level 10

You are referring to AEM personalization. To work with Geo Data - you can use ContextHub and segments. See this article:

Scott's Digital Community: Using the ContextHub with the Experience Manager Toy Store site

You can load different components/clientlibs (which load JS files) for a page based on Geo data.

Also - you can load different Experience Fragments too based on the audience - which can be different locations:

Working with Experience Fragments and the Experience Manager ContextHub 

prohira
Level 4
Level 4

Hi Scott,

I need to load the JS (test1.js or test2.js) in head section. Would it be possible thru Context Hub/Personalization? FYI: these JS files are DTM JS, if that makes any difference.

kautuk_sahni
Community Manager
Community Manager

You can achieve this personalization by:

1. AEM Context Hub Working with Experience Fragments and the Experience Manager ContextHub

// The implementation usage is not same as DTM, it is not used for uploading JS on the page. For uploading JSs use DTM.

2. AEM Target engine (similar to Context Hub)

3. Using Adobe Target with AEM via DTM Adobe Experience Manager Help | Integrating Adobe Experience Manager with Adobe Analytics and Target...

// Via DTM you can certainly load any number of scripts.

~kautuk

prohira
Level 4
Level 4

Hello Kautuk,

I forgot to mention, we are using AEM 6.1, so Experience Fragment doesn't fit here.

The issue is how to load appropriate DTM JS file in the head section. You are right, "via DTM we can certainly load any number of scripts" but here I am looking to load different DTM JS files based upon user location.

Thanks.

kautuk_sahni
Community Manager
Community Manager

I am not sure about OOTB, but you can certainly upload JS conditionally.

Example :- html - Conditionally load JavaScript file - Stack Overflow

But, why not to upload 1 JS file and keep logic in it?

~kautuk

kautuk_sahni
Correct answer by
Community Manager
Community Manager

It is recommended to Embed 1 code per website with different rules/logic inside of that.Any sort of wrapper with conditional logic to decide which DTM embed code to use would 1) introduce

Any sort of wrapper with conditional logic to decide which DTM embed code to use would

1) introduce delays in the process

2) technically not supported

~kautuk

View solution in original post

nasrinj31078225
Level 2
Level 2

Hi @prohira ,

 

How you fetched Akamai EdgeScape headers in AEM/Java code.

We tried by simply fetching headers, but it's not working.

prohira
Level 4
Level 4
You need to modify your property in akamai and add a rule/behavior for Content Targeting (EdgeScape). Once you do that, you can simply use request.getHeader("x-akamai-edgescape") to get the value.
nasrinj31078225
Level 2
Level 2

Hi @prohira ,We are trying to fetch with same, but it's not appearing. We are able to see the header in dispatcher log. But not via JS or Java code.