PHP Script for Drupal to only show Firefox w/ Google Toolbar Referral Ad to Relevant Users



I've managed to make a script that makes it so Drupal only shows the "Get Firefox with Google Toolbar" referral button for users that are running non-Firefox browsers on Windows Systems.

I added a button to my website to get some referral money, but with most users already using Firefox, this is often wasted ad space.

Recall that Google only pays users that are running Windows and have never installed Firefox before on their systems, so some targetting isn't such a bad idea. Google doesn't give any funding to referrals that never used Google Toolbar before, but have once upon a time used Firefox unfortunately.

This code basically looks for keywords in the user agent string, which PHP handles the acquisition of. If a user agent doesn't say "Windows" in it, or says "Firefox" in it, the Block won't show up.

Another Block could be created with another ad using code with all of the "FALSE" values changed to "TRUE" values in order to show a different ad to these users that are already using Firefox or not using Windows. The end result should be more revenue (and eventually profit) for webmasters running Drupal (or another CMS and relevant changes to the script).

This code can be used with Drupal's "Show if the following PHP code returns TRUE (PHP-mode, experts only)." setting for Blocks.

Just paste in the following code:

<?php
//The following code ensures that the user is running windows, since Google only pays for conversions on windows users
if (strstr($_SERVER['HTTP_USER_AGENT'], "Windows"))
{
// the following checks if firefox is being used or not, and returns the appropriate boolean value
if (strstr($_SERVER['HTTP_USER_AGENT'], "Firefox"))
{
return FALSE;
}
else
{
return TRUE;
}
}
else
{
return FALSE;
}
?>

Any problems or suggestions, just leave a comment.

 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <p> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options