> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cometly.com/llms.txt
> Use this file to discover all available pages before exploring further.

# FastSpring integration

> Set up the FastSpring Cometly integration: pass the comet_token into your FastSpring checkout so each purchase is tied to the ad behind it.

If your checkout is powered by **FastSpring**, you can track purchases in Cometly by passing the Cometly `comet_token` into your FastSpring checkout form. The `comet_token` is a unique identifier that the Cometly pixel (the tracking script on your website) creates for each visitor. This FastSpring Cometly integration then uses a webhook, a message FastSpring sends to Cometly after each sale, to deliver the purchase with that token attached.

Cometly then attributes each purchase back to the original visitor and ad click. That lets you see which campaign, ad set and ad produced each FastSpring sale, instead of only seeing that a sale happened.

**Before you start**

* The Cometly pixel is installed on the page that loads your FastSpring checkout. See [Install the Cometly pixel](https://docs.cometly.com/getting-started/install-pixel.md).
* You can edit the JavaScript on that page.

To learn more about the token itself, see [Comet Token](https://docs.cometly.com/concepts/comet-token.md).

## 1. Load the Cometly pixel before the FastSpring form script

Make sure the **Cometly tracking script** loads **before** the FastSpring checkout form script. This makes the `window.cometToken()` function available when FastSpring initializes.

Here is an example of the correct order. Use your own pixel snippet (copy it in Cometly from **Setup**, step **Install the Cometly pixel**) and your own FastSpring storefront:

```html theme={null}
<!-- Cometly pixel: paste your own snippet here -->
<script src="https://js.comet-serve.com/script.js?uid=YOUR_PIXEL_ID"></script>

<script
   id="fsc-api"
   src="https://sbl.onfastspring.com/sbl/1.0.5/fastspring-builder.min.js"
   type="text/javascript"
   data-storefront="yourstore.onfastspring.com/your-storefront"
   data-continuous="true"
   data-data-callback="fsUpdateBadge"
   data-error-callback="fsError">
</script>
```

> [!TIP]
>
> Always keep the Cometly script above the FastSpring script on your page.

## 2. Locate the existing FastSpring callback

In your site's JavaScript, find the callback function named in `data-data-callback`. In this example it is called `fsUpdateBadge`, and it runs when the checkout form is ready. Yours may look similar to this:

```javascript theme={null}
// FastSpring callback
function fsUpdateBadge(data) {
  (function () {
    function getCookie(name) {
      let match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
      if (match) return match[2];
      return "";
    }

    // Push tags once per session
    if (!sessionStorage.getItem('fsTagsPushed')) {
      console.log("Pushing tags...");
      fastspring.builder.push({
        tags: {
          _fbp: getCookie('_fbp'),
          _fbc: getCookie('_fbc'),
          _ttp: getCookie('_ttp'),
          ttclid: getCookie('ttclid')
        }
      });
      sessionStorage.setItem('fsTagsPushed', '1');
    }
  })();
}
```

This example sends various cookie tags (such as Facebook and TikTok parameters) to FastSpring once per session.

## 3. Update the callback to include the Comet Token

Next, change the callback so that it also pushes the **Cometly token** (`comet_token`) to the FastSpring form.

Here is the updated version of the example:

```javascript theme={null}
// FastSpring callback
function fsUpdateBadge(data) {
  // -- START -- Pushes comet_token to the FastSpring form
  fastspring.builder.push({
    tags: {
      comet_token: window.cometToken()
    }
  });
  // -- END -- Pushes comet_token to the FastSpring form

  (function () {
    function getCookie(name) {
      let match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
      if (match) return match[2];
      return "";
    }

    // Push tags once per session
    if (!sessionStorage.getItem('fsTagsPushed')) {
      console.log("Pushing tags...");
      fastspring.builder.push({
        tags: {
          _fbp: getCookie('_fbp'),
          _fbc: getCookie('_fbc'),
          _ttp: getCookie('_ttp'),
          ttclid: getCookie('ttclid')
        }
      });
      sessionStorage.setItem('fsTagsPushed', '1');
    }
  })();
}
```

What changed:

* The new block at the top pushes the `comet_token` into FastSpring as a custom tag.
* Each FastSpring transaction now includes the unique visitor token generated by Cometly.

## 4. Verify the token in FastSpring webhooks

After a purchase is completed, the `comet_token` appears in your FastSpring **webhook payload** under the `tags` object.

This confirms that the token passes through the checkout and is available for attribution.

## 5. Connect FastSpring webhooks to Cometly

Finally, send your FastSpring webhook data to Cometly.

1. In Cometly, click **Events Manager** in the sidebar, then click **Create Event**. Under **App / Integration**, select **Webhooks**, pick your **Purchase** event and click **Create**.
2. Copy the URL under **Your webhook URL** and add it as a webhook in FastSpring.
3. Follow the [Cometly Webhooks guide](https://docs.cometly.com/integrations/webhooks.md) to check for data, map the fields and activate the webhook.
4. In the mapping step, map the `tags.comet_token` field from the payload to Cometly's **Comet Token** field.

Once this is configured, Cometly can track your purchases through FastSpring.

## Check it worked

Complete a test purchase through your FastSpring checkout after the webhook is activated. In Cometly, click **Events Manager** in the sidebar, then open the **Events Log** tab: the purchase appears there within 60 seconds, with **SUCCESS** in the **Details** column and the `comet_token` in its data.

## Frequently asked questions

### How long does it take for a FastSpring purchase to show up in Cometly?

The purchase shows in the Events Log within 60 seconds of FastSpring sending the webhook. It can take up to 15 minutes to appear in the reporting areas, such as the Report Builder or Ads Manager.

### Why is my FastSpring test purchase not showing in Cometly reports?

Test data sent before the webhook was activated is not processed and does not appear in your reports. Activate the webhook first, then make a new test purchase. If it is still missing, open the **Events Log** tab in **Events Manager** and check the **Details** column for an error message.

### What happens if a FastSpring purchase arrives without the comet\_token?

Cometly still accepts an event that has an email address, because an email is enough to identify the person. The `comet_token` is what links the purchase to the visitor's browser session, so leaving it out makes attribution less accurate.

## Next steps

* [Map fields, add filters and activate your webhook](https://docs.cometly.com/integrations/webhooks.md)
* [Use the Events Log to check incoming events](https://docs.cometly.com/support/troubleshooting/general/event-log.md)
* [Learn more ways to use the comet\_token](https://docs.cometly.com/concepts/comet-token.md)
* [Learn how events work in Cometly](https://docs.cometly.com/guides/events/how-events-work.md)

Still have questions or need a hand? We're happy to help. Reach our team at [support@cometly.com](mailto:support@cometly.com).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.