# External ID as Click ID

> Learn how to use an external identifier from a third-party platform as the AnyTrack Click ID to track server-side conversions. Covers the refId parameter, how aliasing works, and a step-by-step setup guide for connecting external platform data with AnyTrack attribution using custom integrations and webhooks.

AnyTrack allows you to use an external identifier instead of the AnyTrack Click ID to track server-side conversions. The `refId` parameter aliases any third-party value (a cart ID, lead ID, or user ID) with the AnyTrack Click ID, so conversions can be matched even when the external platform cannot store custom parameters.

> ❗ **Important**
>
> This guide requires JavaScript skills or the ability to use Google Tag Manager to capture variables, cookies, or event data from the browser. If you are not comfortable with code, share this article with your developer.

## When to Use External IDs

- The platform where conversions happen does not accept custom parameters like the AnyTrack Click ID
- You cannot modify forms, or forms are generated programmatically via JavaScript
- The platform's webhooks do not include custom fields

## How It Works

The `refId` parameter creates an alias between the AnyTrack Click ID and an external identifier. When a conversion event arrives via webhook, AnyTrack uses the alias to match it back to the original session.

**Standard flow (Click ID available):**

During the `AddToCart` event, AnyTrack passes the Click ID to the cart object. During the `Purchase` event, the platform returns the same Click ID in the webhook payload:

```javascript
AnyTrack('trigger', 'AddToCart', {
  customId: 'e.clickId',
  cartId: '{{cartId}}',
  value: '{{cartValue}}',
  currency: '{{currency}}',
  items: [{
    id: '{{skuId}}',
    price: '{{price}}',
    quantity: '{{quantity}}',
    name: '{{itemName}}'
  }],
  token: '{{cartToken}}'
});
```

**External ID flow (Click ID not available):**

During the `AddToCart` event, AnyTrack records the Click ID and aliases it with the `cartId` using the `refId` parameter:

`click_id = refId = cartId`

When the platform sends a webhook with the `cartId`, AnyTrack resolves the alias and ties the conversion back to the original Click ID:

```javascript
AnyTrack('trigger', 'AddToCart', {
  refId: '{{cartId}}',
  cartId: '{{cartId}}',
  value: '{{cartValue}}',
  currency: '{{currency}}',
  brand: '{{itemName}}',
  items: [{
    id: '{{skuId}}',
    price: '{{price}}',
    quantity: '{{quantity}}',
    name: '{{itemName}}'
  }],
  token: '{{cartToken}}'
});
```

## Setup Guide

### Step 1: Trigger an Event with refId

Fire an event using the AnyTrack Event Snippet and include the `refId` parameter with the external identifier value:

```javascript
AnyTrack('trigger', 'AddToCart', {
  refId: '12831238',
  cartId: '12831238',
  value: '200',
  currency: 'USD',
  items: [{
    id: '111',
    price: 200,
    quantity: 1,
    name: 'Tesla'
  }],
  token: 'asdasdjkasdj'
});
```

When this snippet executes, AnyTrack automatically aliases the Click ID with the `refId` value. The alias is stored server-side and used to match incoming webhook conversions.

### Step 2: Create a Custom Integration

Navigate to the [integration catalog](https://dashboard.anytrack.io/catalog/) and create a custom integration. The system issues a webhook URL:

```
https://t1.anytrack.io/GqxV3nTo/collect/custom-test
```

Depending on how the third-party system formats its webhook payload, you may need to remap parameters to match the AnyTrack [event attributes](/docs/event-attributes) format.

### Step 3: Send the Conversion via Webhook

When the conversion happens, the platform sends a webhook containing the external ID. The `refId` in the payload matches the alias created in Step 1:

```json
{
    "event_name": "Purchase",
    "email": "customer@example.com",
    "refId": "12831238",
    "fullName": "John Doe",
    "phone": "+1234567890",
    "country": "US",
    "items": [{
      "id": "111",
      "price": 200.00,
      "quantity": 1,
      "name": "Product Name"
    }],
    "currency": "USD",
    "id": "24356562534585",
    "subtotalprice": 200.00,
    "totalprice": 200.00,
    "taxPrice": 10.00,
    "value": 200.00,
    "transactionId": "#24356562534585"
}
```

AnyTrack resolves the `refId`, connects it to the original Click ID, and forwards the conversion to all connected ad platforms via Conversion API.

***

## Related Resources

- [Install AnyTrack Tag](/docs/install-anytrack-tag)
- [Click ID usage](/docs/generate-retrieve-and-use-atclid)
- [AnyTrack Click ID](/docs/anytrack-click-id)

<FaqAccordion
  title="FAQ & Troubleshooting"
  items={[
    {
      question: "What types of external IDs can I use?",
      answer: "Any unique identifier that is available both in the browser and in the platform's webhook payload. cart IDs, lead IDs, user IDs, email addresses, or cookies. The key requirement is that the same value appears in both the client-side event and the server-side webhook."
    },
    {
      question: "Can I use refId with any AnyTrack event type?",
      answer: "Yes. The refId parameter works with any event triggered via the AnyTrack Event Snippet. Common use cases include AddToCart, Lead, and custom events where the destination platform cannot accept the AnyTrack Click ID directly."
    },
    {
      question: "What happens if the webhook payload format does not match AnyTrack parameters?",
      answer: "You can remap webhook fields using an automation tool like Integromat (Make) to match the AnyTrack event attributes format before sending the data to the AnyTrack webhook endpoint."
    },
    {
      question: "How is this different from standard Click ID tracking?",
      answer: "Standard tracking passes the AnyTrack Click ID directly through forms or links. External ID tracking creates an alias between the Click ID and a third-party identifier, which is useful when the destination platform cannot store or return the AnyTrack Click ID."
    }
  ]}
/>
