Showing posts with label experiment. Show all posts
Showing posts with label experiment. Show all posts

Thursday, January 6, 2011

Blocking Low Paying Adsense Categories

I was looking through the new Adsense interface today (the version with /v3/ in the URL) and found out that the control over blocked ads is a lot better than I remember. Under the "Allow and Block Ads" tab there are two awesome options in "Blocking OptionS" section of the sidebar, "General Categories" and "Sensitive Categories".

Sensitive Categories has things like dating, politics, religion, etc. Whereas General Categories has everything else.

Both of these sections show a list of possible Adsense categories along with what percentage of the ads you've displayed came from each category, and how much of your Adsense revenue came from each category. Most of the categories also break down into multiple sub-categories.

As soon as I found it I immediately realized I had a couple of categories with bad impression/revenue relationships. For instance I had one category that was accounting for 13% of impressions, however it only accounted for 3.8% of revenue. In comparison there are other categories that account for 6.9% of revenue on 3.3% of impressions and 4.5% on revenue on 2.5% of impressions.

So, I went ahead and blocked the categories with horrible impression to revenue relationships. I figure that having more ads from more profitable categories being displayed will translate into more money. Since Adsense has much improved reporting in V3 it will be easy to see just how well my changes do in the future.

There is a 50 category limit on the number of Adsense categories that can be blocked.

Tuesday, September 1, 2009

PHP GD Heatmap Generation

I recently set out to write my own tools to generate a heatmap from clicks on my websites. So far the collection of click positions has been a little tricky because of things like the visitors screen being a different size than mine, javascript being enabled but Adsense being blocked which shifts the position of some elements, and a whole host of other annoyances that don't come to mind at the moment.

One thing that did come sort of easy was figuring out how to generate a heatmap image using the PHP GD image functions and x/y pairs from clicks. At first I was wondering how to get the three color areas without having later clicks overlap other clicks and throw off the flow of the colors.

Rather than working with a click at a time, I needed to generate the heatmap image one color and one click at a time. I would need to loop through the image three times, each time drawing progressively smaller circles using different colors.

I put together a simple function to draw a heatmap onto an image using a list of x/y points and an image created using GD.

<?php

function draw_heatmap($image, &$clicks)
{
if(function_exists('imageantialias'))
{// Only available with compiled in version of GD
imageantialias($image, true);
}

// Heatmap colors
$cold = imagecolorallocate($image, 0, 0, 255);
$warm = imagecolorallocate($image, 0, 255, 0);
$hot = imagecolorallocate($image, 255, 0, 0);

// Loop through the clicks and draw the largest/coldest circles first
foreach($clicks as $click)
{
imagefilledellipse($image, $click['x'], $click['y'], 30, 30, $cold);
}

// Next draw middle/warm circles over the cold ones
foreach($clicks as $click)
{
imagefilledellipse($image, $click['x'], $click['y'], 20, 20, $warm);
}

// Finally draw the smallest/hot circles over everything
foreach($clicks as $click)
{
imagefilledellipse($image, $click['x'], $click['y'], 10, 10, $hot);
}

return true;
}

$width = 200;
$height = 200;
$image = imagecreatetruecolor($width, $height);
$clicks = array(
array('x' => 123, 'y' => 123),
array('x' => 45, 'y' => 113)
);
draw_heatmap($image, $clicks);
header('Content-Type: image/png');
imagepng($image);

?>

Thursday, June 26, 2008

preg_replace_callback VS preg_replace

Some interesting results of a test between the preg_replace_callback function VS the preg_replace function using the e pattern modifier.

Here's the test code.
<?php
function uppers($match)
{
return strtoupper($match[0]);
}
$out = '12345678901234567890123456789012';
$strs = array();
$str_count = 1000;
while($str_count)
{
$strs[] = md5($str_count . microtime());
$str_count--;
}

foreach($strs as &$str)
{
$out = preg_replace('#[ace]+#e', 'strtoupper($0)', $str);
}

foreach($strs as &$str)
{
$out = preg_replace_callback('#[ace]+#', 'uppers', $str);
}

?>


The test was benchmarked using the profiler included in the Xdebug Debugger and Profiler Tool for PHP.
OS is Ubuntu 8.04, Apache version 2.2.8, PHP version 5.2.4
Profiler output is being viewed in KCachegrind.

Here's the callee map generated from the output.



And here's the slightly easier to understand source map.



The two numbers on the left are the percentage of the total runtime dedicated to the actions next to them.
It appears to me that the preg_replace_callback way is faster, but I would love to see how it performs on other OS's if anyone cares to do their own tests & comment.