How to Track Affiliate Clicks Without a Plugin
Short answer: Use a GA4 outbound event for reporting, or a small server-side redirect at /go/ for full control. Both beat any plugin on speed and resilience.
Option 1: GA4 outbound click event
Cheapest path. Add a click handler to every outbound link that fires a GA4 event with the destination and network. No plugin, no extra request to a tracking server, no plugin updates to break the site.
document.addEventListener('click', (e) => {
const a = e.target.closest('a[href]');
if (!a) return;
const url = new URL(a.href, location.href);
if (url.host === location.host) return;
gtag('event', 'affiliate_click', {
destination: url.host,
href: a.href,
page: location.pathname,
});
});Build a GA4 exploration on the affiliate_click event. Group by destination host to see which networks produce the clicks, group by page to see which posts pull the weight.
Option 2: Server-side /go/ redirect
For publishers who want their own click log and the option to swap destinations without editing posts. The pattern: every affiliate link points to https://yoursite.com/go/{slug}. A small handler logs the click and 302s to the real destination.
// Cloudflare Worker example
export default {
async fetch(req, env) {
const slug = new URL(req.url).pathname.split('/').pop();
const dest = await env.LINKS.get(slug);
if (!dest) return new Response('Not found', { status: 404 });
// Log async, don't block the redirect
env.LOG.writeDataPoint({ slug, ts: Date.now() });
return Response.redirect(dest, 302);
},
};Storage choices: Cloudflare KV for the slug-to-URL map, Workers Analytics or Logflare for the click log. Total cost on Cloudflare\'s free tier: zero for most publishers.
Which approach to pick
- GA4 only. You want clicks counted but do not need to swap destinations. Five lines of JS, done.
- Server-side /go/. You want one place to manage destinations, full click logs, and the ability to A/B test merchants. Ships in an afternoon on Cloudflare or Netlify.
- Both. Fire the GA4 event from the click handler and route the link through /go/. Best of both, no plugin in either case.
Don\'t skip monitoring
Tracking tells you a click happened. It does not tell you the destination is alive. Pair either approach with a link health check that follows every redirect and validates the tracking parameters survive. Run a free scan to see what your /go/ links actually resolve to today.
Frequently asked questions
Why skip a plugin?
Plugins add load time, ship breakage with WordPress updates, and lock your data inside their dashboard. Server-side or GA4-based tracking puts the data in tools you already own.
Will GA4 actually attribute affiliate clicks?
Yes, with a custom event. Add an outbound click event with the destination URL and network as parameters, and GA4 will report click counts by network, page, and link.
What about server-side tracking?
Cloudflare Workers, Netlify Edge Functions, or a tiny Node service can intercept clicks at a /go/ path, log them, and 302 to the real destination. No plugin, no JS, fast.
Does this work for Amazon Associates?
Yes. Server-side redirects work for any network including Amazon. Make sure you preserve the tag parameter in the redirect target.
Related: Pretty Links vs ThirstyAffiliates vs native · Missing UTM parameters · UTM builder
Ready to automate affiliate link monitoring?
Start free — no credit card required, upgrade anytime.
Get started free