Use Case:
Approach 1:
Creating your Own Impression service
You can create your own impression service by extending com.day.crx.statistics.Entry here is example
You need to embed following dependency for this
Here is example of how you can use this service
- You often have case where you want to use Impression service provided by CQ to do custom operation for example finding top 10 most viewed page or sorting all page based on there popularity.
- It might possible that your impression data (Page Views) is in external system and then you want to import those data as impression in CQ to have more application context.
- You want to aggregate all data across all publish instances.
Solutions:
Approach 1:
Supporting class
Here is example of how you can use this service
Once you are ready with all data you can use following service to use data,
Actual Implementation
Approach 2:
You don't want to write your own service as mentioned in Approach 1 and 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 in to 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 schedular which will run every night and reverse replicate all data to author instance.
- Once it is on author instance you can use replicator service to replicate to all other publish instance
- Then you can use code mention in approach 1 to get popular resources.
Note: You can always use GA or something to track data. This is more useful if you want to do something internally and not want top share data with GA.
As usual feel free to ask any question you have.