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

November 28, 2026 · Hoplytic team · 5 min read

The short version: this guide in 66 seconds.
Read the 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

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 pluginGoogle Analytics 4Hosted tracker + site script
ExamplesPretty Links, ThirstyAffiliates, LassoEnhanced measurement or Tag ManagerA tracker that matches sales to clicks
Counts clicks per linkYesOnly with a custom dimensionYes
Knows which postPartly, through referrer reports in some pluginsYesYes, plus the spot on the page
Connects to commissionNo, in most free versionsNoYes, through sub-IDs and postbacks
Works outside WordPressNoNoYes: email, YouTube, social
Main weaknessLinks live only while the plugin is activeBlocked by ad blockers and consent choicesOne more service to set up

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:

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.

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

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 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

Things that skew WordPress click numbers

CauseEffect on countsWhat to do
Crawlers, link previews, uptime monitorsToo highUse a tool that labels bots separately
Ad blockers and declined consentToo low in GA4Compare with redirect-based counts, which don't depend on page scripts
Page cachingOld pages without your new scriptPurge the cache after changes
Your own test clicksToo high on new linksTest once, or exclude your own visits
Links opened in a new tab by JavaScriptMissed by some click listenersUse 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 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 and keep the old /go/ addresses working through a redirect file. To go from clicks to money per post, see earnings per article.

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.

More in Tracking fundamentals

Also: tracking glossary · ad platform macros · Markdown copy