Impressions and clicks
The campaign list shows how many times a campaign’s ad has been shown to real visitors (Impressions), how many times visitors clicked it (Clicks) and the percentage of the two (CTR).
How it works
- Every ad is wrapped in two tiny hidden marker elements,
<span class="wpai-s" ...></span>before it and<span class="wpai-m" data-wpai="12" data-wpai-v="0" ...></span>after it (the campaign ID and the number of the ad inside the campaign), and a small script is added to the page. The marker is a part of the page HTML, so it also exists in cached pages. - The script runs in the visitor’s browser. It collects the campaign IDs found on the page.
- It waits until the page has been visible for about a second and a half.
- It sends the IDs, in one request, to the REST address
/wp-json/wpai/v1/hitof your site. - Your server adds one to the counter of every campaign in the request.
What is counted
- Once per visitor per campaign per day. The browser remembers the IDs it has already reported in its local storage (the key
wpai_seen) for 24 hours, so opening ten pages with the same ad counts once. - Bots are ignored. The script does not run for automated browsers or for user agents that look like crawlers, monitors and preview fetchers, and the server checks the user agent again. Bots that do not run JavaScript never reach the counter at all.
- Hidden tabs are ignored until the visitor looks at the page.
- With a persistent object cache on the server (for example Redis or Memcached) the server also drops repeated reports from the same visitor within a day.
This counts ads that were rendered on a page that a real visitor looked at. It is not a viewability measurement: an ad far below the fold counts too. If the browser blocks local storage, the visitor is counted again on every page.
Clicks
The script listens for clicks on the page. A click on a link that lies between the two markers of an ad is reported as a click of that ad. Middle clicks (a new tab) are counted too.
- A visitor is counted for at most five clicks per campaign per day, and a double click within three seconds counts once.
- Bots are ignored in the same way as for impressions.
- The browser keeps the content of frames private. A click inside an
<iframe>, which is how most ad network scripts (AdSense and others) show their ads, cannot be seen, so such ads show impressions only. The network’s own report has their clicks. Image and text ads with your own links are counted. - You can switch the counting off for a campaign with Count clicks on the Content tab.
Statistics of every ad
When a campaign has several ads (separated by <!--more-->), the Statistics tab of the campaign editor shows the impressions, clicks and CTR of each of them, and marks the ad with the best CTR after it has been shown 100 times. Use it to find which of the ads works best. The same tab has a button to reset the statistics. The numbers of each ad are collected from version 1.2.0.
The old counter
Before version 1.2 the plugin counted every time the server generated an ad, including bots and every page of the same visitor, and it did not work behind a page cache. That number is kept and added to the new one, so the column does not start from zero.
Where the numbers live
Every campaign has its own option wpai_hits_<campaign ID> with the impressions and wpai_clicks_<campaign ID> with the clicks, and every ad of a rotation has wpai_vh_<ID>_<n> and wpai_vc_<ID>_<n>. It is increased with a single database query and is not loaded on page views. The counters are deleted when you delete the campaign. Only the numbers are stored, no IP addresses and no visitor identifiers.