Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

delivering a different response based on region

Avatar

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

Avatar

Correct answer by
Administrator

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



Kautuk Sahni

View solution in original post

9 Replies

Avatar

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 

Avatar

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.

Avatar

Administrator

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



Kautuk Sahni

Avatar

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.

Avatar

Administrator

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

Avatar

Correct answer by
Administrator

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



Kautuk Sahni

Avatar

Level 3

Hi @prohira ,

 

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

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

Avatar

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.

Avatar

Level 3

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.