Forum Moderators: martinibuster
newbie-checking-adsense-earnings-every-15-minutes ritual
Sadly, that ritual doesn't seem to go away with time, it's like watching your stocks trade during the day, it's an obsession.
I'm planning on installing a server-side script that will access my account every 30 minutes and email the amount to my cell phone so I don't wig out from withdrawl like I did when we took a trip 3 weeks ago. When we finally got to my mom's house 5 hours away I had to run to the computer, when we got in the hotel lobby I ran to their computer.
I'd probably be better off doing heroin as I can take it with me.
I requested of the author that he add a logging function, to write all the results to a spreadsheet-friendly log file...no word on whether he will. Those spreadsheets could provide hours of entertainment to us addicts.
<?
$username="uername@email.com";
$password="pass";
$cookie="/mywebsite.com/adsense/cookiefile";
$log="/mywebsite.com/adsense/adsense.log.txt";
$destination="/adsense/reports-aggregate?product=afc&dateRange.dateRangeType=simple&dateRange.simpleDate=today";
$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);
preg_match('/\<tr class\="totals"\>.*\<td.*\>.*\<\/td\>.*\<td.*\>(.*)\<\/td\>.*\<td.*\>(.*)\<\/td\>.*\<td.*\>(.*)\<\/td\>.*\<td.*\>(.*)\<\/td\>.*\<td.*\>(.*)\<\/td\>.*<\/tr>/simU', $result, $array);
foreach ($array as $key => $value) {$array[$key] = trim($value, "\x22\x27\n\r ");} // strip $ % , here if desired
list($full,$Impressions,$Clicks,$Rate,$CPM,$Earnings) = $array;
putenv('TZ=US/Pacific'); // match Google time no matter where you or your serverlive
$output=date("Y-m-d H:i:s")." \t ".$Impressions." \t ".$Clicks." \t ".$Rate." \t".$CPM." \t ".$Earnings."\r\n";
if ($handle = fopen($log, 'a')) {fwrite($handle, $output); fclose($handle);} else {echo "error writing";}
//mail("5555555555@mobile.att.net", "Adsense report", $output, "From: Adsense");
mail("myemail@email.com", "Adsense report", $output, "From: Adsense");
?>