Analytics

This is for:

Developer

By harnessing the Adobe Client Data Layer (ACDL) alongside Coveo’s advanced analytics capabilities, you can precisely track user interactions in both Coveo and Adobe Analytics, streamline data collection, and drive a more data-informed digital strategy. Whether you aim to optimize search, gain deeper insights into user behavior, or refine your overall analytics setup, this guide provides step-by-step instructions, code samples, and visual references to support your journey.

Send analytics data to Adobe Analytics

Sending analytics data to Adobe Analytics using the ACDL ensures that web interactions are captured precisely and efficiently. The ACDL is a lightweight JavaScript library that has transformed how data is collected and managed on websites. Integrated seamlessly with Adobe Experience Manager, the ACDL streamlines the orchestration of data across different components of a webpage. This simplification aids in the smooth implementation and optimization of web analytics, making data management more efficient.

Further enhancing this capability, the ACDL facilitates robust integration with Adobe Experience Manager solutions, including Adobe Analytics, Adobe Target, and various third-party applications. This integration is supported by a unified data structure, which not only streamlines the process but also reduces the likelihood of errors, thereby boosting system reliability and performance.

JavaScript code sample using Adobe Client Data Layer with Coveo Atomic

To track user interactions and send search analytics data from Coveo’s Atomic components to Adobe Analytics via ACDL, you need to integrate the ACDL with an Atomic search interface. If you’re not familiar with Atomic components, you can learn how to create a complete search interface by following this guide.

The following script demonstrates how to integrate the Adobe Client Data Layer with a Coveo Atomic search interface. Specifically, it: - Initializes an Adobe Data Layer to track search interactions. - Sends analytics events to Adobe Analytics when: - A user performs a search. - A user applies a search filter using a facet. - A user clicks on a search result.

//Coveo Atomic Script and Stylesheet
<script type="module" src="https://static.cloud.coveo.com/atomic/v3/atomic.esm.js"></script>
<link rel="stylesheet" href="https://static.cloud.coveo.com/atomic/v3/themes/coveo.css">

//Adobe Script from AE Manager Data Collection (Environment)
<script src="https://assets.adobedtm.com/f8b3xxdcee26/3aad9se59f55/launch-9xxxbbc8dd07-development.min.js" async></script>

<script>
//Initialize Adobe Data Layer
window.adobeDataLayer = window.adobeDataLayer || [];

async function main() {
  await customElements.whenDefined("atomic-search-interface");
  const searchInterface = document.querySelector("#search-interface");
  const organizationId = "<ORGANIZATION_ID>"; 1
  const accessToken = "<ACCESS_TOKEN>"; 2
  await searchInterface.initialize({
    accessToken,
    organizationId,
    analytics: {
      analyticsMode: 'legacy',
      analyticsClientMiddleware: async (eventName, payload) => {
        if (payload != null && payload.queryText != '' && payload.results != null) {
          [...]
          //adobe datalayer push event upon search performed
          adobeDataLayer.push({
            event: 'search:performed',
            component: {
              info: {
                name: 'internal search',
                searchType: searchType,
                searchTerm: payload.queryText,
                searchResultCount: payload.numberOfResults,
              },
              attributes: {
                sort: filterType,
                totalResults: payload.results,
                resultsShown: payload.results.length,
                coveo_clientId: payload.clientId,
              },
            },
          });

          if (payload.facetState.length > 0) {
            [...]
            //adobe datalayer push event upon search filter applied
            window.adobeDataLayer.push({
              event: 'search:filter:applied',
              component: {
                info: {
                  filterMethod: facetType,
                  filterType: filterType,
                  filterValue: filterValue,
                },
                attributes: {
                  sort: dropdownFilterType,
                  totalResults: payload.results,
                  resultsShown: payload.results.length,
                  coveo_clientId: payload.clientId,
                },
              },
            });
          }
        }

        if (payload.actionCause == 'documentOpen' || payload.actionCause == 'documentQuickview') {
          if (payload.documentPosition != undefined) {
            [...]
            //adobe datalayer push event upon search result click
            window.adobeDataLayer.push({
              event: 'search:result:click',
              component: {
                info: {
                  title: payload.documentTitle,
                  clickType: clickType,
                  clickPosition: payload.documentPosition,
                  filtersList: filterList,
                  tags: 'see screenshot/description below',
                  coveo_clientId: payload.clientId,
                },
              },
            });
          }
        }
        return payload;
      }
    }
  });

  searchInterface.executeFirstSearch();
}

main();

</script>
1 <ACCESS_TOKEN> (string) is an API key that was created using the Anonymous search template or a search token that grants the Allowed access level on the Execute Queries domain and the Push access level on the Analytics Data domain in the target organization.
Important

We strongly recommend that the access token enforces a searchHub value. See Defining the search hub in the authentication for more details.

2 <ORGANIZATION_ID> (string) is the unique identifier of your Coveo organization (for example, mycoveoorganizationa1b23c).

Send analytics data to Coveo

Coveo Usage Analytics (Coveo UA) lets you track user interactions with your search interfaces, so that you can optimize your Coveo solution. Search, click, and custom events provide the data that powers most Coveo Machine Learning (Coveo ML) models.

Here’s an example where we initialize Coveo UA and send a view event with custom context data:

<script type="text/javascript" src="https://static.cloud.coveo.com/coveo.analytics.js/2/coveoua.js"></script>
<script>
    // Send view events.
    coveoua("init", "<ACCESS_TOKEN>", "<ANALYTICS_ENDPOINT>"); 1
    coveoua("send", "view", { 2
      contentIdKey: "<FIELD_NAME>", 3
      contentIdValue: "<FIELD_VALUE>", 4
      contentType: "<CONTENT_TYPE>", 5
      customData: {
        context_CONTEXT_KEY: "<CUSTOM_CONTEXT_VALUE>" 6
        // ... Additional custom context information ...
      }
    });
  </script>
1 <ACCESS_TOKEN>: A public API key or a valid search token if the page requires user authentication (see Choose and implement a search authentication method, Search token authentication, Execute queries domain, and Analytics data domain).

<ANALYTICS_ENDPOINT>: Your organization analytics endpoint.

  • https://<ORG_ID>.analytics.org.coveo.com for a non-HIPAA organization

  • https://<ORG_ID>.analytics.orghipaa.coveo.com for a HIPAA organization

Where <ORG_ID> is the unique identifier of your Coveo organization.

2 The send command returns a promise. To send multiple events sequentially, use await:
Example
async function sendEvents() {
  try {
    await coveoua("send", "view", { /* event data */ });
  } catch (error) {
    console.error("Error sending events:", error);
  }
}
3 <FIELD_NAME>: The name of a field that can be used to uniquely and permanently identify the tracked page as an item in the index (see About fields). The @clickableuri field is a good choice for pages in a public website, because you can retrieve a web page’s URL using JavaScript code.
4 <FIELD_VALUE>: The value of the <FIELD_NAME> field for the current tracked page. If <FIELD_NAME> is set to @clickableuri, the window.location.href JavaScript function typically returns the matching <FIELD_VALUE> for the current page.
5 <CONTENT_TYPE>: (Optional) The type of content being tracked.
6 CONTEXT_KEY/<CUSTOM_CONTEXT_VALUE>: (Optional) The user context key-value pairs to pass for more personalized recommendations. When you log view events with Coveo UA, all user context key names must be prefixed with context_.

Use AEM tags to trigger Coveo UA or Relay scripts

Implementing Coveo UA or Coveo Relay in Adobe Experience Manager Data Collection, complemented by the Adobe Client Data Layer (ACDL), can significantly enhance your understanding of user interactions within your digital properties.

In this section, you’ll learn how to effectively implement Coveo UA and Coveo Relay within AEM so you can fully leverage the capabilities of both platforms.

  1. Log in to your Adobe Experience Cloud account, and then navigate to the Data Collection page.

    Adobe Experience Manager home page

  2. Select Tags in the left menu.

    Adobe Experience Manager tags options

  3. Click New Property to create a property.

  4. Configure the new property.

    Create property | Adobe Experience Manager Data Collection

  5. Select Extensions in the property menu and install the Adobe Client Data Layer from the extension catalog.

    Extension catalog | Adobe Experience Manager Data Collection

  6. Configure the ACDL extension.

    ACDL extension | Adobe Experience Manager Data Collection

  7. Select Rules in the property menu and create AEM Tags rules. Adobe Experience Manager Tags employ a rule-based system to detect user interactions and associated data. When the conditions in your rules are met, the designated extension, script, or client-side code is triggered. By creating these rules, you can unify disparate marketing and ad tech products into a single, integrated solution. For example, use AEM Tags rules to load Coveo UA or Relay, then leverage ACDL events to send page views directly to Coveo.

  8. Create a rule to load Coveo UA or Relay when the DOM of your website is ready.

    Rule configuration | Adobe Experience Manager Data Collection

    1. Click + in the Events section, configure a Core DOM Ready event, and then click Keep Changes.

      Rule event | Adobe Experience Manager Data Collection

    2. Click + in the Actions section and configure a Core Custom Code action. Set the HTML custom code by pasting either the Coveo UA script or Relay script in the editor, and then click Keep Changes.

      Action configuration | Adobe Experience Manager Data Collection

      1. Here is the code if you want to use Coveo UA.

        Rule action configuration | Adobe Experience Manager Data Collection

        1. <ACCESS_TOKEN>: A public API key or a valid search token if the page requires user authentication.

        2. <ANALYTICS_ENDPOINT>: Your organization analytics endpoint.

          • https://<ORG_ID>.analytics.org.coveo.com for a non-HIPAA organization

          • https://<ORG_ID>.analytics.orghipaa.coveo.com for a HIPAA organization

          Where <ORG_ID> is the unique identifier of your Coveo organization.

      2. Here is the code if you want to use Relay.

        Rule action configuration | Adobe Experience Manager Data Collection

        1. Replace <ORG_ID> with the unique identifier of your Coveo organization.

        2. Replace <TOKEN> in an API key or search token that grants the privileges to push UA data to the target Coveo organization.

        3. Specify a unique <TRACKING_ID> to differentiate and categorize data within your Coveo organization.

  9. Create a rule to listen to an ACDL event in order to trigger calls to Coveo UA or Relay.

    Rule event configuration | Adobe Experience Manager Data Collection

    1. In the Events section, add an ACDL Event - Data Pushed event listening to the page:viewed event.

      Data pushed event | Adobe Experience Manager Data Collection

    2. In the Actions section, add a Core Custom Code action.

      Page view action configuration | Adobe Experience Manager Data Collection

      1. For Coveo UA, use the following code.

        Core Custom Code action - Coveo UA | Adobe Experience Manager Data Collection

      2. For Relay, use the following code.

        Core Custom Code action - Coveo Relay | Adobe Experience Manager Data Collection

  10. Add a library. A library is a set of instructions that defines how extensions, data elements, and rules interact once deployed.

    Event environment | Adobe Experience Manager Data Collection

    1. Set a Name and select the Environment. A library must be assigned to an environment before it can be compiled into a build.

      Library | Adobe Experience Manager Data Collection

    2. Access the Publishing Flow section. As it progresses through the publishing workflow, the library moves through multiple environments to ensure all changes are properly validated before final deployment.

      Library publishing flow | Adobe Experience Manager Data Collection

    3. Add a library resource for each of your rules, and then click Save & Build to Development.

      Library resources | Adobe Experience Manager Data Collection

  11. Access the Environments section and click the box icon to copy the script related to your environment.

    AE select environment | Adobe Experience Manager Data Collection

  12. Copy the script code and paste it in the head of your website.

    AE script | Adobe Experience Manager Data Collection

  13. Add the code to your website to push an event to the ACDL that fits your rules.

    <html>
    	<head>
                <script src="https://assets.adobedtm.com/f8b326dcee26/8966863a3321/launch-2374bfxxxba-development.min.js" async></script>
                <title>Test AEM + Coveo</title>
    	</head>
    	<body>
    	<script>
                    //Initialize Adobe Data Layer
                    window.adobeDataLayer = window.adobeDataLayer || [];
    
                    //Push an Event to Adobe Data Layer
                    window.adobeDataLayer.push({"event":"page:viewed","data":"some data"});
    	</script>
    	    <p>This is a test!</p>
    	</body>
    </html>
  14. Deploy your website.

  15. Visit your website to trigger the events.

  16. You should see a successful request in the network inspector.

    • For Coveo UA:

      Coveo content | Adobe Experience Manager Data Collection

    • For Relay:

      Relay data | Adobe Experience Manager Data Collection

  17. In the Coveo Administration Console Reports (platform-ca | platform-eu | platform-au) page, explore and visualize your Coveo UA data.

Note

Want to create a report tailored to your needs? See Review and manage dashboards.