VIEW events
The VIEW event tracks when the site visitor views a webpage in your app. It triggers every time your webpage loads. Because it is an essential event to track, it's important that you send VIEW events from all webpages where you want to track site visitor behavior.
JSS Next.js and JSS Angular apps automatically capture VIEW events, with no coding required.
By default, the VIEW event triggers when a webpage loads, but not when a route changes. To capture VIEW events in response to a route change, send the events using the routing tools of your framework:
-
Next.js App Router - use an effect when the value returned by
usePathnamechanges. -
Next.js Pages Router - send the events in
routeChangeComplete.
Contributed by:
Boris Brodsky
You can send VIEW events by using the pageView function and optionally passing it the page view event data object.
The page view event data object
The page view event data object represents all the data about the event.
The page view event data object is optional, but we recommend that you provide it so you can also provide the following optional data in it:
-
Data such as the channel and the language of the page where the event triggered, the referrer URL, UTM parameters, and whether the event triggered on a SitecoreAI personalized page variant.
-
The search data object. If you provide this object, the event becomes a Sitecore Search entity page view event, and the event with all its data is sent to Sitecore Search.
NoteRefer to the Sitecore Search Events API reference and data model to construct search data objects.
Examples
During development, use your web browser's developer tools to check the payload containing all the event data that is sent to Sitecore.
Here's an example page view event data object for a VIEW event. The object contains some optional event data and extension data:
This object is passed to the pageView function, which sends the event:
By default, VIEW events include UTM parameters. Consider the following URL:
A VIEW event captured on the previous URL will contain all the UTM parameters in the event data. The event data object associated with this URL contains the following payload:
Here's an example page view event data object for a VIEW event. The object contains some optional event data, extension data, and search data:
You can send this event by passing the object to the pageView function:
For this event data object, the following payload is sent to Sitecore: