Adrails Docs

Set up tracking

Put the Adrails script on your site, record sales and leads, and send them from your server so they reach Meta and Google Ads.

Tracking records visits, leads and sales on your own site, and credits them to the campaign and ad that brought the visitor. Events your server signs are also sent back to Meta and Google Ads, so their bidding learns from sales their pixel or tag missed.

It has two parts:

  • A script on your pages. It remembers where each visitor came from and records page views. Anything it sends stays in Adrails.
  • Calls from your server. Your server sends the sales and leads, signed with a secret key. Only these can reach Meta and Google Ads.

1. Create the tracking source

  1. Open Settings > Tracking.
  2. Enter your Website domain, such as example.com, and choose Set up tracking.

Subdomains are included: a checkout on shop.example.com counts for example.com. A workspace has one tracking source. You can add up to 10 domains to it under Allowed domains.

Only owners and administrators can set up and change tracking.

2. Add the script to every page

Copy the script from Install and paste it on every page of your site, before </head>:

<script async src="https://adrails.ai/api/tracking/script?key=atr_..."></script>

The address and the key in your snippet are your own; copy them from Settings, not from this page.

On each page, the script:

  • keeps a visitor id in a first-party cookie, _adrails_visitor_v1, for a year;
  • keeps the UTM parameters and click ids the visitor arrived with (utm_*, fbclid, gclid, ttclid, msclkid, campaign_id, adset_id, ad_id) for 90 days, in the browser's local storage under _adrails_attribution_v1;
  • builds Meta's fbc from fbclid, and reads Meta's _fbp cookie when your Meta pixel set one;
  • records a page_view;
  • defines adrailsTrack(eventName, fields), which records another event and returns its event_id.

Once the script is live, page views appear in Settings > Tracking within a minute: Last event 2 minutes ago, 1,240 in the last 7 days.

3. Record sales and leads

From the page: recorded in Adrails only

adrailsTrack("purchase", {
  event_id: "order-1042",
  value: 89.9,
  currency: "EUR",
  user: { email: "customer@example.com" }
});

This counts for attribution in Adrails. It is never sent to Meta or Google Ads.

From your server: sent to Meta and Google Ads

Send the same event from your server, with the server key in the Authorization header:

curl -X POST "https://adrails.ai/api/tracking/collect?key=atr_..." \
  -H "authorization: Bearer atr_server_..." \
  -H "content-type: application/json" \
  -d '{
    "event_name": "purchase",
    "event_id": "order-1042",
    "value": 89.9,
    "currency": "EUR",
    "fbc": "<_fbc cookie>",
    "fbp": "<_fbp cookie>",
    "gclid": "<saved gclid>",
    "user": { "email": "customer@example.com" }
  }'

Settings > Tracking shows this snippet with your keys filled in. The server key is shown to owners and administrators only. Every field is described in the API reference.

Send what you have:

  • For Meta: fbc and fbp are the _fbc and _fbp cookies your Meta pixel sets on your domain, read from the checkout request. event_id is the id your pixel sent for the same sale, so Meta counts it once.
  • For Google Ads: gclid is the click id saved when the visitor arrived. The script keeps it in local storage, under _adrails_attribution_v1: pass it to your server with the checkout, or save it yourself when the visitor lands.
  • For attribution in Adrails: visitor_id is the _adrails_visitor_v1 cookie, readable by your server on your own domain. It ties the sale to the visit and its campaign.

The two keys

Public keyServer key
Looks likeatr_...atr_server_...
Where it goesIn every page, in the scriptOn your server only
Who can see itAnyone who reads your pageOwners and administrators, in Settings > Tracking
Accepted fromYour allowed domains onlyAnywhere
Rate limit120 events per minute per visitorNone
Reaches Meta and Google AdsNeverYes, within the limits

The public key is in every page of your site, so anyone can send events with it. That is why events sent with it are only counted in Adrails. A forged sale reaching an ad platform would teach its bidding to buy more of nothing, with your money.

Never put the server key in a page, an app bundle or a public repository. Whoever holds it can send events as your site.

Avoid counting a sale twice

  • In Adrails: an event_id already recorded for your source is accepted but not recorded again, and not sent again. Use your order id, or another id unique to the sale.
  • In Meta: send the same event_id your pixel sent. Meta keeps one of the two.
  • In Google Ads: if the Google tag already counts the same sales, make one of the two conversion actions secondary in Google Ads.

Remove tracking

Remove tracking at the bottom of Settings > Tracking stops accepting the script and deletes every event recorded so far. Conversions already sent to Meta and Google Ads stay there. Remove the script from your site too.

Next

On this page