Display AdSense Earnings In Conky
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.
I've also created a script for displaying your Project Wonderful Earnings in Conky as well.
- Conky
- PHP with the curl extension
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.
If the script sucks, or you have any general improvement ideas, don't be shy. I'd be glad to hear any ideas.
it's good info, but i've never been used linux so i won't use it.
05-26-2009
Hmm, I set it up and everything but it always reports earnings as $0.00
09-03-2009
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
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
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
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
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
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<mpl=login&hl=en_US&alwf=true<mpl=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<mpl=login&hl=en_US&alwf=true<mpl=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
Yes, that worked -- thank you so much! I will post on that other site to here! Thanks again!
10-19-2009
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
Garys Hood Bot
Subscribe