Behavioral analyticsedit

Behavioral analytics is an analytics event collection platform introduced to Elastic in version 8.7.0. Use these tools to track end-user behavior and continually optimize search results.

Capture data and analytics to be stored in Elasticsearch indices, for advanced analysis and visualization.

Even if you don’t use Elastic for search, you can use these tools to collect analytics from your application/website.

Availability and prerequisitesedit

Behavioral analytics is available in Elastic 8.7.0 and later. Analytics are a beta feature. Beta features are subject to change and are not covered by the support SLA of general release (GA) features. Elastic plans to promote this feature to GA in a future release.

Analytics are available to all Elastic Cloud users.

Analytics are also available to self-managed deployments that satisfy subscription requirements. View the requirements for this feature under the Elastic Enterprise Search section of the Elastic Stack subscriptions page.

Your deployment must include the Elasticsearch, Kibana, and Enterprise Search services.

Overviewedit

You’ll manage analytics in the Enterprise Search UI in Kibana. You’ll get most of the information you need in the UI. Go to Enterprise Search > Behavioral Analytics to get started.

Using behavioral analytics is a three-step process:

  1. Create a collection. A collection stores analytics events.
  2. Set up a UI integration.
  3. Analyze the data collected. Refer to Analytics events.

Collectionsedit

A collection is a set of analytics events.

Get started by creating a collection in the Enterprise Search UI:

  1. Go to the Collections tab under Enterprise Search > Behavioral Analytics.
  2. Select Create new collection.

When you create a collection we automatically create a data view for the collection. The data view has the same name as the analytics collection. This allows Kibana to access your analytics data stored in Elasticsearch.

This means that once you integrate analytics into your application or website, you can immediately use Discover to view events, set filters, and create visualizations using Lens.

Once you’ve created a collection, you need to complete your UI integration.

UI integrationedit

Detailed integration instructions are provided in the Kibana UI. Find these in the Integrate tab under Enterprise Search > Behavioral Analytics > View collection.

Use the following integration options:

Once embedded, Search UI users have the following integration to simplify event dispatching:

JavaScript embededit

Add a JavaScript snippet to your website or application source files. The embed tracks page view events implicitly.

This approach is best for web browsers. Node apps and Search UI users shouldn’t choose this option.

Instructions for getting started are available in the Kibana UI.

Follow these steps:

  1. Embed the behavioral analytics JavaScript snippet on every page of the website or application you’d like to track.

    <script src="https://my-cloud-deployment.ent.us-west2.gcp.elastic-cloud.com/analytics.js" data-dsn="https://snapshot.ent.us-west2.gcp.elastic-cloud.com/api/analytics/collections/test"></script>
  2. Initialize the client to start tracking events:

    <script type="text/javascript">window.elasticAnalytics.createTracker();</script>
  3. Track individual events by calling the trackEvent method. For example, to track clicks on a search result:

    window.elasticAnalytics.trackEvent("click", {
      category: "product",
      action: "add_to_cart",
      label: "product_id",
      value: "123"
    });

JavaScript clientedit

The JavaScript client is available as an NPM package. We recommend this approach if your application bundles JavaScript from NPM packages. This is a good option for Node apps (server-side apps). Analytics will be bundled with your app.

This allows the browser to optimize the JavaScript download.

Note that the NPM package does not track page view events implicitly.

Instructions for getting started are also available in the Kibana UI.

Follow these steps to get started:

  1. Download the behavioral analytics JavaScript tracker client from NPM:

    npm install @elastic/behavioral-analytics-javascript-tracker

  2. Import the client in your application:

    import {
      createTracker,
      trackPageView,
      trackEvent,
    } from "@elastic/behavioral-analytics-javascript-tracker";
  3. Initialize the client to start tracking events:

    Use the createTracker method to initialize the tracker with your data source name (DSN). You will then be able to use the tracker to send events to Behavioral Analytics.

    Once you have called createTracker, you can use the tracker methods such as trackPageView to send events to Behavioral Analytics.

  4. Dispatch Pageview and behavior events.

    Once integrated, you should be able to see page view events within the "events" tab.

Search UI integrationedit

Search UI is a JavaScript library for building search experiences. Use the NPM Search UI analytics plugin to integrate behavioral analytics with Search UI.

This integration enables you to dispatch events from Search UI to the behavioral analytics client. The advantage of this integration is that you don’t need to set up custom events. Events fired by Search UI are dispatched automatically.

To use this integration, follow these steps:

  1. Embed Behavioral Analytics into your site using the JavaScript embed or the JavaScript client.
  2. Install the @elastic/search-ui-analytics-plugin by importing it into your app.
  3. Add the plugin to your Search UI configuration.

See the Search UI analytics plugin documentation for details.

GDPR compliance

Users may be concerned about the privacy implications of analytics data collection. Behavioral analytics is fully GDPR compliant, because no personal data are collected.

To integrate the behavioral analytics client, session data are stored in two tokens:

  • User Token. A unique identifier for the user. Stored under EA_UID cookie. Default time length is 24 hours from the first time the user visits the site.
  • Session Token. A unique identifier for the session. Stored under EA_SID cookie. Time length is 30 minutes from the last time the user visits the site.

These tokens enable the client to identify a user across sessions. They do not collect sensitive information, such as IP addresses or location data, or any other personal data.

Next stepsedit