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
- Open Settings > Tracking.
- 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
fbcfromfbclid, and reads Meta's_fbpcookie when your Meta pixel set one; - records a
page_view; - defines
adrailsTrack(eventName, fields), which records another event and returns itsevent_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:
fbcandfbpare the_fbcand_fbpcookies your Meta pixel sets on your domain, read from the checkout request.event_idis the id your pixel sent for the same sale, so Meta counts it once. - For Google Ads:
gclidis 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_idis the_adrails_visitor_v1cookie, readable by your server on your own domain. It ties the sale to the visit and its campaign.
The two keys
| Public key | Server key | |
|---|---|---|
| Looks like | atr_... | atr_server_... |
| Where it goes | In every page, in the script | On your server only |
| Who can see it | Anyone who reads your page | Owners and administrators, in Settings > Tracking |
| Accepted from | Your allowed domains only | Anywhere |
| Rate limit | 120 events per minute per visitor | None |
| Reaches Meta and Google Ads | Never | Yes, 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_idalready 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_idyour 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
- Send conversions to Meta and Google Ads: connect a dataset or a conversion action, and the limits that protect them.
- API reference: every field, status and error.
MCP security
How the MCP server keeps a connection inside one workspace and the permissions you granted, what data leaves Adrails through it, and what Adrails records.
Send conversions to Meta and Google Ads
Send the events your server signs to a Meta dataset and a Google Ads conversion action, within a value limit and a daily limit.
