Ad Logger '.adlog_get_version().' Beta Version

'; adlog_top_message_box(); $ops = adlog_options(); global $adlog_ui_notice_version; if ($ops['ui_notice_acknowledgement'] < $adlog_ui_notice_version){ return; } global $wpdb; $adlog_table = adlog_table_name(); if (!adlog_table_exists()){ adlog_message('Logging table does not exist...'); adlog_create_logging_database(); } adlog_check_settings_versions(); $count = $wpdb->get_var("SELECT COUNT(*) FROM $adlog_table"); $rows_per_page = $ops['ui_num_rows_per_page']; if ($count > 1){ $num_pages = ceil($count / $rows_per_page); } else { $num_pages = 1; } $nonce = wp_create_nonce("Ad-Logger"); ?>
'; ?> Loading data...
'; adlog_side_donate_box(); adlog_side_info_box(); echo ''; ?>

Iframes to log

'; adlog_add_log_checkbox("Google AdSense ", 'log_adsense', 'google.png'); adlog_add_log_checkbox("Amazon Associates ", 'log_amazon', 'amazon.png'); adlog_add_log_checkbox("Facebook Likes ", 'log_facebook', 'facebook.png'); adlog_add_log_checkbox("Twitter Tweets ", 'log_twitter', 'twitter.png'); adlog_add_log_checkbox("Google +1 ", 'log_plusone', 'plusone.png'); echo ''; add_thickbox(); ?>

AdSense click blocking

If AdSense click(s) detected within '1 hour',2=>'2 hours',3=>'3 hours',6=>'6 hours',12=>'12 hours',24=>'1 day',48=>'2 days',72=>'3 days',168=>'1 week',336=>'2 weeks',720=>'30 days',2208=>'3 months')); ?> :
   1) set Ad Injection '; } else if (adlog_plugin_exists('/ad-injection')){ echo ' Ad Injection (installed but not active) '; } else { ?> ad blocking cookie with duration of '0 hours (disabled)','1'=>'1 hour', '2'=>'2 hours', '3'=>'3 hours', '6'=>'6 hours', '24'=>'1 day', '48'=>'2 days', '72'=>'3 days', '168'=>'1 week', '720'=>'30 days', '8760'=>'1 year')); ?>
   2) hide class divs - delay by '1 second', '2'=>'2 seconds', '3'=>'3 seconds', '5'=>'5 seconds' )); ?>
   (These divs will also be hidden if the 'adlogblocked=1' cookie is found).

Warning: Do not attempt to test the ad blocking feature by clicking on your own ads - you could get yourself banned.
Info: 1) If a caching plugin is being used with Ad Injection, the Ad Injection insertion mode must be set to 'mfunc'. 2) These features work using JavaScript and cookies, so if the user doesn't have these enabled, or clears their cookies, ad blocking will not occur.

Data to show/store

All Size Unit Referrer IP Browser Src
Data to show
Data to store

Note that data will only be shown if you have configured Ad Logger to store it!


Testing the plugin

You may well want to see how the plugin works without having to wait for other genuine user data to be logged. These Facebbok Like, Twitter Tweet and Google +1 buttons can be used to test the plugin.
Note that you must *never* test Google AdSense adverts as that is against their TOS - you will have to wait for genuine clicks to occur.

When testing the Facebook/Twitter/Google +1 buttons you don't have to submit the statuses to your account (or even have signed up), it is enough to click the link, wait for the popup window to open, and then close the pop up window. If you are already signed into one of these services then the status message may be automatically added to your account.

Tweet

Alternatively if you click on this 'Add test data' button a set of fake records will be will be added to the database. You can then delete them by clicking on 'Delete test data'.

Database actions


Debugging

'; } function adlog_add_test_data(){ $homeurl = home_url(); $query = "INSERT INTO `TABLENAME` (Date, Type, Size, Unit, Page, Referrer, IP, Browser, Debug) VALUES ('2011-08-02 12:13:12', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer1', '".ip2long("123.123.123.123")."', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1', '*TD*'), ('2011-08-02 12:13:14', 2, '', 3, '$homeurl', 'http://www.example.com/referrer2', '".ip2long("123.123.123.124")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-02 12:14:15', 3, '', 3, 'http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/', 'http://www.advancedhtml.co.uk/', '".ip2long("123.123.123.125")."', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1', '*TD*'), ('2011-08-02 12:14:16', 4, '', 3, '$homeurl', 'http://www.example.com/referrer4', '".ip2long("123.123.123.126")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-02 12:14:17', 5, '', 3, 'http://www.advancedhtml.co.uk/', 'http://wordpress.org/extend/plugins/ad-logger/', '".ip2long("123.123.123.127")."', 'Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', '*TD*'), ('2011-08-03 12:14:18', 1, '728x90', 3, '$homeurl', 'http://www.example.com/referrer6', '".ip2long("123.123.123.128")."', 'Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', '*TD*'), ('2011-08-03 12:14:19', 1, '728x90', 3, '$homeurl', 'http://www.example.com/referrer7', '".ip2long("0.0.0.0")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-03 12:15:14', 1, '728x90', 3, '$homeurl', 'http://www.example.com/referrer8', '".ip2long("123.123.123.123")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-03 12:16:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer9', '".ip2long("123.123.123.123")."', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', '*TD*'), ('2011-08-04 12:17:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer1', '".ip2long("123.123.123.123")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-04 12:18:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer2', '".ip2long("123.123.123.124")."', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', '*TD*'), ('2011-08-04 12:19:14', 2, '', 3, 'http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/', 'http://www.example.com/referrer3', '".ip2long("123.123.123.124")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-04 12:24:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer4', '".ip2long("123.123.123.125")."', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', '*TD*'), ('2011-08-05 12:34:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer4', '".ip2long("123.123.123.125")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-06 12:44:14', 3, '', 3, 'http://www.reviewmylife.co.uk/', 'http://wordpress.org/extend/plugins/ad-injection/', '".ip2long("123.123.123.126")."', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1', '*TD*'), ('2011-08-07 12:54:14', 3, '', 3, 'http://www.reviewmylife.co.uk/', 'http://wordpress.org/extend/plugins/ad-injection/', '".ip2long("123.123.123.126")."', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/534.50.2 (KHTML, like Gecko) Version/5.0.6 Safari/533.22.3', '*TD*'), ('2011-08-08 13:14:14', 3, '', 3, 'http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/', 'http://www.example.com/referrer6', '".ip2long("123.123.123.126")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-09 14:14:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer1', '".ip2long("123.123.123.126")."', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', '*TD*'), ('2011-08-09 15:14:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer1', '".ip2long("123.123.123.124")."', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/534.50.2 (KHTML, like Gecko) Version/5.0.6 Safari/533.22.3', '*TD*'), ('2011-08-09 16:14:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer1', '".ip2long("123.123.123.124")."', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)', '*TD*'), ('2011-08-09 17:14:14', 4, '', 3, 'http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/', 'http://wordpress.org/extend/plugins/ad-injection/', '".ip2long("123.123.123.124")."', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)', '*TD*'), ('2011-08-09 18:14:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer1', '".ip2long("124.123.123.124")."', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1', '*TD*'), ('2011-08-10 19:14:14', 2, '', 3, 'http://www.advancedhtml.co.uk/', 'http://www.example.com/referrer1', '".ip2long("125.123.123.124")."', 'Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', '*TD*'), ('2011-08-10 20:14:14', 5, '', 3, 'http://www.advancedhtml.co.uk/ad-injection-1-2-0-0-preview-wordpress-ad-management-plugin/', 'http://wordpress.org/extend/plugins/ad-injection/', '".ip2long("126.123.123.124")."', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)', '*TD*'), ('2011-08-10 21:14:14', 1, '468x60', 3, '$homeurl', 'http://www.example.com/referrer1', '".ip2long("127.123.123.124")."', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1', '*TD*') ;"; adlog_sql($query); } function adlog_delete_test_data(){ $query = "DELETE FROM `TABLENAME` WHERE Debug = '*TD*'"; adlog_sql($query); } function adlog_plugin_exists($plugin_dir) { $plugins = get_plugins($plugin_dir); if ($plugins) return true; return false; } function adlog_add_log_checkbox($text, $option, $image){ echo ''.$text.''; adlog_add_checkbox($text, $option); } function adlog_top_message_box(){ $ops = adlog_options(); if (isset($_POST['adlog_action']) && $_POST['adlog_action']=='Save') { echo '

'; echo 'All settings saved.'; echo '


'; } global $adlog_ui_notice_version; if ($ops['ui_notice_acknowledgement'] < $adlog_ui_notice_version){ global $adlog_notice; ?>

Thanks for installing Ad Logger, please take a moment to read this important information.

1. Ad Logger uses JavaScript events to 'guess' when ads have been clicked. This method does not modify your original ad code.

2. This method of logging is not 100% accurate. It is probably about 80-90% accurate.

3. Ad Logger logs raw clicks. The numbers will not match your ad provider's statistics as they only show you valid clicks.

4. You use this plugin (as with all GPL plugins) at your own risk. It is your responsibility to judge whether you are allowed to use it with your ad provider(s).

5. Don't test the plugin by clicking on your own ads! You may get yourself banned by your ad provider.


'; echo "4th October 2011: New feature to hide divs if the AdSense click count is reached. UI tweaks - show loading circle whilst waiting for data. You can now click on the '⇓' or 'Type' icon to filter the results further. Please contact me ASAP if you spot any bugs, or odd behaviour via the ".'quick feedback form.'; echo '


'; } } function adlog_feedback_url(){ $wp_version = get_bloginfo('version'); $ad_version = adlog_get_version(); $data = urlencode($wp_version." / ".$ad_version); return "https://docs.google.com/spreadsheet/viewform?formkey=dEJscnl4T2RJV3NHaEJwcWdsWlo3WEE6MA&entry_3=$data"; } function adlog_get_version(){ $plugin_data=get_plugin_data(ADLOG_PATH . '/ad-logger.php'); return $plugin_data['Version']; } function adlog_side_donate_box(){ ?>

Donate $10, $20 or $50!

I have spent many hundreds of hours creating this plugin. If it helps you please consider making a donation. Thank you!

Amount:

Info

More Ad Logger information

Beta version

This plugin was first publicly released on 28th September 2011. It is very new, so it will have bugs and problems. Please let me know what you think, and report any problems to me.

More by this author

"; foreach ($values as $key=>$value){ $option_value = $value; $display_value = $value; if ($associative){ $option_value = $key; } echo ""; } echo ""; } function adlog_is_associative($array){ $keys = array_keys($array); $count = count($keys); for ($i=0; $i<$count; ++$i){ if ($i != $keys[$i]) return true; } return false; } function adlog_add_checkbox($label, $name){ echo ''; echo '"; echo $label; } function adlog_checkNoticeNonce(){ if (empty($_POST) || !check_admin_referer('_adlognoticeform', '_ad-logger-notice-nonce')){ echo 'form error'; exit(); } } function adlog_checkNonce(){ if (empty($_POST) || !check_admin_referer('_adlogform', '_ad-logger-nonce')){ echo 'form error'; exit(); } } function adlog_process_action(){ $action = $_POST['adlog_action']; if (isset($action)){ $ops = adlog_options(); global $adlog_notice; switch($action){ case 'Save': adlog_checkNonce(); adlog_save($ops); break; case $adlog_notice: adlog_checkNoticeNonce(); $ops['ui_notice_acknowledgement'] = $ops['settings_version']; adlog_save($ops); break; case 'Delete log Data': adlog_checkNonce(); adlog_delete_all(); break; case 'Create log DB': adlog_checkNonce(); adlog_create_logging_database(); break; case 'Delete log DB': adlog_checkNonce(); adlog_delete_table(); break; case 'Reset settings to default': adlog_checkNonce(); adlog_update_options(adlog_default_options()); break; case 'Delete settings': adlog_checkNonce(); delete_option('adlog_options'); adlog_options(1); break; case 'Add test data': adlog_checkNonce(); adlog_add_test_data(); break; case 'Delete test data': adlog_checkNonce(); adlog_delete_test_data(); break; case 'Reset Notice': adlog_checkNonce(); $ops['ui_notice_acknowledgement'] = 0; adlog_save($ops); break; default: adlog_checkNonce(); adlog_error("Error: '$action' command is not understood."); } } } function adlog_save($ops){ // Extract all know options $default_options = adlog_default_options(); foreach ($default_options as $key => $value){ if (isset($_POST[$key])){ $ops[$key] = $_POST[$key]; } } adlog_update_options($ops); } function adlog_update_options($ops){ update_option('adlog_options', $ops); // Refresh options from database as cached values are now invalidated global $adlog_data; $adlog_data = get_option('adlog_options'); } function adlog_sql($query){ global $wpdb; $query = str_replace("TABLENAME", adlog_table_name(), $query); if($wpdb->query($query) === false){ echo "Error with: $query
Msg: ".$wpdb->last_error."
"; return false; } return true; } function adlog_error($msg){ echo "$msg
"; } function adlog_message($msg){ echo "$msg
"; } function adlog_delete_table() { adlog_message('Deleting table...'); adlog_sql("DROP TABLE IF EXISTS TABLENAME"); } function adlog_delete_all() { adlog_message('Deleting all data...'); adlog_sql("TRUNCATE TABLE TABLENAME"); } // All these stored in a single DB option row function adlog_default_options(){ return array( 'click_detection_mode' => 1, 'log_all' => 'off', 'log_adsense' => 'on', 'log_amazon' => 'on', 'log_facebook' => 'on', 'log_twitter' => 'on', 'log_plusone' => 'on', // 'block_ads_if_num_adsense_clicks' => 3, 'block_ads_if_num_clicks_occur_within_hours' => 168, 'block_ads_cookie_hours' => 0, 'divs_to_hide' => 'adlog-advert', 'divs_to_hide_delay' => 1, // 'store_all' => 'off', 'store_size' => 'on', 'store_unit' => 'on', 'store_referrer' => 'off', 'store_ip' => 'on', 'store_browser' => 'on', 'store_src' => 'off', // 'ui_num_rows_per_page' => 20, 'ui_show_size' => 'on', 'ui_show_unit' => 'off', 'ui_show_referrer' => 'off', 'ui_show_ip' => 'on', 'ui_show_browser' => 'on', 'ui_show_src' => 'off', 'ui_notice_acknowledgement' => 0, // 'debug_mode' => 'off', 'log_db_version' => ADLOG_LOG_DB_VERSION, 'settings_version' => ADLOG_SETTINGS_VERSION ); } // Hopefully run on install and upgrade function adlog_activate_hook(){ $ops = adlog_options(); if(empty($ops)){ // 1st Install. adlog_install_options(); } else { // Upgrade check. adlog_upgrade_if_necessary(); } } function adlog_install_options(){ $new_options = adlog_default_options(); adlog_update_options($new_options); } function adlog_upgrade_db(){ $stored_options = adlog_options(); $new_options = adlog_default_options(); $stored_settings_version = adlog_settings_version($stored_options); $new_settings_version = adlog_settings_version($new_options); $stored_log_db_version = adlog_log_db_version($stored_options); $new_log_db_version = adlog_log_db_version($new_options); // 1. Copy existing options to new array. Use default as a baseline, // and then overwrite default with the saved ones. foreach ($new_options as $key => $value){ if (array_key_exists($key, $stored_options)){ $new_options[$key] = $stored_options[$key]; } } // 2. Upgrade settings if necessary. // 3. Upgrade database if necessary. $db_upgraded = true; $upgrade_log_db_version = 2; if ($stored_log_db_version < $upgrade_log_db_version){ // TODO what if these fail? $db_upgraded = adlog_sql(" ALTER TABLE `TABLENAME` ADD COLUMN ( Referrer VARCHAR(128), IFrameSource VARCHAR(128), Debug VARCHAR(64) ), MODIFY IPAddress INT UNSIGNED ;"); if ($db_upgraded){ $new_options['log_db_version'] = $upgrade_log_db_version; } } $upgrade_log_db_version = 3; if ($db_upgraded && $stored_log_db_version < $upgrade_log_db_version){ $db_upgraded = adlog_sql(" ALTER TABLE `TABLENAME` ADD COLUMN Type TINYINT ;"); if ($db_upgraded){ $new_options['log_db_version'] = $upgrade_log_db_version; } } $upgrade_log_db_version = 5; if ($db_upgraded && $stored_log_db_version < $upgrade_log_db_version){ $db_upgraded = adlog_sql(" ALTER TABLE `TABLENAME` CHANGE IPAddress IP INT UNSIGNED, CHANGE IFrameSource Src VARCHAR(256) ;"); if ($db_upgraded){ $new_options['log_db_version'] = $upgrade_log_db_version; } } $upgrade_log_db_version = 6; if ($db_upgraded && $stored_log_db_version < $upgrade_log_db_version){ $db_upgraded = adlog_sql(" ALTER TABLE `TABLENAME` MODIFY Referrer VARCHAR(256);"); if ($db_upgraded){ $new_options['log_db_version'] = $upgrade_log_db_version; } } // 4. Bump up settings version number. $new_options['settings_version'] = $new_settings_version; // 5. Save upgraded options. adlog_update_options($new_options); } function adlog_create_logging_database() { $table = adlog_table_name(); if (adlog_table_exists()){ adlog_message('Logging database already exists. If you want to re-create it you need to delete it first: '.$table); return; } adlog_message('Creating logging database: '.$table); $structure = "CREATE TABLE `TABLENAME` ( ID INT PRIMARY KEY AUTO_INCREMENT, Date DATETIME, Type TINYINT, Size VARCHAR(11), Unit TINYINT, Page VARCHAR(128), Referrer VARCHAR(256), IP INT UNSIGNED, Browser VARCHAR(256), Src VARCHAR(128), Debug VARCHAR(64) );"; adlog_sql($structure); if (!adlog_table_exists()){ adlog_message("Error: $table has not been created by Ad Logger. Try clicking 'Create log DB'."); } else { adlog_message("Table has been creating. Ad Logger is ready to start logging :)
"); } } add_action('admin_menu', 'adlog_admin_menu_hook'); add_filter('plugin_action_links', 'adlog_settings_link_hook', 10, 2); // TODO what are these numbers ?>