Google Tag Manager

Learn how to track sale conversion events using Google Tag Manager (GTM) and Linkkit to measure purchases, subscriptions, and revenue generated from your referral links.

Learn how to track sale conversion events using Google Tag Manager (GTM) and Linkkit to measure purchases, subscriptions, and revenue generated from your referral links.

Business Plan Requirement
This feature is available only on Business plans and higher-tier subscriptions.

Linkkit’s Google Tag Manager integration allows you to track conversion events directly through Google Tag Manager (GTM).

Prerequisites

Before you begin, make sure conversion tracking is enabled for your Linkkit links, as it is required to start tracking conversions.

Linkkit Partners
If you're using Linkkit Partners, you can skip this step since conversion tracking is enabled by default for all partner links.
Option 1: Workspace-Level Setup
To enable conversion tracking for all future links in a workspace:

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

Once enabled, conversion tracking will be automatically applied to all new links created through the Linkkit Link Builder.
Option 2: Link-Level Setup
If you don't want to enable conversion tracking for all links in your workspace, you can enable it for individual links instead.

To do this, open the Linkkit Link Builder for the desired link and turn on the Conversion Tracking option.
Option 3: Via the API
You can also enable conversion tracking programmatically using the Linkkit API.

Simply set trackConversion: true when creating or updating a link to enable conversion tracking for that link.

Install Linkkit via Google Tag Manager

There are two steps to install the Linkkit Analytics script using Google Tag Manager:

  • Add the Linkkit Analytics script to GTM.
  • Create a User-Defined Variable for the linkkit_id cookie.

Step 1: Add the Linkkit Analytics Script to GTM

First, add the Linkkit Analytics script to your website through Google Tag Manager.

In your GTM workspace, go to the Tags section and click New to create a new tag.

Select Custom HTML as the tag type and add the following code:

<script>
  (function (c, n) {
    c[n] =
      c[n] ||
      function () {
        (c[n].q = c[n].q || []).push(arguments);
      };

    var methods = ["trackClick", "trackLead", "trackSale"];
    for (var i = 0; i < methods.length; i++) {
      (function (method) {
        c[n][method] = function () {
          var args = Array.prototype.slice.call(arguments);
          args.unshift(method);
          c[n].apply(null, args);
        };
      })(methods[i]);
    }

    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>


Use Your Publishable Key
Be sure to replace linkkit_pk_xxxxxxxx with the actual publishable key from your Linkkit workspace, available in the Analytics Settings page.

Configure the Tag

Set the trigger to All Pages – Page View so the tag fires on every page of your website.

Name the tag "Linkkit Analytics Script" and save your changes.

Step 2: Create a User-Defined Variable for the linkkit_id Cookie

To access the linkkit_id cookie set by the Linkkit Analytics script, you'll need to create a User-Defined Variable in Google Tag Manager.

In your GTM workspace, navigate to the Variables section and click New to create a new variable.

Configure the Variable

Set up the variable with the following settings:

  • Variable Type: First-Party Cookie
  • Cookie Name: linkkit_id
  • Variable Name: Linkkit ID Cookie

Click Save to create the variable.

This variable will allow Google Tag Manager to access the Linkkit click ID stored in the user's browser for conversion tracking and attribution.

Linkkit ID Variable
This variable automatically reads the linkkit_id cookie value set by the Linkkit Analytics script. You can use it in your tags to pass the Linkkit ID when tracking conversion events.

Tracking Lead Events

There are two ways to track lead events using Google Tag Manager:

  • Thank You Page Tracking (Recommended)
  • Form Submission Tracking

Option 1: Thank You Page Tracking (Recommended)

This method tracks lead events when users reach a thank-you or success page after submitting a form.

It is recommended because it is more reliable, less affected by ad blockers, and provides more accurate conversion data.

To set it up, create a Custom HTML tag in Google Tag Manager and add the following code:

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

    // Get linkkit_id from cookie using GTM variable
    var clickId = {{LinkKit ID Cookie}} || "";

    // Only track the lead event if email and clickId are present
    if (email && clickId) {
      linkkitAnalytics.trackLead({
        eventName: "Sign Up",
        customerExternalId: email,
        customerName: name || email,
        customerEmail: email,
        clickId: clickId,
      });
    }
  })();
</script>
Pass Customer Details
Make sure to pass the email and name query parameters to the thank-you page so the lead event can be attributed to the correct customer.

Configure the Tag

Set this tag to fire on specific pages by creating a Page View trigger with the following settings:

  • Trigger Type: Page View
  • This trigger fires on: Some Page Views

Add conditions such as:

  • Page URL contains /thank-you
  • Page Path equals /success
  • Or any URL pattern that matches your thank-you pages

Name the tag “Linkkit Lead Tracking - Thank You Page” and save it.

Option 2: Form Submission Tracking

This method tracks lead events immediately when users submit forms on your website.

Note that this approach may be less reliable due to potential ad blockers and timing issues during form submission.

To set it up, create a Custom HTML tag in Google Tag Manager and add the following code:

<script>
  (function () {
    // Get form data - customize these selectors based on your form
    var name = document.getElementById("name")
      ? document.getElementById("name").value
      : "";
    var email = document.getElementById("email")
      ? document.getElementById("email").value
      : "";

    // Get linkkit_id from cookie using GTM variable
    var clickId = {{LinkKit ID Cookie}} || "";

    // Only track the lead event if email and clickId are present
    if (email && clickId) {
      linkkitAnalytics.trackLead({
        eventName: "Sign Up",
        customerExternalId: email,
        customerName: name || email,
        customerEmail: email,
        clickId: clickId,
      });
    }
  })();
</script>
Customize Form Field Selectors
Update the DOM selectors (getElementById('name'), getElementById('email')) to match your actual form field IDs, or use another method to capture form data based on your website’s structure.

Configure the Form Submission Tag

Set this tag to fire on form submissions by creating a new trigger:

  • Trigger Type: Form Submission
  • This trigger fires on: Some Forms (or All Forms if you want to track all form submissions)

Add conditions to specify which forms should trigger lead tracking.

Name the tag “Linkkit Lead Tracking - Form Submission” and save it.

Tracking Sales Events

There are two ways to track sales events using Google Tag Manager:

  • Order Confirmation Page Tracking (Recommended)
  • Checkout Form Submission Tracking

Option 1: Order Confirmation Page Tracking (Recommended)

This method tracks sales when users reach an order confirmation or success page after completing a purchase.

It is recommended because it provides more reliable tracking, is less affected by ad blockers, and ensures better conversion data accuracy.

To set it up, create a Custom HTML tag in Google Tag Manager and add the following code:

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

    // Only track if customer ID and amount are present
    if (customerId && amount) {
      // Track the sale event
      linkkitAnalytics.trackSale({
        eventName: "Purchase",
        customerExternalId: customerId,
        amount: parseInt(amount), // Amount in cents
        invoiceId: invoiceId || undefined,
        currency: "usd", // Customize as needed
        paymentProcessor: "stripe", // Customize as needed
      });
    }
  })();
</script>

Configure the Tag

Set this tag to fire on specific pages by creating a Page View trigger with the following settings:

  • Trigger Type: Page View
  • This trigger fires on: Some Page Views

Add conditions such as:

  • Page URL contains /order-confirmation
  • Page Path equals /checkout/success
  • Or any URL pattern that matches your order confirmation pages

Name the tag “Linkkit Sales Tracking - Order Confirmation” and save it.

Option 2: Checkout Form Submission Tracking

This method tracks sales immediately when users complete checkout forms on your website.

Note that this approach may be less reliable due to potential ad blockers and timing issues during the checkout process.

To set it up, create a Custom HTML tag in Google Tag Manager and add the following code:

<script>
  (function () {
    // Get checkout data - customize these selectors based on your form
    var customerId = document.getElementById("customer_id")
      ? document.getElementById("customer_id").value
      : "";
    var amount = document.getElementById("amount")
      ? document.getElementById("amount").value
      : "";
    var invoiceId = document.getElementById("invoice_id")
      ? document.getElementById("invoice_id").value
      : "";

    // Only track if customer ID and amount are present
    if (customerId && amount) {
      // Track the sale event
      linkkitAnalytics.trackSale({
        eventName: "Purchase",
        customerExternalId: customerId,
        amount: parseInt(amount), // Amount in cents
        invoiceId: invoiceId || undefined,
        currency: "usd", // Customize as needed
        paymentProcessor: "stripe", // Customize as needed
      });
    }
  })();
</script>
Customize Checkout Form Selectors
Update the DOM selectors (getElementById('customer_id'), getElementById('amount'), etc.) to match your actual checkout form field IDs, or use another method to capture checkout data based on your website’s structure.

Configure the Checkout Form Tag

Set this tag to fire on checkout form submissions by creating a new trigger:

  • Trigger Type: Form Submission
  • This trigger fires on: Some Forms (or All Forms if you want to track all form submissions)

Add conditions to specify which forms should trigger sales tracking (for example, checkout forms).

Name the tag “Linkkit Sales Tracking - Checkout Form” and save it.

Sale Event Properties

Here are the properties you can include when sending a sale event:


Property

Required

Description

customerExternalId

Yes

The unique ID of the customer in your system. Used to identify and attribute all future events to this customer.

amount

Yes

The sale amount in cents.

paymentProcessor

No

The payment processor used for the sale (e.g., Stripe, Shopify). Defaults to custom.

eventName

No

The name of the sale event. Defaults to Purchase.

invoiceId

No

The invoice ID of the sale. Can be used as an idempotency key to prevent duplicate sale records.

currency

No

The currency of the sale. Defaults to usd.

metadata

No

Additional information stored with the sale event.

clickId

No

For direct sale tracking, the unique click ID associated with the conversion. This value can be retrieved from the linkkit_id cookie.

customerName

No

For direct sale tracking, the customer's name. If not provided, a random name will be generated.

customerEmail

No

For direct sale tracking, the customer's email address.

customerAvatar

No

For direct sale tracking, the customer's avatar URL.

Testing Your Setup

To test your Google Tag Manager (GTM) setup, use the Preview Mode in Google Tag Manager:

  • Enable Preview Mode
    • Open your GTM workspace.
    • Click the Preview button in the top-right corner.
  • Connect Your Website
    • Enter your website URL.
    • Click Connect.
  • Test Your Tracking Method
    Option 1: Order Confirmation Tracking
    Option 2: Form Submission Tracking
    • Open your order confirmation page with the required query parameters, for example:
      ?customer_id=123&amount=1000&invoice_id=inv_456
    • Go to your checkout page.
    • Complete a test purchase form submission.
  • Verify Tag Firing
    • Check the GTM Preview debugger.
    • Confirm that your tracking tags are firing correctly and sending conversion events.

Verify Conversion Tracking

You can verify that your conversion events are being tracked by:

  • Checking your browser’s Developer Console for any JavaScript errors.
  • Using the Network tab to confirm that requests are being sent to the Linkkit Analytics endpoint.
  • Opening your Linkkit dashboard to ensure sale events are appearing correctly in your analytics.

Common Troubleshooting Tips

  • Tag not triggering: Confirm that your triggers are set up correctly and that the trigger conditions match your website’s page structure.
  • Form data not captured (Option 2): Check that your DOM selectors are correctly targeting the actual checkout form fields, including the correct field IDs or names.
  • Missing query parameters (Option 1): Make sure your checkout flow redirects users to the confirmation page with all required query parameters included.
  • Incorrect amount format: Verify that sale amounts are provided in cents (for example, $10.00 should be sent as 1000 cents).
  • Multiple events being recorded: Review your trigger settings to ensure your tags are not firing more than once for the same action.
  • Duplicate tracking: Make sure you have implemented only one tracking method (Option 1 or Option 2) to prevent duplicate conversion events.
  • Missing publishable key: Confirm that the placeholder value has been replaced with your actual Linkkit publishable key.
Client-Side Tracking Limitations
Add your content here.Client-side tracking may have some limitations, including:

Ad blockers: Users with ad blockers may prevent tracking scripts from loading, which can affect conversion data.
JavaScript disabled: Conversion events cannot be recorded if users have disabled JavaScript in their browsers.
Network issues: Failed tracking requests may not be automatically retried, resulting in missing events.
Privacy restrictions: Some users may block client-side tracking tools due to privacy settings or browser restrictions.

For more reliable and accurate conversion tracking, consider implementing server-side conversion tracking with Linkkit.

View Conversion Results

Your setup is complete! You can now monitor your conversion performance and track revenue growth through the Linkkit dashboard.

Linkkit provides three different views to help you analyze your conversions:

Time-Series View

A timeline-based view that displays the number of clicks, leads, and sales over a specific period.

This helps you track conversion trends and understand how your campaigns are performing over time.

Funnel Chart View

A visual representation of your conversion funnel that shows conversion rates and drop-off points across each stage of the customer journey:

Clicks → Leads → Sales

This view helps you identify where users are dropping off and understand how effectively your links are converting visitors into leads and customers.

Real-Time Events Stream

A live activity feed that displays every conversion event generated across all your Linkkit links in your workspace.

This view allows you to monitor conversion activity in real time, verify tracking accuracy, and quickly review events such as clicks, leads, and sales as they occur.

Example apps