Page viewed conversion metrics

This topic explains how to create a page viewed metric in LaunchDarkly. Page viewed metrics track how often end users view an element on a page hosted at a specific URL. For example, you might want to track how often customers view an item when its price is discounted different amounts.

For example, you can use page viewed metrics to track:

  • How many times a blog post was viewed
  • Whether or not customers view a help article
Page viewed events are different from session replay visited URL properties

LaunchDarkly’s observability features include a session replay plug-in that automatically tracks the URLs a user visits during a session recording. You can use the session replay visited-url property to filter the sessions displayed in the Sessions tab of the LaunchDarkly UI. However, you cannot use this property as an event for creating new metrics.

This topic describes how to instrument page viewed events and metrics that you can use to create experiments or guarded rollouts.

Prerequisites

Page viewed metrics are only compatible with the following JavaScript-based client SDKs:

  • Electron
  • JavaScript
  • Node.js (client-side)
  • React Web
  • Vue

If you do not use one of these SDKs and would like to track page views, use a custom conversion binary metric instead.

Flush events when an end user is redirected

SDKs send events at regular intervals, such as every five seconds. If a browser redirects an end user to another page, any events that occurred between when the SDK last sent events and when the browser redirected will be lost. To avoid this, flush events when you know the browser will redirect an end user to another page, such as on click. To learn more, read Flushing events.

Metric definition

When you create a page viewed conversion metric, you first choose the metric aggregation type:

  • Count uses sum aggregation to measure the total number of times a context views a matching page.
  • Count distinct units (Percent) uses average aggregation to measure whether or not a context visits a matching page. This option automatically sets the metric analysis type to average, to measure the percent of units that visit a matching page for a given flag variation.

If you aggregate using the Count option, you must also choose the metric analysis method:

  • Average: the default Average analysis method calculates the average number of page views per context for a given flag variation. For metrics you plan to use in funnel metric groups, you must select “Average.”
  • Percentile: you can choose between P50-P99, which represent the 50th through the 99th percentile. This method counts the page views per context, then finds the number of page views that fall into the chosen percentile.

If you choose Count distinct units (Percent), the metric definition automatically uses the “Average” analysis method.

To learn more about the metric definition options, read Analysis method and Analysis units.

Create page viewed metrics

To create a page viewed metric:

  1. Open the Data section and navigate to the Metrics list.
  2. Click Create metric. The “Create metric” dialog appears.
  3. If you use warehouse native metrics, you can select either LaunchDarkly hosted or Warehouse native. Select LaunchDarkly hosted.
  4. Select an event kind of Page viewed.
  5. Specify the Target type you want to track behavior on. Expand the section below to view the four types of URL matching.
URL matching schemaDescriptionExample
Simple match

This sends an event when the end user accesses a URL, or clicks on an element hosted at a URL, that matches the string you enter in the Target URL field or a formulation of that URL that included appended parameters. If you want events to record for URLs with substrings, specify each URL individually.

If you specify:

Then LaunchDarkly sends events from views or clicks at:

If you specify:

Then LaunchDarkly sends events from views or clicks at:

Exact match

This sends an event when the end user accesses a URL, or clicks on an element hosted at a URL, that exactly matches what you enter in the Target URL field. Identical base URLs with different substrings do not send events.

If you specify:

Then LaunchDarkly sends events from views or clicks at:

Views and clicks at https://www.example.com/login and https://www.example.com#signin do not send events.

Regular expression

This sends an event based on a regex expression you specify. This lets you designate more precise locations to send click and page view events.

If you specify:

  • example.com\/account\/.*\/billing

Then LaunchDarkly sends events from views or clicks at any string between account/ and /billing, such as http://example.com/account/12345/billing.


You can test your regular expressions using the tool at Regular Expressions 101.

Substring match

This sends an event when the end user accesses a URL, or clicks on an element hosted at a URL with a specific string of text in it.

If you specify:

Then LaunchDarkly sends events from views or clicks at:

If you specify:

  • your-substring

Then LaunchDarkly sends events from views or clicks at:

  • example.com/your-substring
  • example.com/username/your-substring/
  • example.com/your-substring/settings

Because all of these URLs contain your-substring, clicks on the CSS selectors you specify on each page send events.

  1. Enter the full URL or search pattern in Target URL.
  2. (Optional) Click Add target URL to track behavior on more than one URL target.
  3. In the Metric definition section, choose either Count or Count distinct units (Percent) from the drop-down menu to configure the aggregation type. The window populates a full metric definition using default values.
  4. Use the [analysis unit] drop-down menu to change or add analysis units. For page viewed metrics, the analysis unit will usually default to “user,” “customer,” or similar, representing an individual person.
  5. If you chose Count as the aggregation type, choose either Average or a percentile between P50-P99 click rate to specify the metric analysis method.

A page viewed conversion metric.

A page viewed conversion metric.
  1. Enter a metric Name.
  2. (Optional) Add a Description.
  3. (Optional) Add any Tags.
  4. (Optional) Update the Maintainer.
  5. Click Create.

You can connect the metric to an experiment or guarded rollout to monitor the impact of a flag change.

You can also use the REST API: Create metric