• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    Click conversion metrics

    Read time: 2 minutes
    Last edited: Mar 01, 2023

    Overview

    This topic explains how to create a click conversion metric for an experiment in LaunchDarkly.

    Some metrics require the JavaScript or React SDK

    Click conversion metrics are only available on the JavaScript and React SDKs. If you do not use the JavaScript or React SDK and would like to track clicks or page views, use a custom conversion metric.

    Call track and flush 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 browser redirected the end user will be lost. To avoid this, call track and then flush when you know the browser will redirect an end user to another page, such as on click.

    Click conversion metrics track how often an end user interacts with an element of your product's UI. Click conversion metrics must be used with either the JavaScript or React SDK.

    For example, you might want to track how often a customer clicks a "Save" button when it is red versus how often a customer clicks the "Save" button when it is blue. You can create a metric that monitors clicks on the button as designated by a CSS selector located at a specific URL.

    You can even monitor clicks on the button across different URLs by telling the metric to track different URLs based on substrings or simple matches. For example, you could track an event on every URL with /checkout-page/ in the URL path.

    Understanding CSS selectors

    CSS selectors designate specific areas of your product UI, like buttons or images, that your end users can interact with. You can create a metric that monitors interaction with one or more CSS selectors.

    For example, some CSS selectors include:

    • #example-element-id
    • .example-classname
    • button.example-button
    • .example-button, .example-button-alt

    The CSS selector must be present in your application after the end user interacts with it in order for LaunchDarkly to record the metric. For example, if the end user clicks an element that is dynamically removed from your application in response to the click, then LaunchDarkly will not record the metric event.

    If the CSS selector will not be present after the end user interacts with it, we recommend using a custom conversion metric instead. To learn more, read Custom conversion metrics.

    Creating click conversion metrics

    To create a click conversion metric:

    1. Navigate to the Experiments list.
    2. Click the Metrics tab.
    3. Click Create metric. The "Create a new metric" panel appears.
    4. Enter a human-readable Name for the metric.
    5. (Optional) Enter a Description.
    6. (Optional) Type or choose from available Tags.
    7. (Optional) Choose a Maintainer. By default, the person who creates the metric is set as the Maintainer.
    8. Click the Event kind menu and select "Click."
    9. Enter one or more CSS selectors in the Click targets field. If you include multiple CSS selectors, separate them with commas.
    10. Specify the type of Target URL you want to track behavior on. There are four types of URL matching:
    URL matching schemaDescriptionExample
    Simple matchThis 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:
    • https://www.example.com
    Then LaunchDarkly sends events from views or clicks at:
    • https://www.example.com
    • https://www.example.com#signin
    If you specify:
    • https://www.example.com, and
    • https://www.example.com/login
    Then LaunchDarkly sends events from views or clicks at:
    • https://www.example.com
    • https://www.example.com/login
    Exact matchThis 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:
    • https://www.example.com
    Then LaunchDarkly sends events from views or clicks at:
    • https://www.example.com
    Views and clicks at https://www.example.com/login and https://www.example.com#signin do not send events.
    Substring matchThis 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:
    • 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.
    Regular expressionThis 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.
    1. Enter the webpage URL.
    2. (Optional) Click Add additional URL to track behavior on more than one URL.
    3. Choose one or more context kinds available for experiments for the metric to measure events from.
    Metrics must use valid randomization units

    Using invalid randomization units will result in invalid experiment results. To learn more, read Randomization units. If you're unsure of which randomization unit to use, contact Support for help determining valid context kind selections.

    1. Click Save metric.

    After you create a metric, you can connect it to an experiment. To learn how, read Building experiments.

    You can also use the REST API: Create metric