Tuesday, 11 June 2019

Disable location tracker in AEM

Location tracker popup is annoying when page is loaded. This is enabled by default when clientcontext is used. 

Steps to disable location tracker:

  • Copy clientcontext component /etc/clientcontext/default to /etc/clientcontext/custom
  • Open this new component and delete the geolocation component.
  • Map this new component path to your design path ex: /etc/designs/default/jcr:content/homepage
We can see location tracker is disabled for specific site now.

Sunday, 13 January 2019

Targeting content in AEM

AEM enables to target content for different audience.

This post will explain how to target title component to display content based on user's location and do A/B testing.

Create a web page called Target under we-retail website.


Click here to check how to enable ContextHub.
Navigate to AEM instance and create Brand and activities. 


Saturday, 12 January 2019

Cannot read property 'extend' of undefined': ContextHub

While adding ContextHub to AEM site could see below errors

Change ContextHub entry in head section from 
<sly data-sly-resource="${'contexthub' @ resourceType='granite/contexthub/components/contexthub'}"/>

to 

!--/* Include Context Hub */-->
<sly data-sly-call="${clientlib.js @ categories='granite.utils'}"/>
<sly data-sly-resource="${'contexthub' @ resourceType='granite/contexthub/components/contexthub'}"/>


Click here to check how to setup ContextHub in AEM.

Using script reference in AEM ContextHub

While creating audience in AEM contextHub, we see a component called Script Reference. When we drag-n-drop the component, we don't see any scripts by default in the drop down.


Wednesday, 9 January 2019

URL Shortening in AEM

Content pages in AEM start with path /content/. It is best practice to hide /content/site in the URL.

Below configs show how to achieve URL shortening on both AEM server and dispatcher.

Configs on AEM Server:

·         There are many ways to configure the rewrites on publish server. e.g. Resource Resolver, Vanity URLs, Sling mapping.
·         Configuring the Apache Sling Resource Resolver Factory is one of the ways to configure rewrites. This service needs to be configured on the publish server so that if someone hits the publish server directly; we see the correct rules applied there.
Make sure that the publish server has the below configuration applied


Sunday, 6 January 2019

Backend forbids caching, sent: 'Dispatcher: no-cache'

When using dispatcher if we use below code then pages will not be cached in dispatcher. Error in dispatcher.log is "Backend forbids caching, sent: 'Dispatcher: no-cache'"

response.setHeader("Dispatcher", "no-cache");                       
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setDateHeader("Expires", 0);