Expand my Community achievements bar.

Custom Analytics Data Reporting in AEM List View

Avatar

Level 2

10/10/22

Company Name:

Company URL:

Your Name: Venkatesh Sankaranarayanan

Your Title: AEM Architect

 

This work involves AEM and Analytics. And this work is based on requirement from one of my customers which is about  rendering custom analytics data in AEM list view. Customer wants this data to enable Authors to get right sense of page usage statistics and user interaction on pages.

 

 

How this requirement popped up: Customer has an AEM – Analytics implementation wherein AEM passes custom pageName to Analytics tracking object. Usually, by default, AEM sets pagename property value as ‘content: sitesection: site subsection: pagename’. And this is passed as part of tracking object. However, in this case, custom value is passed and analytics report is generated against these custom values.

As the pagename of Analytics data and default pagename of AEM is not same, AEM is not able to match the Analytics report data and render right values in AEM list view variables. So, every page of site shows the Analytics Out of the box metrics – pageViews, Timespent on page, unique visitors – as zero. And that is not helping customer in knowing the usage statistics of page and planning accordingly.

 

How to address this requirement:  To address this, following are required

  1. Custom eVar to set default content path for page
  2. Custom Polling Importer and related classes
  3. Custom OSGi configuration to render custom analytics data in JCR

 

The following diagram explains how AEM and Analytics work together to address this. Let us see each item of this diagram.

 

aem_analytics_custom_implmn_screenshot.png

Create custom eVar at Analytics:  This eVar is meant for capturing default content path of AEM page which is of format ‘content: sitesection: site subsection: pagename’.  This eVar is required, as OOTB element PageName contains custom value and not the default value.

 

Set eVar value at AEM :  Default pagename value is set using sitecatalyst.jsp available at /libs/cq/analytics/components/sitecatalyst. doPageTrack method of this JSP takes care of setting default pagename. This method needs to be updated to set custom eVar with default pageName.

 

  1. s.pageName="<%= xssAPI.encodeForJSString(pageName) %>"
  2.  s. eVar7=s.pageName

 

Once it is set, any AEM page, configured for Analytics tracking, would show this property (i.e eVar7) and appropriate value while loading. This can be verified using Developer console.

 

Custom eVar based Report: At analytics end, it can be verified whether custom eVar property is available with right value. Also, out-of-box metrics like pageviews can be checked for this custom element.

 

Custom Polling Importer: This is required at AEM end. AEM has 6 OOTB polling importer for Analytics data for collecting data pertained to 30 days / 90 days / 1 year. These importer implementations are designed to collect data only for default Analytics element – page on some scheduled configurable interval.

As the requirement is to collect data from custom element – eVar7, default importer classes would not help. So, custom importer class has to be created by implementing interface com.day.cq.polling.importer.Importer. Appropriate methods of this importer need to be overridden.

Primarily this importer service needs to be configured with custom value for SCHEME_PROPERTY.Element for which report needs to be generated needs to be passed as part of polling configuration.

This importer makes HTTP API call to Analytics, gets report in form of JSON Object.

Custom Managed Polling Configuration : As OOTB Polling configurations does not help in fetching custom importer, custom managed polling configuration needs to be defined which maps to the custom importer using SCHEME value.

This configuration needs to be an instance of

com.day.cq. polling.importer.impl.ManagedPollConfigImpl which allows to configure  the scheme, datasource and importing interval.

 

Custom Polling Configuration: Custom Polling configuration needs to be defined in /etc which maps to the custom managed polling configuration created in earlier step. Along with the mapping, it needs to define the target path where the imported data needs to be stored.

It is to be noted that OOTB Polling Configuration is automatically created for any site which is mapped to use Analytics cloud service. However, that OOTB configuration would take care of OOTB Polling Importer which would not fetch any custom analytics data.

If you would need Custom reporting data to reflect on OOTB Analytics columns , then the target path of custom polling configuration can point to any OOTB Polling configuration.

 

Custom ReportEntry class has to be created where relavent element name needs to be mentioned while preparing element. In this case, eVar7 should be used. By default, OOTB code would use the page element.

 

How this Solution Helps

This solution can  help customer to continue to have their own custom name for pages and still get analytics metrics for those pages without any limitation.

 

 

 

 

 

 

 

 

 

Aspire Analytics Experience Manager