Display AdSense Earnings In Conky

Introduction

Conky is a fantastic resource monitor for Linux/BSD that can be customized to not only show system statistics, but run external scripts as well. I've created a script that will display Google AdSense statistics directly into your Conky display.

Conky Example

I've also created a script for displaying your Project Wonderful Earnings in Conky as well.


Requirements
  • Conky
  • PHP with the curl extension

Usage

There are three things you need to change on the script to fit your needs. If you understand PHP it should be a breeze for you.

First, set your username and password by changing the values in the quotes.

$username = "username@example.com";
$password = "mypassword";

Next, change the output echo to fit your needs. The current configuration will display the monetary earnings for today.

echo "Today Earnings: $earnings[today]\n";

The values you can use with $earnings are $impressions, $clicks, $ctr, and $ecpm. The values you can use along with today are yesterday, last7days, thismonth, lastmonth, sincelastpayment.

echo "Last Month Impressions: $impressions[lastmonth]\n";
echo "Last 7 Day CTR: $ctr[last]\n";
echo "Yesterday ECPM: $ecpm[yesterday]\n";

You can easily combine and set the order for multiple options like below. This would display today's earnings - this month's earnings.

echo "Today: $earnings[today] - Month: $earnings[thismonth]\n";

To integrate this into Conky, add the following lines to your .conkyrc configuration.

AdSense Statistics:
${texeci 900 /location/to/adsense.php}

This will update your AdSense statistics every 15 minutes (900 seconds). You can change this value, but it might not be a good idea to poll your account too often.

Make sure the AdSense script is executable, by setting the correct permissions.


Download

AdSense PHP Script


You are a terrible programmer, Gary

If the script sucks, or you have any general improvement ideas, don't be shy. I'd be glad to hear any ideas.


Leave A Comment

Enter the number: 2167

Comment:(*required)


it's good info, but i've never been used linux so i won't use it.

05-26-2009


Kame

Hmm, I set it up and everything but it always reports earnings as $0.00

09-03-2009


Gary

For those wondering, Kame was setting his variable incorrectly. Be sure to read carefully and follow the format to display earnings properly. He got it working once I sent off an email with a quick fix.

09-03-2009


David

I think Google may have changed their login procedure and now this script won't work.

I was using a variant on this script for a few months, then today it stopped working. I'm getting this error :

Your browser's cookie functionality is turned off. Please turn it on

But I am (was) using cookie files as described in the above script.

Anyone else with trouble?

David

10-14-2009


Gary

David, you are correct. I have updated the script to accommodate their new login.

Please test this out and let me know if it works for you.

10-14-2009


David

Gary - Thanks!

Yes, your mod worked like a charm! Thanks for the quick response.

For those playing at home, it looks like there were just a couple mods :
1) The addition of the preg_match line for 'GALX'
2) Slight modification of the line for $data = curl_post(...)

10-14-2009


Felix

This is a longshot, but I am PHP-retarded, so I thought I'd post this: I found a .NET version of this script at http://www.alexandre-gomes.com/?p=206 but as you know, Google changed their login method. So that script no longer works. What, exactly, was changed on this script (in plain english, since I'm PHP-retardo) - or if anyone can direct me on how to modify that C# script, I will buy you a beer.. somehow. Thanks!

10-19-2009


Gary

change

string ga3t, newUrl;

to

string ga3t, galx, newUrl;

---------------------------------------

under

ga3t = System.Text.RegularExpressions.Regex.Match(webclient.ResponseHeaders["Set-Cookie"], "GA3T=(?.*)").Groups["ga3t"].Value;

add the line

galx = System.Text.RegularExpressions.Regex.Match(webclient.ResponseHeaders["Set-Cookie"], "GALX=(?.*)").Groups["galx"].Value;

---------------------------------------

change

response = webclient.UploadData(loginPostFormUri, "POST", Encoding.UTF8.GetBytes("continue=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&service=adsense&nui=15&fpui=3&ifr=true&rm=hide&ltmpl=login&hl=en_US&alwf=true&ltmpl=login&GA3T="
+ ga3t + "&Email=" + HttpUtility.UrlEncode(username) + "&Passwd=" + HttpUtility.UrlEncode(password) + "&null=Sign+in"));

to

response = webclient.UploadData(loginPostFormUri, "POST", Encoding.UTF8.GetBytes("continue=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&service=adsense&nui=15&fpui=3&ifr=true&rm=hide&ltmpl=login&hl=en_US&alwf=true&ltmpl=login&GA3T="
+ ga3t + "&GALX=" galx + "&Email=" + HttpUtility.UrlEncode(username) + "&Passwd=" + HttpUtility.UrlEncode(password) + "&null=Sign+in"));

---------------------------------------

that should do it, let me know if it works for you

10-19-2009


Felix

Yes, that worked -- thank you so much! I will post on that other site to here! Thanks again!

10-19-2009


Thomas

Good job Gary, you are awesome. I'm new to PHP (but not to programming) and my solution was pretty close. The GALX part was the missing piece I needed, thanks again!!!

10-28-2009


Anton

Does't work =(

./adsense.php
Today Earnings:

11-23-2009


kabir

i have been used that code for scrapping as give above. but it displays the message that \"Your browser\'s cookie functionality is turned off. Please turn it on.\".in that situation what can i do for working the above script for scrapping adsense.

01-28-2010


I am having a bit of trouble with your script on my webserver. When i run it i get, "Fatal error: Call to undefined function curl_init()". Curl is installed, i can run it as that user and it is configured into php. If i do a "sudo php adsense.php" the script executes just fine.

So i decided to see if i had to do the same on my workstation, and i didn't need to sudo. It ran just fine as my user. I'm kind of stumped here as to what the difference could be. Could it be php version's or the fact i'm using suPHP on my webserver you think?

03-10-2010



Your Ad Here