Client-side tracking

Learn how to track sales conversion events with Linkkit on the client side, allowing you to attribute purchases and revenue directly from your frontend application.

Learn how to track sales conversion events with Linkkit on the client side, allowing you to attribute purchases and revenue directly from your frontend application.

Business Plans & Above
This feature is available exclusively on Business plans and higher-tier subscriptions.

Linkkit’s powerful attribution platform helps you understand how effectively your links are driving user acquisition, conversions, and revenue growth.

In this guide, you'll learn how to track conversion events with Linkkit using client-side tracking, enabling you to measure leads, sales, and other key actions directly from your frontend application.

Limitations of Client-Side Conversion Tracking
Client-side conversion tracking has a few limitations to be aware of:

Ad blockers – Some users may have ad blockers that prevent tracking scripts from loading.
JavaScript disabled – Conversion events cannot be tracked if JavaScript is disabled in the user's browser.
Network interruptions – Failed tracking requests caused by network issues may not be retried automatically.
Privacy restrictions – Certain browser settings, privacy tools, or user preferences may block client-side tracking.

For improved reliability and more accurate attribution, consider implementing server-side conversion tracking with Linkkit.


Step 1: Enable Conversion Tracking for Your Links

Before you can start tracking conversions, you'll need to enable conversion tracking for your Linkkit links. Once enabled, Linkkit can attribute leads, sales, and other conversion events back to the original referral link.

Linkkit Partners
If you're using Linkkit Partners, you can skip this step because conversion tracking is automatically enabled for all partner links.
Option 1: Enable Conversion Tracking at the Workspace Level
To automatically enable conversion tracking for all new links created within a workspace, follow these steps:

Navigate to your workspace’s Tracking Settings page.
Turn on the Workspace-Level Conversion Tracking option.

Once enabled, conversion tracking will be applied to all future links created in that workspace.
This option will automatically enable conversion tracking in the **Linkkit Link Builder** for all future links created within the workspace.
Option 2: Enable Conversion Tracking at the Link Level
If you prefer not to enable conversion tracking for every link in a workspace, you can activate it individually for specific links.

To enable conversion tracking for a particular link:

Open the Linkkit Link Builder for the link.
Turn on the Conversion Tracking option.

Enabling conversion tracking for a link

This setting will apply conversion tracking only to the selected link.

For faster access, you can also press the C keyboard shortcut while inside the Linkkit Link Builder to quickly enable conversion tracking for the current link.
Option 3: Enable Conversion Tracking via the API
You can also enable conversion tracking programmatically using the Linkkit API.

When creating or updating a link, simply set the trackConversion parameter to true:


Step 2: Install the Linkkit Analytics Script

Next, you'll need to install the Linkkit Analytics script and configure it for client-side conversion tracking.

1. Allowlist Your Website Domain

To enable Linkkit to receive and process client-side conversion events, you'll first need to add your website's domain to the allowlist.

To do this:

  • Navigate to your workspace's Tracking Settings page.
  • Add your website's domain to the Allowed Hostnames list.

Adding your domain provides an extra layer of security by ensuring that only authorized websites can send conversion events using your publishable key.

When adding domains to the Allowed Hostnames list, you can use different hostname patterns depending on the traffic you want to track:

  • example.com – Tracks conversion events only from example.com.
  • *.example.com – Tracks conversion events from all subdomains of example.com (such as www.example.com, app.example.com, or shop.example.com), but does not include example.com itself.

This flexibility allows you to control exactly which domains and subdomains are authorized to send conversion events to Linkkit.

Local Testing
Add your conWhen testing locally, you can temporarily add localhost to the Allowed Hostnames list. This allows local events to be tracked by Linkkit. Be sure to remove it before going live.tent here.
2. Generate Your Publishable Key

Before you can start tracking conversions on the client side, you'll need to generate a publishable key from your Linkkit workspace.

To generate a publishable key:

  • Navigate to your workspace's Tracking Settings page.
  • Locate the Publishable Key section.
  • Generate a new publishable key.

This key is used to authenticate and securely send client-side conversion events from your website to Linkkit.

3. Install the Linkkit Analytics Script

Next, install the Linkkit Analytics script on your website or web application.

The Linkkit Analytics script is responsible for capturing attribution data and enabling client-side conversion tracking.

You can install the Linkkit Analytics script using any of the following methods:

Publishable Key Configuration
When installing the analytics script, make sure to configure the publishable key generated in Step 1. Client-side conversion tracking will not function without a valid publishable key.
<script>
  !(function (c, n) {
    c[n] =
      c[n] ||
      function () {
        (c[n].q = c[n].q || []).push(arguments);
      };
    ["trackClick", "trackLead", "trackSale"].forEach(
      (t) => (c[n][t] = (...a) => c[n](t, ...a)),
    );
    var s = document.createElement("script");
    s.defer = 1;
    s.src = "https://www.linkkitcdn.com/analytics/script.conversion-tracking.js";
    s.setAttribute("data-publishable-key", "linkkit_pk_xxxxxxxx"); // Replace with your publishable key
    document.head.appendChild(s);
  })(window, "linkkitAnalytics");
</script>
import { Analytics as LinkKitAnalytics } from '@linkkit/analytics/react';

export default function RootLayout({
  children,
}) {
  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
      <LinkKitAnalytics
        ...
        publishableKey="linkkit_pk_xxxxxxxx" // Replace with your publishable key
      />
    </html>
  );
}


Step 3: Track lead events

Direct Sale Tracking
Want to track sales without a prior lead event? Explore our direct sale tracking guide to get started.

Once the Linkkit Analytics script has been installed, you can begin tracking lead events directly from your application on the client side.

Track Leads Using URL Query Parameters (Recommended)

If users are redirected to a thank-you page after completing a successful action, you can track lead events by reading values from the URL query parameters.

This approach is simple to implement and helps ensure that conversion events are accurately attributed to the original referral link.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Thank You</title>
  </head>
  <body>
    <div>Thank you for signing up!</div>

    <script>
      // Get query parameters from URL
      const params = new URLSearchParams(window.location.search);
      const email = params.get("email");
      const name = params.get("name");

      if (email) {
        // Track the lead event
        dubAnalytics.trackLead({
          eventName: "Sign Up",
          customerExternalId: email, // can also be customer email
          customerName: name || undefined,
          customerEmail: email,
        });
      }
    </script>
  </body>
</html>
import { useAnalytics } from "@dub/analytics/react";
import { useEffect } from "react";

export function ThankYouPage() {
  const { trackLead } = useAnalytics();

  useEffect(() => {
    // Get query parameters from URL
    const params = new URLSearchParams(window.location.search);
    const email = params.get("email");
    const name = params.get("name");

    if (email) {
      // Track the lead event
      trackLead({
        eventName: "Sign Up",
        customerExternalId: email, // can also be customer email
        customerName: name || undefined,
        customerEmail: email,
      });
    }
  }, [trackLead]);

  return <div>Thank you for signing up!</div>;
}


Track Leads from Form Submissions

You can also track lead events directly when users submit a form on your website.

This method allows you to record conversions immediately after a successful form submission, ensuring that lead activity is captured and attributed to the appropriate referral source in Linkkit.

When sending a lead event to Linkkit, you can include the following properties to provide additional context and improve conversion attribution:


Property

Required

Description

clickId

Yes

The unique identifier of the click associated with the lead event. This value can typically be retrieved from the linkkit_id cookie. If an empty string is provided (for deferred lead tracking), Linkkit will attempt to locate an existing customer using customerExternalId and use the associated clickId if available.

eventName

Yes

The name of the lead event being tracked. This can also be used as a unique identifier to associate a lead event with future sale events (for example, via the leadEventName property when tracking sales).

customerExternalId

Yes

A unique customer identifier from your system. Linkkit uses this value to recognize the customer and attribute future conversion events to them.

customerName

No

The customer's name. If not provided, Linkkit may generate a placeholder name automatically.

customerEmail

No

The customer's email address.

customerAvatar

No

A URL pointing to the customer's profile image or avatar.

mode

No

Defines how the lead event should be processed. Available options include: async (does not block the request), wait (waits until the event is fully recorded), and deferred (delays lead creation until a later request).

metadata

No

Additional custom data to store with the lead event. Supports up to 10,000 characters.

When to Track Lead Events

Lead events should be tracked after a user successfully completes an action that indicates interest in your product or service, such as:

  • Creating a new account or registering as a user
  • Subscribing to a newsletter
  • Submitting a contact form
  • Requesting a demo or signing up for a free trial
  • Downloading gated content, such as eBooks, guides, or whitepapers

To ensure accurate conversion tracking, the lead event should only be triggered after your backend confirms that the action has been completed successfully. This helps prevent duplicate, incomplete, or invalid lead records from being captured in Linkkit.


Step 4: Track Sale Events

Once the Linkkit Analytics script has been installed, you can begin tracking sale events directly from your application on the client side.

Track Sales Using URL Query Parameters (Recommended)

If users are redirected to a confirmation or thank-you page after completing a purchase, you can track sale events by reading values from the URL query parameters.

This method makes it easy to record completed purchases and attribute them to the appropriate referral link within Linkkit, ensuring accurate conversion and revenue tracking.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Order Confirmation</title>
  </head>
  <body>
    <div>Thank you for your purchase!</div>

    <script>
      // Get query parameters from URL
      const params = new URLSearchParams(window.location.search);
      const customerId = params.get("customer_id");
      const amount = params.get("amount");
      const invoiceId = params.get("invoice_id");

      if (customerId && amount) {
        // Track the sale event
        linkkitAnalytics.trackSale({
          eventName: "Purchase",
          customerExternalId: customerId, // can also be customer email
          amount: parseInt(amount), // Amount in cents
          invoiceId: invoiceId || undefined,

          // Additional props for direct sale tracking (without prior lead event):
          // clickId: "cm3w...", // Read from linkkit_id cookie
          // customerName: "John Doe",
          // customerEmail: "john@example.com",
          // customerAvatar: "https://example.com/avatar.jpg",
          // currency: "usd",
          // paymentProcessor: "stripe",
          // metadata: { plan: "pro" },
        });
      }
    </script>
  </body>
</html>
import { useAnalytics } from "@linkkit/analytics/react";
import { useEffect } from "react";

export function OrderConfirmationPage() {
  const { trackSale } = useAnalytics();

  useEffect(() => {
    // Get query parameters from URL
    const params = new URLSearchParams(window.location.search);
    const customerId = params.get("customer_id");
    const amount = params.get("amount");
    const invoiceId = params.get("invoice_id");

    if (customerId && amount) {
      // Track the sale event
      trackSale({
        eventName: "Purchase",
        customerExternalId: customerId, // can also be customer email
        amount: parseInt(amount), // Amount in cents
        invoiceId: invoiceId || undefined,

        // Additional props for direct sale tracking (without prior lead event):
        // clickId: "cm3w...", // Read from linkkit_id cookie
        // customerName: "John Doe",
        // customerEmail: "john@example.com",
        // customerAvatar: "https://example.com/avatar.jpg",
      });
    }
  }, [trackSale]);

  return <div>Thank you for your purchase!</div>;
}


Track Sales from Form Submissions

You can also track sale events directly when users successfully complete a checkout or purchase form on your website.

This approach allows you to record sales immediately after a transaction is completed, ensuring that revenue and conversion data are accurately attributed to the correct referral source in Linkkit.

The following properties can be included when sending a sale event to Linkkit:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Checkout</title>
  </head>
  <body>
    <form id="checkoutForm">
      ...
      <button type="submit">Checkout</button>
    </form>

    <script>
      document
        .getElementById("checkoutForm")
        .addEventListener("submit", function (e) {
          e.preventDefault();

          // Track the sale event
          linkkitAnalytics.trackSale({
            eventName: "Purchase",
            customerExternalId: "cus_RBfbD57H", // can also be customer email
            amount: 5000, // $50.00
            invoiceId: "in_1MtHbELkdIwH",

            // Additional props for direct sale tracking (without prior lead event):
            // clickId: "cm3w...", // Read from linkkit_id cookie
            // customerName: "John Doe",
            // customerEmail: "john@example.com",
            // customerAvatar: "https://example.com/avatar.jpg",
            // currency: "usd",
            // paymentProcessor: "stripe",
            // metadata: { plan: "pro" },
          });
        });
    </script>
  </body>
</html>
import { useAnalytics } from "@linkkit/analytics/react";
import { useState } from "react";

export function CheckoutForm() {
  const { trackSale } = useAnalytics();
  // …

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();

    // Track the sale event
    trackSale({
      eventName: "Purchase",
      customerExternalId: "cus_RBfbD57H", // can also be customer email
      amount: 5000, // $50.00
      invoiceId: "in_1MtHbELkdIwH",

      // For direct sale tracking (without prior lead event):
      // clickId: "cm3w...", // Read from linkkit_id cookie
      // customerName: "John Doe",
      // customerEmail: "john@example.com",
      // customerAvatar: "https://example.com/avatar.jpg",
    });
  };

  return (
    <form onSubmit={handleSubmit}>
      ...
    </form>
  );
}


Property

Required

Description

customerExternalId

Yes

A unique identifier for the customer in your system. Linkkit uses this value to identify the customer and attribute future events accordingly.

amount

Yes

The sale amount, typically provided in the smallest currency unit (for example, cents for USD).

paymentProcessor

No

The payment platform that processed the transaction (such as Stripe or Shopify). Defaults to custom if not specified.

eventName

No

The name of the sale event. Defaults to Purchase.

invoiceId

No

The invoice or transaction ID associated with the sale. This can be used as an idempotency key to prevent duplicate sale records. Only one sale event can be recorded per invoice ID.

currency

No

The currency used for the transaction. Defaults to usd.

metadata

No

An object containing additional information or custom data related to the sale.

clickId

No

(For direct sale tracking) The unique click identifier associated with the sale. This value can be retrieved from the linkkit_id cookie.

customerName

No

(For direct sale tracking) The customer's name.

customerEmail

No

(For direct sale tracking) The customer's email address.

customerAvatar

No

(For direct sale tracking) A URL pointing to the customer's avatar or profile image.

When to Track Sale Events

Sale events should only be tracked after a user successfully completes a purchase or payment-related action, such as:

  • Completing a checkout or placing an order
  • Making a subscription payment
  • Paying an invoice
  • Converting from a trial or demo to a paid plan
  • Any other successful revenue-generating transaction

To ensure accurate conversion and revenue tracking, the sale event should be triggered only after your backend confirms that the payment has been successfully processed. This helps prevent duplicate, incomplete, or invalid sale records from being sent to Linkkit.

Refund Tracking
Need to track refunds? Follow our refunds tracking guide to set up and monitor refund events.


Step 5: View Your Conversions

That's it — you're all set! Once conversion tracking is configured, you can monitor your leads, sales, and revenue directly within the Linkkit Analytics Dashboard.

To help you better understand your conversion performance, Linkkit provides several reporting views:

Time-Series View

A time-based visualization that displays the number of clicks, leads, and sales over a selected period. This view helps you track trends, measure performance, and identify changes in conversion activity over time.

Time-series chart showing clicks, leads, and sales over time.

Funnel View

A funnel chart that visualizes the conversion rates and drop-off rates across each stage of the conversion journey, from Clicks → Leads → Sales.

This view helps you identify where users are progressing successfully and where potential customers are dropping off, making it easier to optimize your conversion funnel and improve overall performance.

Funnel chart displaying conversion and drop-off rates from Clicks → Leads → Sales.

Real-Time Events Stream

A live event stream that displays every conversion event as it happens across all links in your workspace.

This view provides real-time visibility into user activity, allowing you to monitor clicks, leads, and sales as they occur and quickly verify that your conversion tracking is working correctly.

Real-time events stream showing conversion activity across all workspace links.