Posts Tagged ‘adverts’

Ad Logger ‘click logging’ plugin for WordPress

Tuesday, October 4th, 2011

Ad Logger for WordPress is a new plugin for logging clicks on iframe adverts and other social network buttons. At the moment it can log Google AdSense / Amazon Associates adverts, and Facebook, Twitter and Google +1 social media buttons. It also has a ‘catch-all’ mode which will log any other iframe clicks.

Clicks stats in one place – You can get statistics for all these services individually but Ad Logger allows you to see all the clicks in one place. It will however give you different number; Ad Logger counts raw clicks, whereas your ad/social media provider will count valid clicks.

Raw click logs – With Ad Logger you can see the raw logs which will give you information that your ad/social media provider probably won’t allow you to see such as IP address, page referrer, and browser agent.

Reports – Ad Logger has an AJAX UI to allow you to move through the results easily. As well as seeing the log you can view reports showing the which browser, referrer, page, IP most of your clicks come from. And you can filter the results to show all the logs for a specific IP, page, iframe type, etc by clicking on the type icon, or the ⇓ arrows.

Click bombing protection – As it has access to the raw click logs Ad Logger can help you to combat intentional or accidental AdSense ‘click bombing’ by disabling adverts if too many clicks are registered. It can disable ads that you may have inserted using the Ad Injection plugin, or by dynamically hiding the div that you have put the adverts into.

Ad Logger’s main UI

Here is the main UI, from top to bottom you can see the yellow message bar which I use to highlight the latest updates, then the navigation buttons. To the right of the navigation buttons are the report links.
Next is the main log table – you can see it combines clicks from AdSense, Amazon Associates, Facebook, Twitter and Google +1. You can click on the type icon or the ⇓ arrows to filter your results.
Under the table you can set how many rows are shown at once.
Next are the boxes to select which iframes are logged.
Then the optional click blocking preferences.
Finally you can configure what information is shown in the log table, and what information gets stored to the database.

ad logger main ui

Example Ad Logger report

This is the type report and shows how many clicks occurred on each type of iframe. Here you can see that there were 27 clicks on Facebook like buttons, and 5 on Google +1.

ad logger type report

Filtered report

By clicking on any of the ‘type’ icons you can filter your results to just that type. Here I clicked on the Facebook icon and so am just seeing Facebook button clicks.

ad logger filtered

How does it work?

Ad Logger works by using JavaScript to monitor whether a click has ‘probably’ occurred. I say probably because this method isn’t 100% accurate. It is pretty good though. It notes when the mouse pointer has entered the iframe, and then listens for a ‘blur’ even which corresponds quite well to someone clicking on the ad/social button.

Ad Logger does not modify your original ad code, so hopefully won’t break your ad provider’s TOS. I can’t however guarantee this, so you have to make a judgement call as to whether you think it is safe for you to use.

Results are stored in a new table in your WordPress database. This table can be cleared of data at any time, and it will be automatically deleted if you uninstall the plugin. The plugin limits the size of the table to 100,000 rows (this will be configurable in a later release).

If you have configured click blocking then Ad Logger will use a cookie to count how many clicks have occurred. If the limit is reached then Ad Logger can then set another cookie which will prevent Ad Injection’s ads from being added to new pages, and/or it can remove the div containing the ads from the current page.

How much does it cost?

Nothing! £0, $0! You are however welcome to make a donation via the plugin UI if you find it useful. I have spent several hundred hours of my own time producing this plugin, which I have now released under a GPLv2 licence.

How do I install Ad Logger?

Ad Logger is available for free from the WordPress plugin repository.

The easiest way to install it by searching for ‘Ad Logger’ from the ‘Add New’ link in the ‘Plugins’ section of the WordPress UI.

Future planned features

Future planned features include being able to block adverts by IP address (which will work either standalone with Ad Logger, or in conjunction with Ad Injection), more awareness of other iframe types, and possibly the ability to log non-iframe events. E.g. other advertising/affiliate link clicks.

Include a different advert in each WordPress post depending on category

Sunday, September 11th, 2011

I’ve had many requestes from people who want to include different adverts on each post according to the post category. One example would be a football website that has a different post category for each team. They might want different ads to show depending on the team. E.g. ads for Liverpool F.C. might not appeal to followers of Manchester United!

With Ad Injection there is no way to achive this directly in the UI, but by adding some simple PHP code to one of the ad slots you can do this.

1. In your plugins directory create a sub-directory called ‘ad-injection-ads’. e.g. /wordpress/wp-content/plugins/ad-injection-ads/

2. Create a text files in this folder for each of the categories that you want an ad for. The text files should be named [category nicename].txt The ‘nicename’ of the category is the category name with spaces and dots converted to ‘-‘ and apostrophes removed. e.g.

Liverpool = liverpool.txt
Manchester United = manchester-united.txt
A.F.C Aldermaston = a-f-c-aldermaston.txt
Bishop’s Stortford = bishops-stortford.txt

ad injection ad code box

3. Then put the code below (from the starting <?php to the closing ?>) into one of the ad box – shown above. The code will load the text file ad matching the category name when the post is displayed.

<?php
$plugin_dir = dirname(__FILE__);
$ad_dir = dirname($plugin_dir).'/ad-injection-ads/';
if (file_exists($ad_dir)){
    global $post;
    $categories = get_the_category($post->ID);
    foreach ($categories as $cat){
        // nicename: spaces and dots are converted to '-' and apostrophes are removed
        $full_ad_path = $ad_dir.$cat->category_nicename.'.txt';
        if (file_exists($full_ad_path)){
            $ad = file_get_contents($full_ad_path);
            if ($ad === false) echo "<!--ADINJ CATCODE: could not read ad from file: $full_ad_path-->n";
            echo $ad;
            break; // only show first category ad that matches
        } else {
            echo "<!--ADINJ CATCODE: could not find ad at: $full_ad_path-->n";
        }
    }
} else {
    echo "<!--ADINJ CATCODE: could not find ad directory: $ad_dir-->n";
}
?>

Some extra information:

  • This code will load one text file ad per post. If for example you had a post with the categories ‘Liverpool’ and ‘Manchester United’ it would load which ever ad it found first.
  • If will ignore categories that have no text file in the directory. If you have a post with the categories ‘Liverpool’ and ‘Latest News’ then it will always load the liverpool.txt as long as you don’t create a ‘latest-news.txt’.
  • This code will only work in ‘direct’ ad insertion mode. It won’t work in ‘mfunc’ mode.

Expansion ideas:

  • Show a default advert if no text file exists.
  • Create multiple text files for each category and then randomly select one (shown below).
  • Use different code for top, random or bottom ads. e.g. you could have liverpool_top.txt and liverpool_random.txt

Randomly picking one advert from a pool of ads

Here is a more complex example which allows each category to have a pool of text ads to choose from. It will randomly pick a file that contains the category nicename as a substring. If the category nicename is ‘liverpool’ the code will pick out any files in the directory containing ‘liverpool’, e.g. ‘liverpool.txt’, ‘liverpool1.txt’, ‘liverpool2.txt’. If you put this code into the ‘random’ advert and want a different advert to appear in each slot you should tick the ‘Re-select an ad for each position on post’ box in the ad placement settings of Ad Injection.

<?php
$adinj_filter_category_ads_filter;
if (!function_exists('adinj_filter_category_ads')){
function adinj_filter_category_ads($file) {
    global $adinj_filter_category_ads_filter;
    return strpos($file, $adinj_filter_category_ads_filter) !== false;
}}
$plugin_dir = dirname(__FILE__);
$ad_dir = dirname($plugin_dir).'/ad-injection-ads/';
if (file_exists($ad_dir)){
    $files = scandir($ad_dir);
    global $post;
    $categories = get_the_category($post->ID);
    foreach ($categories as $cat){
        // nicename: spaces and dots are converted to '-' and apostrophes removed
        global $adinj_filter_category_ads_filter;
        $adinj_filter_category_ads_filter = $cat->category_nicename;
        $filtered_files = array_filter($files, 'adinj_filter_category_ads');
        $random_file = array_rand($filtered_files);
        $full_ad_path = $ad_dir.$filtered_files[$random_file];
        if (file_exists($full_ad_path)){
            $ad = file_get_contents($full_ad_path);
            if ($ad === false){
                echo "<!--ADINJ CATCODE: could not read ad at: $full_ad_path-->n";
            }
            echo $ad;
            break; // only show first category ad that matches
        } else {
            echo "<!--ADINJ CATCODE: could not find ad at: $full_ad_path-->n";
        }
    }
} else {
    echo "<!--ADINJ CATCODE: could not find ad directory: $ad_dir-->n";
}
?>

Randomly picking many adverts from a pool of ads

This will pick a selection of adverts from an ad pool and display them all without duplicates. The use case for this could be if you want to display a selection of adverts down your sidebar. You might have a pool of 20 adverts, and this code can pick any number of those and show them in random positions, without duplicating any adverts. Name your adverts ‘widgetadpool1.txt’, ‘widgetadpool2.txt’, etc. Then modify the ‘$i < condition' in the for loop to select how many of the adverts you want to show.

<?php
if (!function_exists('adinj_adhtml_filter_ads')){
function adinj_adhtml_filter_ads($file) {
    return strpos($file, 'widgetadpool') !== false;
}}
$plugin_dir = dirname(__FILE__);
$ad_dir = dirname($plugin_dir).'/ad-injection-ads/';
if (file_exists($ad_dir)){
    $files = scandir($ad_dir);
    $filtered_files = array_filter($files, 'adinj_adhtml_filter_ads');
    for ($i=0; $i<10; ++$i){ // max num ads shown
        $random_file = array_rand($filtered_files);
        $full_ad_path = $ad_dir.$filtered_files[$random_file];
        if (file_exists($full_ad_path)){
            $ad = file_get_contents($full_ad_path);
            if ($ad === false){
                echo "<!--ADINJ RAND: could not read ad at: $full_ad_path-->n";
            }
            echo $ad.'<br />';
        } else {
            echo "<!--ADINJ RAND: could not find ad at: $full_ad_path-->n";
        }
        unset($filtered_files[$random_file]);
        if (empty($filtered_files)) break;
    }
} else {
    echo "<!--ADINJ RAND: could not find ad directory: $ad_dir-->n";
}
?>


Ad Injection 1.2.0.0 preview – WordPress ad management plugin

Tuesday, September 6th, 2011

Ad Injection (the plugin for injecting adverts into your WordPress blog) version 1.2.0.0 should be out in a week or two (mid-September 2011). Here is a preview of some of the new features – the screen shots are from the unreleased version so the UI may change slightly before release.

New ad positioning options

Ad Injection already has many options for selecting exactly how the top, random and bottom ads are positioned. But some people need more control, so 1.2.0.0 will have a load of new features.

ad injection placement settings

  1. With 1.2.0.0 it will be possible to have the top ad start at a position other than at the very top. You will be able to choose a paragraph for it to start, or a character position. If you choose a character position the ad will appear at the next paragraph after your chosen character. The character count is based on the raw number of characters in the content (which includes HTML tags).
  2. Ad Injection has had the option to select which paragraph the random ads start at for a long time. Recently I added options to start the ads ‘at or after’ a paragraph/character position as well. The new 1.2.0.0 will have options to start the ads from the middle of the post – particularly useful if you like a top, middle and a bottom advert. There are several different methods by which the middle position can be calculated.
  3. A brand new feature is to set a position to stop the random adverts. You can stop the adverts by paragraph/character count, in the middle of the post, or two thirds of the way down the post.
  4. These options were previously hidden away on the Ad Rotation tab. They all affect the ad placement settings so it made more sense to move them here.
  5. The bottom ad no longer has to be right at the bottom of the post. If you want it at the last-but-one paragraph, you’ll be able to do that.
  6. Another setting relevant to this section that was previously hidden away where you probably wouldn’t spot it.
  7. Instead of disappearing when you exclude all the home or archive ads, these sections will now fade away. This (I hope) makes it obvious that the options do exist, but that they are disabled.

Blogs with thousands of tags

I had been having intermittent reports that parts of the UI were not drawing on some blogs. I found out that this was caused on blogs that had large numbers of tags, but very little memory. The old Ad Injection would load all the tags at once (which on some blogs could be thousands).

A recent update to Ad Injection includes an update to load the tags in batches of 100, and the new 1.2.0.0 version will move the filters section futher down the screen, so if you do run out of memory you will (hopefully) still be able to use the most useful parts of the UI.

ad injection filters

Minor UI tweaks

You can see in this screenshot the tick boxes which will become transparent instead of invisible in Ad Injection 1.2.0.0. And on the right I’ve added the ‘days older than’ settings information to the summary. These are important settings so I think it makes sense to have the information easily visible.

ad injection global settings

New features :) / New bugs :(

This update will include major changes to the part of the code that does the insertion of advert into your post content. As such it may contain new bugs – but don’t worry I usually get bugs fixed pretty soon after they are reported. If you want to beta test the 1.2.0.0 version contact me via the feedback form in Ad Injection, or via this website.

If you have any comments on the soon to be released Ad Injection 1.2.0.0 please do get in touch.

You can download Ad Injection from the WordPress site, or from your blog by searching for ‘Ad Injection’.

Ad Injection plugin for WordPress

Monday, December 6th, 2010

Ad Injection is a free WordPress plugin that injects any kind of advert (e.g. Google AdSense, Amazon Associates, ClickBank, TradeDoubler, etc) into the existing content of your WordPress posts and pages. You can control the number of adverts based on the post length, and it can restrict who sees adverts by post age, visitor referrer and IP address. Adverts can be configured in the post (random, top, and bottom positions) or in any widget/sidebar area. There's support for A:B split testing / ad rotation.

ad injection plugin for wordpress 1 450

PayPal – The safer, easier way to pay online.

Download

Download Ad Injection plugin for WordPress for free from this link. Or just search for Ad Injection from your WordPress install and WordPress will automatically install it for you.

Features

Automatic advert injection

The ads can be injected into existing posts without requiring any modification of the post. The injection can be done randomly between paragraphs, and there is an option to always inject the first advert at a specified paragraph (e.g. the first or second). Randomly positioning the adverts helps to reduce 'ad blindness'. Two additional adverts can be defined for the top and bottom of the content. Widget adverts can be defined as well for your sidebars.

ad injection plugin for wordpress 3 450

Widget support

Widgets can be added to your sidebars, or other widget areas on any pages. The same ad display restrictions that you setup for your other ads will also apply to the widgets.

Ad rotation / split testing

You can define multiple adverts for the same ad space which are rotated according to the ratios you define. Works with random, top, bottom and sidget/sidebar ads.

Ad quantity by post length

The number of adverts can be set based on the length of the post. It is a good idea for longer posts to have more adverts than shorter posts for example. Adverts can also be turned off for very short posts.

ad injection plugin for wordpress 4 450

Ads on old posts only

Adverts can be restricted to posts that are more than a defined numbers of days old. This prevents your regular visitors from having to see your ads.

Category, tag and post type filters

You can configure the adverts to only appear on specific categories, tags, or post types, or block the adverts from specific categories, tags or post types.

Search engines only (dynamic feature)

You can specify that ads should only be shown to search engine visitors (or from any other referring websites) so that your regular visitors (who are unlikely to click your ads) get a better experience of your site. You can define which search engines or any other referring sites see your adverts. A visitor who enters the site by a search engine will see ads for the next hour.

Block ads from IP addresses (dynamic feature)

IP addresses of people who shouldn't see your ads can be defined. These could be the IP addresses of your friends, family, or even yourself.

ad injection plugin for wordpress 2 450

Not tied to any ad provider

The advert code can be copied and pasted directly from your ad provider (Google AdSense, adBrite, ClickBank, etc) which will help you to comply with any terms of service (TOS) that state their ad code may not be modified.

Flexible ad positioning

Easy positioning options are provided for left, right, center, float left, and float right. Extra spacing can be set above and below the ad. Or if that isn't flexible enough, you can write your own positioning code using HTML and CSS.

You can specify a specific paragraph for random ads to start from, or if you need per-post control of the random adverts you can insert tags into the post source to say where the adverts should start and end.

ad injection plugin for wordpress 5 450

Inject PHP and JavaScript

As the plugin will inject whatever content you like into the page you can write your own ad rotation or a/b split testing code for the ads you inject. PHP code can be automatically executed.


Full documentation is available on the WordPress Ad Injection page.


If you do get any errors please use the 'Report a bug or give feedback' link on the plugin to send me the error details.