Skip to content

Server-Side Client ID

Set up server-side client ID generation for scenarios where the AnyTrack Tracking Tag cannot load. Send PageView events, track conversions with standard events, and enrich data with event attributes using the collect endpoint.

⚠️ Warning

This is an advanced implementation that requires working knowledge of JavaScript, server-side HTTP requests, and JSON payloads. If you can install the Tracking Tag on your website, use that instead — it handles session creation and event tracking automatically with no code required.

When the Tracking Tag cannot run on your page — Facebook Lead Ads, offline campaigns, headless checkouts, or landing pages you do not control — you can generate a client ID server-side and send events directly to the AnyTrack collect endpoint.

This creates a visitor session without any browser-side JavaScript. Once the session exists, you can track conversions through the webhook endpoint using the click_id or refId parameter, just like any other integration.

Important

Replace {propertyid} with your actual AnyTrack Property ID. You can find it in your Property Settings.

  1. Generate a random 14-character alphanumeric cid (client ID)
  2. POST a JSON payload to the collect endpoint with the cid, event name, page URL, and timestamp
  3. AnyTrack creates a visitor session tied to that cid
  4. Send subsequent conversion events through the webhook endpoint using the click_id or refId
https://t1.anytrack.io/assets/{propertyid}/collect

Send a POST request with a JSON body containing the following fields.

FieldTypeRequiredDescriptionExample
cidstringYesClient ID: a unique, random 14-character alphanumeric string. You generate this value.o5p4JFQGh1Yku4
enstringYesEvent name. Use PageView to create the initial session.PageView
tsstringYesTimestamp in milliseconds (Unix epoch).1662315001464
ncintegerYesNew client flag. Set to 1 for a new visitor, 0 for a returning one.1
dlstringYesDocument location. The full page URL including UTM parameters and click IDs.https://example.com/?utm_source=google&gclid=abc
dtstringYesDocument title. The page title associated with this event.My Landing Page
drstringNoDocument referrer. The URL the visitor came from.https://google.com
ridstringRecommendedExternal ID from your database (customer ID, lead ID). Use this to resolve identity and attribute conversions via refId instead of click_id.customer_12345
{
"cid": "o5p4JFQGh1Yku4",
"en": "PageView",
"dl": "https://example.com/?utm_source=google&utm_medium=cpc&utm_campaign=tof-campaign&utm_id=12312321&gclid=abc123",
"dt": "My Landing Page",
"dr": "https://google.com",
"nc": 1,
"ts": "1662315001464",
"rid": "lead_98765"
}

📘 Note

Include all UTM parameters and ad platform click IDs (gclid, fbclid, ttclid) in the dl field. AnyTrack parses these automatically to attribute the session to the correct campaign.

The cid is a random 14-character alphanumeric string (a-z, A-Z, 0-9). Each visitor must receive a unique value. Here are examples for common automation tools:

// Generates a random 14-character alphanumeric client ID
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let cid = '';
for (let i = 0; i < 14; i++) {
cid += chars.charAt(Math.floor(Math.random() * chars.length));
}
output = [{ cid }];
// Use in a Make Custom JavaScript module
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let cid = '';
for (let i = 0; i < 14; i++) {
cid += chars.charAt(Math.floor(Math.random() * chars.length));
}
return cid;
import random
import string
# Generate a 14-character alphanumeric client ID
cid = ''.join(random.choices(string.ascii_letters + string.digits, k=14))
const crypto = require('crypto');
// Generate a 14-character alphanumeric client ID
const cid = crypto.randomBytes(10).toString('base64url').slice(0, 14);

After creating the initial session with a PageView event, you can send conversion events through the AnyTrack webhook endpoint. Use standard event names so AnyTrack automatically maps them to each ad platform’s format.

Event NameDescriptionEvent Source
PageViewPage view, automatically triggered on page load. Use this to create the initial session via the collect endpoint.Browser
ViewContentUser views a product pageBrowser
OutboundClickUser clicks an external link (generates a click_id automatically)Browser
AddToCartUser adds an item to cartBrowser & Server-side
InitiateCheckoutUser starts a checkoutBrowser & Server-side
AddPaymentInfoUser adds payment details during checkoutBrowser & Server-side
FormSubmitUser submits an online formBrowser
LeadLead event with a 0 monetary valueServer-side
CompleteRegistrationLead event with a monetary valueServer-side
PurchasePurchase event with a monetary valueServer-side
UpsellSubsequent sale after the initial purchaseServer-side

Send these events via the webhook endpoint after the session is created:

{
"click_id": "{propertyid}{cid}",
"event_name": "Lead",
"value": 0,
"currency": "USD",
"transactionId": "txn_abc123"
}

Or use the refId (external ID) if you passed a rid during session creation:

{
"refid": "lead_98765",
"event_name": "Purchase",
"value": 200,
"currency": "USD",
"transactionId": "order_xyz789"
}

📘 Note

The click_id for server-side sessions is the Property ID concatenated with the cid you generated: {propertyid}{cid}. If you passed a rid during the collect call, you can use refid instead. Learn more about using an external ID as click ID.

Include event attributes in your webhook payload to improve Event Match Quality and give ad platforms richer signals for optimization.

Customer traits are automatically hashed and normalized before being sent to ad platforms. There is no need to hash the data yourself.

AttributeTypeExample
emailstringjsmith@example.com
firstNamestringJohn
lastNamestringSmith
phonestring+16505554444
citystringMenlo Park
statestringCA
zipcodestring94025
countrystringUS
AttributeTypeExample
valuenumber142.50
currencystringUSD
transactionIdstringorder_xyz789
brandstringNike
shippingPricenumber9.99
taxPricenumber12.50
itemsarraySee Product Attributes
{
"refid": "lead_98765",
"event_name": "Purchase",
"value": 142.50,
"currency": "USD",
"transactionId": "order_xyz789",
"email": "jsmith@example.com",
"firstName": "John",
"lastName": "Smith",
"phone": "+16505554444",
"brand": "Nike",
"items": [
{
"id": "SKU-001",
"name": "Air Max 90",
"price": 142.50,
"quantity": 1,
"brand": "Nike",
"category": "Shoes"
}
]
}

The more attributes you include, the higher your Event Match Quality score. Higher scores mean better attribution, more accurate lookalike audiences, and improved return on ad spend (ROAS). See the full list of supported attributes in the Event Attributes article.

Lead ad forms run natively inside the ad platform — your website never loads, so the Tracking Tag cannot execute. Generate a cid server-side when the lead arrives (via Zapier, Make, or the platform’s webhook), send a PageView to the collect endpoint with the ad URL and UTM parameters, then send a Lead event through the webhook with the customer’s email and phone.

Phone calls, in-store visits, and events that happen outside a browser. Create a session with the campaign URL that drove the offline action, then post the conversion event (e.g., Purchase, Lead) when the sale closes. Include customer data for identity matching.

Checkout pages hosted on a third-party domain where you cannot install the Tracking Tag. Generate a cid on your server, pass it through the checkout flow, and send InitiateCheckout and Purchase events from your backend when the order completes.

When a CRM status changes (e.g., a lead moves to “Qualified” or “Closed Won” in HubSpot or Salesforce), trigger a Zap or Make scenario that generates a cid, creates a session with the original campaign URL, and sends the appropriate conversion event to AnyTrack.

Affiliate campaigns or partner pages where you cannot add JavaScript. Use the rid field to pass your own lead or customer ID during session creation, then track conversions server-side as they happen in your system.

Server-Side Client ID FAQ

FAQ was last reviewed on 2026-06-10

What is the AnyTrack Client ID?
The Client ID (cid) is a unique cookie ID — a random 14-character alphanumeric string that anonymously identifies a user in AnyTrack. When the Tracking Tag runs in the browser, it generates and stores this value as a first-party cookie automatically. In server-side implementations where the Tracking Tag cannot load, you generate the cid yourself and send it to the collect endpoint to create the session manually.
Why is the Client ID required to track conversions?
Every conversion in AnyTrack must be tied to an identified user. The cid is the anonymous identifier that makes this possible — it connects a conversion event (like a Purchase or Lead) back to the ad click, UTM parameters, and campaign data that started the journey. Without a cid, AnyTrack has no way to create the user session or build the attribution chain. No cid means no session, no attribution, and no data sent to your ad platforms.
What is an external ID (refid) and why do I need it?
The external ID (refid) is used to alias an AnyTrack cid with an external identifier that you control — such as an email address, phone number, or anonymous ID from your own system. You pass it as rid when creating the session via the collect endpoint. This is often needed when the AnyTrack click_id cannot be passed to your CRM, cart, or conversion source (for example, HubSpot, GoHighLevel, or other CRMs). In simple terms: when AnyTrack tracks an event in the browser, a click_id is generated. When you associate it with an external ID, you are telling AnyTrack that this click_id belongs to a specific email, and every future event sent identified by this email should be matched to the same user.
What is the difference between the Client ID and the Click ID?
The Client ID (cid) is a unique cookie ID that anonymously identifies a user. The Click ID (click_id) is a unique event identifier generated by the Tracking Tag on the client side — it associates a specific action that a cid performs to a Property ID and a timestamp. All event attributes (customer data, transaction details, product information) are associated to the click_id. In server-side implementations, you generate the cid yourself and construct the click_id by concatenating the Property ID with the cid.
Does each visitor need a unique cid value?
Yes. The cid is a unique 14-character alphanumeric string that identifies a single visitor session. Reusing the same cid across different visitors will merge their data into one session, corrupting attribution. Generate a new random value for every visitor.
When should I use server-side client ID instead of the Tracking Tag?
Use server-side client ID only when the Tracking Tag cannot run: Facebook or TikTok Lead Ads (no website loads), offline conversions, headless checkouts on third-party domains, or landing pages you do not control. In all other cases, the Tracking Tag is the recommended approach because it captures richer browser-side data automatically.
Can I send multiple conversion events after creating a single session?
Yes. Create one session with a PageView event via the collect endpoint, then send as many conversion events as needed through the webhook endpoint using the same click_id or refid. For example, you can track Lead, then InitiateCheckout, then Purchase as the customer progresses through your funnel.
Which AnyTrack plans support the server-side collect endpoint?
The collect endpoint is available on all AnyTrack plans. There are no plan-specific restrictions for server-side client ID generation.