Google
AtTheBoard.com
Categories
 » Auto and Trucks
 » Business
 » Computers
 » Drinks
 » Education
 » Family
 » Finance
 » Food
 » Gadgets
 » Health
 » Hobbies
 » Home Improvement
 » Humor
 » Internet
 » Legal
 » Marketing
 » Parenting
 » Pets
 » Politics
 » Recreation
 » Relationships
 » Religion
 » Self Improvement
 » Sports
 » Travel
 » Womens Interest
 » Writing

Show your earnings in your Google Home page!


This script will allow your to see your adsense earnings in your iGoogle home page.

Change the login and password parameters, upload to your server and than
add the URL to your iGoogle home page.

This script is AS-IS without any warranty


<?php
/************ SCRIPT CONFIGURATION ***********/
/*********************************************/

$username="YourAdSenseUsername";
// your adsense username

$password="YourAdsensePassword";
// your adsense password

$daterange = 20 ;
// range of days to aggregate in RSS reader

$cookie="./.cookiefile";
// a temp file name - you mostly don't care about this
// This will create a hidden file in the current directory. If it seems to fail,
// replace with a full physical path (i.e. /home/you/temp/cookiefile)


/************ DO NOT MODIFY BELOW ************/
/*********************************************/

$daysbefore = mktime(0, 0, 0, date("m") , date("d") - $daterange, date("Y"));
list ($d_from,$m_from,$y_from) = split(':',date("j:n:Y", $daysbefore));
list ($d_to,$m_to,$y_to) = split(':',date("j:n:Y"));


/* Following lines are based on a script found on WMW forums */
/* http://www.webmasterworld.com/forum89/5349.htm */
//https://www.google.com/adsense/report/aggregate?
//product=afc
//dateRange.dateRangeType=simple
//dateRange.simpleDate=thismonth
//reportType=property
//groupByPref=date
//unitPref=page
//https://www.google.com/adsense/report/aggregate?product=afc&
// dateRange.dateRangeType=simple&dateRange.simpleDate=thismonth&
// reportType=property&groupByPref=date&outputFormat=TSV_EXCEL&unitPref=page


$destination="/adsense/report/aggregate?"
."sortColumn=0"
."&reverseSort=false"
."&outputFormat=TSV_EXCEL"
."&product=afc"
."&dateRange.dateRangeType=simple"
."&dateRange.simpleDate=thismonth"
."&unitPref=page"
."&reportType=property"
."&groupByPref=date";

$postdata="destination=".urlencode($destination)."&username=".urlencode($username)."&password=".urlencode($password)."&null=Login";

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"https://www.google.com/adsense/login.do");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt ($ch, CURLOPT_TIMEOUT, 20);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);

$result=preg_split("/\n/",$result);
array_pop($result);
array_pop($result);
array_shift($result);
$result = array_reverse($result);
header('Content-type: text/xml');

print '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
?>

<Module>
<ModulePrefs title="Adsense" />
<Content type="html">
<?php

print '<![CDATA[';

print '<style type="text/css">
<!--
TD {font-size:8px}
-->
</style>';

print ' <table> <tr><td>Day<td>Pages</td><td>Clicks</td><td>CTR</td><td>eCPM</td><td>Earnings</td></tr>';

foreach ($result as $line) {
$item = array();
$line = str_replace("\x00",'',$line);
$line = str_replace('"','',$line);
list($day, $pages, $clicks, $ctr, $eCPM, $income) = preg_split("/\s/",$line);
$item['content'] = "<tr><td>$day<td>$pages</td><td>$clicks</td><td>$ctr</td><td>$eCPM</td><td>$income</td></tr>";
print $item['content'] ."\n";
}
print '</table>]]>';

?>
</Content>
</Module>