Docs » Create custom events

Create custom events πŸ”—

Create custom events to capture meaningful metrics about customer journeys and user behavior on your site. Custom events support filtering by tags and the ability to add custom attributes.

How custom events can add value to your organization πŸ”—

Splunk RUM automatically collects metrics about page loads, errors, and core web vitals. Sometimes, you need custom logic to capture a specific workflow that is important to your organization to understand.

Use case πŸ”—

Suppose you are an online retailer. A meaningful custom event for your business might be understanding behavior around conversion rates and why users drop off and don’t finish a checkout workflow. You might also want to understand where users are stagnating in your application. You can create a custom event to discover which events precipitate an unsuccessful customer journey. Perhaps users are stopped by an error in your checkout workflow, or are unable to enter a promo code. Custom events provide the opportunity for you to see a unique perspective on your data driven by the questions that matter most to you.

Create a custom event πŸ”—

The following examples show how to create a custom event for browser, Android, and iOS applications.

To create a custom event, first declare the tracer, and next define the custom event.

You can declare the tracer through either CDN or NPM. You need to declare the tracer only once. For more information on the difference between CDN and NPM, see Instrument your web application for Splunk RUM.

The following example shows how to initialize the tracer and create a custom event using the NPM package:

import {trace} from '@opentelemetry/api'

const tracer = trace.getTracer('appModuleLoader');
const span = tracer.startSpan('test.module.load', {
attributes: {
      'workflow.name': 'test.module.load'
}
});
// time passes
span.end();

Note

If you want a custom event to appear in the UI, you must set the attribute workflow.name for it. Without the workflow.name attribute, the span is still recorded but will only appear in the request waterfall view.

Next steps with custom events πŸ”—

For examples, dashboards, and metrics related to custom events see:

Advanced instrumentation πŸ”—

For more information on advanced instrumentation, see:

This page was last updated on Aug 22, 2024.