Behavioral analytics
editBehavioral analytics
editBehavioral 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 prerequisites
editBehavioral 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.
Overview
editYou’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:
- Create a collection. A collection stores analytics events.
- Set up a UI integration.
- Analyze the data collected. Refer to Analytics events.
Collections
editA collection is a set of analytics events.
Get started by creating a collection in the Enterprise Search UI:
- Go to the Collections tab under Enterprise Search > Behavioral Analytics.
- 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 integration
editDetailed 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 embed
editAdd 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:
-
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>
-
Initialize the client to start tracking events:
<script type="text/javascript">window.elasticAnalytics.createTracker();</script>
-
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 client
editThe 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:
-
Download the behavioral analytics JavaScript tracker client from NPM:
npm install @elastic/behavioral-analytics-javascript-tracker
-
Import the client in your application:
import { createTracker, trackPageView, trackEvent, } from "@elastic/behavioral-analytics-javascript-tracker";
-
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 astrackPageView
to send events to Behavioral Analytics. -
Dispatch Pageview and behavior events.
Once integrated, you should be able to see page view events within the "events" tab.
Search UI integration
editSearch 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:
- Embed Behavioral Analytics into your site using the JavaScript embed or the JavaScript client.
-
Install the
@elastic/search-ui-analytics-plugin
by importing it into your app. - 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 steps
edit- Learn about tracking events.
- Refer to the analytics API reference.