Hi @nick_2024
When implementing page view tracking for analytics with Adobe Experience Manager (AEM), it is important to select the appropriate event to ensure accurate page view counts. The documentation provided from the AEM Core Components library describes several events, including cmp:show and cmp:loaded, which can be used to trigger analytics tracking.
The cmp:show event is triggered on page load and is dispatched from in-line JavaScript immediately beneath the opening <body> tag, making it the earliest event in the Data Layer event queue. This event is particularly used in components like the accordion, carousel, and tabs when a user views or interacts with these components.
The cmp:loaded event is triggered as soon as the Data Layer is populated with the Core Components on the page. This event signals that all the initial components have been loaded onto the page.
In choosing between cmp:show and cmp:loaded for page view tracking, consider the following:
- cmp:show: Since this event is also dispatched on page load and is expected to be the first event, it can be a good candidate for tracking initial page views. However, if the same component is used multiple times on a page (e.g., in an accordion or tabs that can be expanded or collapsed), this event might trigger multiple times, potentially leading to over-counting page views.
- cmp:loaded: This event signifies that the page has fully loaded all its initial components. Using this event would ensure that the page view is counted once all components are ready, which might provide a more accurate count of page views.
It is important to note that if any of the components that trigger the cmp:show event are dynamic and can load content after the initial page load (e.g., lazy loading of tabs or additional content being loaded into an accordion), it could potentially trigger the event multiple times. This could indeed impact the page view count if not handled properly.
For precise page view tracking, you might want to:
- Use the cmp:loaded event to ensure the page view is counted once, after all initial components are fully loaded.
- Implement additional logic to ensure that cmp:show events triggered by user interactions after the initial page load do not count as additional page views.
It's also recommended to configure your analytics to differentiate between the initial page load event and subsequent interactions that may trigger the same events. Doing so will provide a more accurate representation of user engagement with the page.
For more information on the events triggered by AEM Core Components, you may refer to the official documentation: