# How to track affiliate link clicks in WordPress (and which post earned the sale)

> Three ways to count affiliate link clicks in WordPress: a link plugin, Google Analytics or a hosted tracker with a site script. Setup, limits and fixes.

Source: https://hoplytic.com/blog/track-affiliate-clicks-wordpress · Updated 2026-11-28 · Hoplytic Guides

Video version (66 seconds): [https://hoplytic.com/video/track-affiliate-clicks-wordpress.mp4](https://hoplytic.com/video/track-affiliate-clicks-wordpress.mp4)

## Video transcript

How do you track affiliate clicks in WordPress, and find which post earns?

A link plugin is enough for click counts per link. Google Analytics four gives clicks per page, but cloaked links on your own domain need a custom event. A tracker with a site script is the only method that connects a click on a post to a commission.

Set links to three-oh-two or three-oh-seven, not three-oh-one, or returning visitors skip the plugin. Bots and link previews can inflate your counts.

Each click gets an ID in the network's sub-ID, like clickref on Awin or SID on CJ. A small script on your pages records the post, the spot and the link text. Wrap spots in a data spot attribute to compare them.

In Hoplytic, you paste the affiliate link and the click ID fills the network's sub-ID. The site script adds page, spot and link text to every click, without cookies. You can import links from Pretty Links, ThirstyAffiliates or Lasso, and keep the old addresses working.

The full guide is right below. Hoplytic: ad tracking made simple.

## Key points

- A link plugin counts clicks per link, GA4 counts clicks per page, and only a tracker with sub-IDs connects clicks to commission.
- To know which post and which button earned, you need both the page of the click and a click ID that comes back with the sale.
- Caching, ad blockers and bots change your click counts; know which way each one pushes the number.
- Mark affiliate links with rel="sponsored" whatever tool you use; tracking and disclosure are separate jobs.

You have 140 posts and a few hundred affiliate links. Some posts earn, most don't, and the network report only says "Amazon: 31 sales". Tracking clicks inside WordPress is the first step to knowing which post and which button did the work.

**Short answer:** for click counts per link, a link plugin is enough. For clicks per page, use GA4's outbound click events. To connect clicks to commission per post, use tracking links that put a click ID in the network's sub-ID, plus a small script on your pages that records which post and spot each click came from.

## The three methods

| | Link plugin | Google Analytics 4 | Hosted tracker + site script |
| --- | --- | --- | --- |
| Examples | Pretty Links, ThirstyAffiliates, Lasso | Enhanced measurement or Tag Manager | A tracker that matches sales to clicks |
| Counts clicks per link | Yes | Only with a custom dimension | Yes |
| Knows which post | Partly, through referrer reports in some plugins | Yes | Yes, plus the spot on the page |
| Connects to commission | No, in most free versions | No | Yes, through sub-IDs and postbacks |
| Works outside WordPress | No | No | Yes: email, YouTube, social |
| Main weakness | Links live only while the plugin is active | Blocked by ad blockers and consent choices | One more service to set up |

## Method 1: a link plugin

Link plugins create addresses like `yoursite.com/go/standing-desk` that redirect to the affiliate link, and count each hit. Setup is quick: install, create a link, paste the short address into your post.

What to watch:

- **Bots inflate counts.** Crawlers and link previews request your `/go/` URLs too. Check whether your plugin filters them and how; if click counts look far higher than your traffic suggests, that's usually why.

- **Redirect type.** Set links to 302 or 307, not 301. A cached 301 means returning visitors skip the plugin, so their clicks aren't counted.

- **The plugin is a single point of failure.** Deactivate it, change permalinks or move hosts carelessly, and every short link returns a 404. See [affiliate links that never break](https://hoplytic.com/blog/affiliate-links-that-never-break).

- **Clicks aren't sales.** A plugin counts that someone clicked. It can't tell you which click bought unless it adds a click ID to the network link and reads back conversions.

## Method 2: Google Analytics 4

GA4 records clicks on links that leave your domain as outbound click events, with the link URL. That answers "which pages send clicks to which merchants", which a plugin often can't.

The catch for WordPress affiliates: a cloaked link on your own domain, like `yoursite.com/go/desk`, doesn't leave your domain, so GA4 doesn't count it as outbound. You need a custom event for those. The full setup, including the custom dimension you need to see link URLs in reports, is in [GA4 outbound affiliate clicks](https://hoplytic.com/blog/ga4-outbound-affiliate-clicks).

GA4 also misses visitors who block it or decline analytics cookies, so treat its click numbers as a sample, not a total.

## Method 3: tracking links plus a site script

This is the only method that ties a click on a specific post to a specific commission. It has two parts.

### Part 1: a click ID in the sub-ID

Each click on a tracking link gets a unique ID, for example `c7f3a9e1`, and the tracker puts it in the network's [sub-ID](https://hoplytic.com/blog/sub-id-tracking) field: `clickref` on Awin, `sid` on CJ, `subId1` on Impact. When the sale comes back, by postback or from the network's report, it carries `c7f3a9e1`, and the tracker knows exactly which click it was.

### Part 2: the page and spot of the click

The referrer alone is unreliable: browsers often trim it to just the domain. A small script on your pages records the post, the spot and the link text at the moment of the click. To compare spots inside a post, wrap them:

`<div data-spot="comparison-table">
... your table with affiliate links ...
</div>
<div data-spot="verdict-button">
<a href="https://go.yoursite.com/desk">Check the price</a>
</div>`
Now a sale can be reported as "post: best standing desks, spot: comparison-table, link text: Check the price".

### Adding a script to WordPress

- Use a code snippets plugin such as WPCode and add the line to the footer, so it loads on every page.

- Or add it to your theme's footer template. Use a child theme, or it disappears on the next theme update.

- Clear your caching plugin and any CDN cache afterwards, then view the page source to confirm the line is there.

## Things that skew WordPress click numbers

| Cause | Effect on counts | What to do |
| --- | --- | --- |
| Crawlers, link previews, uptime monitors | Too high | Use a tool that labels bots separately |
| Ad blockers and declined consent | Too low in GA4 | Compare with redirect-based counts, which don't depend on page scripts |
| Page caching | Old pages without your new script | Purge the cache after changes |
| Your own test clicks | Too high on new links | Test once, or exclude your own visits |
| Links opened in a new tab by JavaScript | Missed by some click listeners | Use plain `<a href>` links |

## Disclosure and rel attributes

Tracking doesn't replace disclosure. Google asks site owners to mark paid and affiliate links with `rel="sponsored"` (or `nofollow`), and most networks and the FTC expect a clear affiliate disclosure near the links. Many block editors and link plugins can add the rel attribute automatically.

## Doing it with Hoplytic

In Hoplytic you paste the affiliate link, the network is recognized and its sub-ID filled with the click ID, and you can put the link on your own domain such as `go.yoursite.com`. The [site script](https://hoplytic.com/help/site-script) adds page, spot and link text to every click, without cookies, and the Pages report shows which posts earn across all networks. If your links are already in Pretty Links, ThirstyAffiliates or Lasso, you can [import them](https://hoplytic.com/help/import-links) and keep the old `/go/` addresses working through a redirect file. To go from clicks to money per post, see [earnings per article](https://hoplytic.com/blog/earnings-per-article).

![Copying Hoplytic's one-line site script from the Site script page, to paste before the closing body tag on every page.](https://hoplytic.com/video/howto-site-script.gif)

*Copy the one line and paste it before </body> on every page.*

## Questions people ask

### Does WordPress track link clicks by itself?

No. WordPress has no built-in click tracking. You need a plugin, an analytics tool such as Google Analytics, or an external tracking link.

### Do caching plugins break affiliate click tracking?

They can break plugin-based counting that runs in PHP on each page view, and they can serve an old page without a tracking script you just added. Clear the cache after any tracking change and test a click.

### Which is better for WordPress: Pretty Links or a hosted tracker?

A plugin is simpler if you only need cloaked links and click counts on one site. A hosted tracker is better when you also share links outside WordPress, want sales matched to clicks, or want links that survive a plugin or host change.
