---
title: Coveo Page View Analytics
slug: '3013'
canonical_url: https://docs.coveo.com/en/3013/
collection: coveo-for-sitecore-v5
source_format: adoc
---
# Coveo Page View Analytics

> **Legacy feature**
>
> The Coveo Hive Framework is now in maintenance mode and is no longer recommended for new implementations.
>
> To build new search experiences, use one of Coveo's more modern, lightweight, and responsive libraries.
> To get started, see the [Build search](https://docs.coveo.com/en/2473.md) article.

![Coveo for Sitecore Specific Rendering](c4sc-v5/sitecore-20-px-new.png)
The **Coveo Page View Analytics** rendering leverages the [coveo.analytics.js](https://github.com/coveo/coveo.analytics.js) module to record view events in the [Coveo Usage Analytics service](https://docs.coveo.com/en/l3bf0598.md).
The rendering adds a JavaScript code snippet to the current page.

The [Coveo Machine Learning (Coveo ML)](https://docs.coveo.com/en/188.md) [content recommendations](https://docs.coveo.com/en/1016.md) feature relies on view usage analytics event data and is enhanced with [user context](https://docs.coveo.com/en/2360.md).

> **Important**
>
> Coveo is deprecating version 1.0 of the `coveoua.js` file in the [coveo.analytics.js](https://github.com/coveo/coveo.analytics.js) module.
> Version 1.0 of the `coveoua.js` file will no longer record page view analytics.
> You must upgrade to `coveoua.js` version 2.
>
> From the [May 9, 2023 release](https://docs.coveo.com/en/n3ne0564.md) of Coveo for Sitecore onward, the **Coveo Page View Analytics** rendering uses `coveoua.js` version 2.
> Upgrade to the May 9, 2023 release or later to benefit from this change.

## Usage notes

* Whereas the [**Coveo for Sitecore Analytics**](https://docs.coveo.com/en/2186.md) rendering tracks events that take place in a search interface (for example, selecting a facet, performing a keyword search, or clicking a search result), the **Coveo Page View Analytics** rendering is meant to track view events in website content pages.

* For further details regarding the combined use of the **{doctitle}** and [**Coveo User Context**](https://docs.coveo.com/en/3069.md) renderings to add user context in your Sitecore article items, see [Leverage user context for Coveo Machine Learning](https://docs.coveo.com/en/2360.md).

* Analytics events are only sent to the Coveo Analytics service when viewing the published site.
Actions performed when viewing site pages in the **Experience Editor** or in **Preview Mode** aren't recorded in the Coveo Analytics service.

* In the [Coveo Administration Console](https://docs.coveo.com/en/183.md), view events are displayed under the **Event browser** tab on the [**Data Health**](https://platform.cloud.coveo.com/admin/#/orgid/usage/health/) ([platform-ca](https://platform-ca.cloud.coveo.com/admin/#/orgid/usage/health/) | [platform-eu](https://platform-eu.cloud.coveo.com/admin/#/orgid/usage/health/) | [platform-au](https://platform-au.cloud.coveo.com/admin/#/orgid/usage/health/)) page.

  ![The Data Health page | Coveo](https://docs.coveo.com/en/assets/images/c4sc-v5/data-health-for-view-events.png)

## Insertion location

+
<div>
<h3>Coveo Hive</h3>
  
The **Coveo Page View Analytics** rendering is an Allowed Control in the following placeholder(s): `UI Resources`

  <video width="690" height="335" controls="">
  <source src="https://docs.coveo.com/en/assets/images/c4sc-v5/page-view-analytics-hive.mp4" type="video/mp4" />
  Your browser doesn't support the video tag.
</video>
  <div class="figure-caption">Example insertion sequence where a `PageViewPlaceholder` placeholder was added directly to the article MVC layout `.cshtml` file. The Allowed Controls of this placeholder were set to enable insertion of the **Coveo Page View Analytics** rendering.
  </div>
</div>
<div>
<h3>Coveo Hive SXA</h3>
  
Coveo for Sitecore SXA rendering insertion locations aren't limited by placeholder Allowed Controls. The **Coveo Page View Analytics** rendering may therefore be inserted throughout the partial design.

  <video width="690" height="335" controls="">
  <source src="https://docs.coveo.com/en/assets/images/c4sc-v5/page-view-analytics-sxa.mp4" type="video/mp4" />
  Your browser doesn't support the video tag.
</video>
  <div class="figure-caption">Example insertion sequence for the **Coveo Page View Analytics** rendering.
  </div>
</div>
+

## Data source options

The following table lists the available data source options for this rendering.

| Option name | Description |
|---|---|
| Content type | Allows selection of a Sitecore `tag` item located under the `sitecore/system/settings/buckets/TagRepository` content tree folder. |
| Coveo Page View Analytics properties | Key-value metadata pairs to log with the page view event. > **Important** > > To log user context metadata for the purpose of enriching a [Coveo Machine Learning (Coveo ML)](https://docs.coveo.com/en/188.md) [Content Recommendation (CR)](https://docs.coveo.com/en/1016.md) [model](https://docs.coveo.com/en/1012.md), use `Custom context` key-value pairs in the [**Coveo User Context**](https://docs.coveo.com/en/3069.md#data-source-options) rendering data source. |

## Sample generated HTML and corresponding visual output

```html
<script>
    // Code snippet to load and log page view analytics.
    // Imported from https://github.com/coveo/coveo.analytics.js
    (function (c, o, v, e, O, u, a) {
        a = 'coveoua'; c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };
        c[a].t = Date.now(); u = o.createElement(v); u.async = 1; u.src = e;
        O = o.getElementsByTagName(v)[0]; O.parentNode.insertBefore(u, O)
    })(window, document, 'script', 'https://static.cloud.coveo.com/coveo.analytics.js/2/coveoua.js');

    document.addEventListener("CoveoSearchEndpointInitialized", function () {
        var accessToken = Coveo && Coveo.SearchEndpoint && Coveo.SearchEndpoint.defaultEndpoint && Coveo.SearchEndpoint.defaultEndpoint.accessToken
            ? Coveo.SearchEndpoint.defaultEndpoint.accessToken.token
            : "";

                var customMetadata = {"custom1key" : "custom1val" , "custom2key" : "custom2val" , "contentIdKey" :
                "permanentid" , "contentType" : "Beginner" , "contentLanguage" : "en" , "contentIdValue" :
                "FC9CAA002F21400DB03F91EB610AACC9" , "anonymous" : true};

        if (typeof (CoveoForSitecoreUserContext) !== "undefined") {
            customMetadata["customData"] = {};
            var currentContext = CoveoForSitecoreUserContext.handler.getContext();
            Object.keys(currentContext).forEach(function(key) {
                customMetadata["customData"]["context_" + key] = currentContext[key];
            });
        }

        coveoua('onLoad', function() {
            Object.defineProperty(coveoanalytics.CoveoAnalyticsClient.prototype, 'baseUrl', { get() { return "/coveo/rest/ua" + "/v15" }});
            coveoua('init', accessToken);
            coveoua('send', 'view', customMetadata);
        });
    });

</script>
```

**Sample call to the analytics proxy endpoint**:

![Sample API call | Coveo for Sitecore 5](https://docs.coveo.com/en/assets/images/c4sc-v5/coveo-page-view-event-sample-api-call.png)