How to custom page view impression in AEM 6.0?

1.3k Views Asked by At

I see in AEM 6.0 that have a built-in component for page view statistic, displayed as impression column in author site admin. But this built-in does not support for filter the top page view in sites and so on. This one is useful for calculate page view for each page. I'm facing the performance problem for calculate top page view with more than thousand of pages. Anyone have a solution for this one ?. Many thanks and appreciate.

3

There are 3 best solutions below

1
On

While the impression data initially appears tempting, it is not meant for end-user page view analytics. The CQ integrations with SiteCatalyst, etc are meant for real analytics (or 3rd party solutions, such as Google Analytics).

If you consider the author displays impressions, 1+ publish instances would have to "reverse replicate" impression data back to the author, which would get pushed right back to publish instances.

When you consider the Apache Dispatchers serving up cached pages w/o passing the request to the publish instances, you can understand how even your production publish instances don't see all the traffic, either.

0
On

You can create a variant of the page with a selector. Something like: statistics.html.jsp in your page node, then:

http://example.com/a.html is the normal page http://example.com/a.statistics.html is the page that adds the statistics component.

1
On

Finding top 10 most viewed page or sorting all page based on their popularity using Impression service provided by CQ is a bit tricky because of following reasons

  1. It might possible that Page Views is in external system and then you want to import those data as impression in CQ to have more application context.
  2. you have to aggregate all data across all publish instances.
  3. It's Slow.

To calculate top page view with more than thousand of pages you have three options

  1. Creating your Own Impression service
    You can create your own impression service by extending com.day.crx.statistics.Entry. Then You can do all the optimizations.
  2. Adobe analytics: If you have thousands of pages then go with adobe analytics. It will give you the top results and other filtering options through their Rest Service.

  3. Modify the OOTB service implementation.

You don't want to write your own service but wanted to use OOTB service available to you. Only problem with this is, You have multiple publish instance and some how you want to combine all data into one so that you get accurate picture. It kind of tricky to get all data from all publish instance (through reverse replication) and then combine them on author and then push them over again. However you can use one instance to collect all stat data (king of single source of truth and then replicate it back to all instance every day)

Make sure that you enable page view tracking by adding following line

       <cq:include script="/libs/foundation/components/page/stats.jsp" />

Then configure all publish instance to point to one DNS using following config (You can always override this under /apps) /apps/wcm/core/config.publish/com.day.cq.wcm.core.stats.PageViewStatistics /apps/wcm/core/config.publish/com.day.cq.wcm.core.stats.PageViewStatisticsImpl

make sure that pageviewstatistics.trackingurl is pointing to single domain (You need to create a domain, something like impression.mydomain.com that will be stand alone CQ instance to take all impression request) Now you have consolidated page impression on one machine You can easily write a scheduler which will run every night and reverse replicate all data to author instance. Once it is an author instance you can use replicator service to replicate to all other publish instance Then you can tweak some code as mentioned in the custom approach to get popular resources. For read more about the Custom implementation: Implementations instruction: