Analytics events

edit

Analytics events

edit

Refer to Analytics events reference for a complete list of the fields logged by events.

Once your analytics collection is set up and analytics are integrated into your application, you can start sending events to your Elastic deployment.

Events come in three broad categories:

  • Common events: All integrations support pageview and click events.
  • Search events: If you use Search UI, use the AnalyticsPlugin hook to automatically track search events.
  • Custom events: Can be sent using the trackEvent function.

This page covers the following topics:

Send events

edit

Send events using the Browser tracker

edit

Example:

window.elasticAnalytics.trackEvent("click", { category: "product" })

Send page view events via the NPM Package in React

edit

Example:

const SearchPage = (props) => {
  useEffect(() => {
    // function executed on component mount
    trackPageView();
  }, []);

  return (
    <div>
      <h1>Search Page</h1>
    </div>
  );
};

Send custom events

edit

Example: send custom events via NPM Package.

import { trackEvent } from '@elastic/behavioral-analytics-javascript-tracker';

const ProductDetailPage = (props) => {

  return (
    <div>
      <h1>Product detail page</h1>
      <input type="button" onClick={() => {
        trackEvent("click", {
          category: "product",
          action: "add_to_cart",
          label: "product_id",
          value: "123"
        })
      }} />
      }}>Add to Basket</input>
    </div>
  )
}

How to view events

edit

Once you begin sending events, you can view them in the Kibana UI.

Analytics events are stored as a logs data stream type.

View events in the Collections dashboard

edit

The Collections dashboard provides a quick overview of events you’re tracking. It’s a great place to get started. In Kibana, go to the Events tab under Enterprise Search > Behavioral Analytics > View collection.

You can view the event type, timestamp, and user UUID. The following screenshot is an example Analytics events dashboard view:

Analytics events dashboard showing the event type

View events in Discover

edit

You can also view events in the Kibana Discover app.

Find your collection’s data view
edit

First you need to find your collection’s data view:

  1. In the main menu, go to Analytics > Discover.
  2. Find the data view dropdown menu.
  3. You’ll find a data view automatically created for your collection. It will be named elastic_analytics.<your-collection>.
  4. Select this data view.

The following screenshot shows you where to find the data view dropdown menu in Discover:

Analytics Discover app showing the data view dropdown menu
Explore your event data
edit

Now you’re ready to explore your event data. Discover has a lot of options, but here’s a quick overview of how to get started:

  • Filter your data by searching for terms, such as click and pageview. You’ll see a time series of hits that match your search.
  • Search for "event" in the field name search bar. For example:

    • Select event.action. You’ll find a list of all the events you’ve sent and their frequency distribution.
    • Search for event.customer_data.totalResults : 0 to find all events where user search queries had 0 results.
  • Select Visualize to create a Lens visualization.