Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 5 min read

Transparent Click Tracking: Custom Tracking Domains, Redirects and Postbacks

A click tracker sits between the ad and the landing page. It records the click, gives it an id, and sends the visitor on. Done badly, it is a black box that ad networks distrust and that adds delay. Done well, it is tran

Transparent Click Tracking: Custom Tracking Domains, Redirects and Postbacks

A click tracker sits between the ad and the landing page. It records the click, gives it an id, and sends the visitor on. Done badly, it is a black box that ad networks distrust and that adds delay. Done well, it is transparent : it runs on your own domain, it says exactly where it sends people, and it adds nothing but its own id.

This is how I built the click tracker in EventsIQ.

Step 1: a tracking domain of your own

The ad link should point at a subdomain you own, like track.yoursite.com, not at the tracker company's domain. Visitors and ad networks see your name.

Setting one up is a single DNS record:

track.yoursite.com CNAME <the tracker's address>

Behind the scenes, EventsIQ uses Cloudflare for SaaS custom hostnames for this. When a customer adds their subdomain, the app registers it with Cloudflare, Cloudflare checks the CNAME and issues the HTTPS certificate, and the status moves from "Waiting for DNS" to "Issuing certificate" to "Live". The customer never handles a certificate.

Two small rules that save support tickets:

  • Refuse a bare domain. Pointing yoursite.com itself at a tracker would take over the whole website. Only subdomains are allowed.
  • Help with DNS panels. Providers like Namecheap and GoDaddy add your domain to the Name field for you, so the customer should type only track.

Two kinds of tracking domain: a shared subdomain that works straight away, or your own that needs one DNS record.

Step 2: record the click, then one plain redirect

When a visitor hits the tracking link, the tracker:

  1. Reads the campaign from the link and the macros the network filled in (campaign id, ad id, click id).
  2. Records the click and gives it its own id, for example eiq_click=ck_8f21a.
  3. Sends the visitor to the landing page with one HTTP 302 , adding its click id.

No meta refresh, no JavaScript redirect, no second hop. Each extra hop costs time on a phone and loses visitors.

The landing page form then keeps that click id (in EventsIQ for 90 days). When the form is submitted, the lead carries the click id, and the server joins the two. From then on the lead knows its campaign, ad, ad set and the network's own click id, even if the page never saw them.

Transparent means the link names its destination

Google Ads is the strictest network here. The ad's Final URL has to be the real landing page. A tracker may only sit in the tracking template , and it must show where it sends the visitor next.

So the tracking template carries the destination in plain sight:

https://track.yoursite.com/spring?...&gclid={gclid}&eiq_url={lpurl}

Google replaces {lpurl} with the Final URL. When a link carries eiq_url, the tracker goes exactly there. It skips everything a normal campaign could do on the redirect: no routing rules, no split tests, no swapped page.

Not an open redirect

A tracker that follows any address it is given can be abused to send people anywhere under your brand. So the tracker checks the host in eiq_url against the landing pages the campaign already uses. An unknown host gets a 404. The check is by host, not by full address, so a different path or your own utm_source does not cause real clicks to be refused.

Google's parallel tracking

Google runs most clicks through parallel tracking. The browser opens the landing page directly, and loads the tracking template in the background at the same time. In that background request, Google swaps {lpurl} for an address of its own on google.com/asnc/, so the page is not loaded twice.

One click goes two ways: the page opens straight away, and the tracking link records the click and its gclid in the background.

That changes how the lead finds its click. The visitor never passes through the tracker, so the page never gets eiq_click. Instead:

  1. The tracker records the click with the real gclid and redirects the background request to Google's address, unchanged (and only if it really is google.com over HTTPS under /asnc/).
  2. The page has the same gclid on its URL, from Google.
  3. The lead is joined to the click by that shared gclid.

One more detail stops a click being counted twice. Without a tracker in front, a page normally asks the server for a click id itself (direct mode). Under parallel tracking that would make a second click. So the Final URL suffix carries a small marker, eiq_tracked=1, which tells the page the click is already recorded.

Step 3: postbacks for sales that happen later

In lead generation, the sale often happens days later, in a buyer's CRM. The tracker cannot see that. A postback closes the gap: the CRM calls a URL when the status changes.

https://app.eventsiq.io/cv?click_id={click_id}&event=sold&value={value}&key=YOUR_KEY

The server then walks the chain:

  1. Find the click by its id.
  2. Find the click's campaign.
  3. Find the campaign's conversion integration (which pixel or Google Ads account).
  4. Send the event there, with the network's own click id saved on the lead.

A postback travels from the CRM through the click and campaign to the right pixel.

The nice part: the CRM never needs to know about pixels. Five campaigns on three ad accounts can all send event=sold, and each sale lands on the right pixel, because the campaign decides where it goes.

For leads that never had a click (Meta or TikTok instant forms), the CRM can post back with lead_id instead of click_id.

What to take away

  • Put the tracker on the customer's own subdomain. One CNAME, certificates handled for them.
  • Record the click, then send one plain 302 that names where it goes.
  • Check the destination host, so the tracker is never an open redirect.
  • Handle Google's parallel tracking by joining on the gclid, and mark tracked visits so nothing counts twice.
  • Let CRMs report later sales with a simple postback URL, and let the campaign decide which pixel hears about it.

The last step, actually sending the sale to Meta, TikTok and Google, is the subject of the next post.

Let's Work Together

If you are building tracking or attribution and want a hand, contact me here: LinkedIn

Originally published at www.hassaanistic.com/blogs/transparent-click-tracking-custom-domain.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.