1 ) { if(!empty($_REQUEST['as_action'])) { $message = $amped_sense->handle_action($_REQUEST['as_action'],$as_page); } } ?>
Congratulations on installing AmpedSense! You're about to run some kick-butt split tests to help you increase your AdSense revenue. Sweet!
$messageTo use the AmpedSense Plugin, you need to sign in to your Google account.
You should use the Google account that you use for AdSense on this site.
This allows AmpedSense to show you which ads are working the best so you can easily make decisions on your split test performance. By authenticating, you agree to our terms.
"; } else { //have refresh token, let's get an access token if we need it if(!isset($_SESSION['as_googleaccesstoken']) || $_SESSION['as_googleaccesstoken']=='' || (isset($_SESSION['as_googleaccesstokenexpires']) && time() > $_SESSION['as_googleaccesstokenexpires'])) { //use proxy so we never expose our secret $installid = isset($amped_sense->settings['installid']) ? $amped_sense->settings['installid'] : 0; $returnedas = $amped_sense->getUrlContents("http://www.ampedsense.com/api/wporg-googlehandler.php?installid=$installid&rt=".urlencode($amped_sense->settings['googlerefreshtoken'])); if(stristr($returnedas,"Error")!="" || stristr($returnedas,"|||")=="") //shouldn't have error, need delimiter { echo "Error: $returnedas"; } else { list($accesstoken,$expirein) = explode("|||",$returnedas); $_SESSION['as_googleaccesstoken'] = $accesstoken; $_SESSION['as_googleaccesstokenexpires'] = time() + $expirein; } } //grab all data from google for each segment date $google_success = false; $apiresults = array(); //indexed by fromdate if(isset($_SESSION['as_googleaccesstoken']) && $_SESSION['as_googleaccesstoken']!="") { foreach($amped_sense->settings['segments'] as $i=>$segment) { //only if not hidden if(!(isset($segment['hide']) && $segment['hide']==1)) { $fromdate = $amped_sense->get_ir_fromdate($i); if(!isset($apiresults[$fromdate])) { $start = date("Y-m-d",strtotime($fromdate)); $end = date("Y-m-d"); $dimension = "CUSTOM_CHANNEL_NAME"; //don't use MATCHED_AD_REQUESTS, because link units count the next page only, and we should factor in unmatched ad requests too //don't use AD_REQUESTS, use PAGE_VIEWS - that's what the adsense portal reports, and it makes most sense $metricclause = "metric=PAGE_VIEWS&metric=CLICKS&metric=PAGE_VIEWS_CTR&metric=PAGE_VIEWS_RPM&metric=EARNINGS"; $returnedjson = $amped_sense->getUrlContents("https://www.googleapis.com/adsense/v1.4/accounts/".urlencode($amped_sense->settings['adsensepublisherid'])."/reports/?access_token=".urlencode($_SESSION['as_googleaccesstoken'])."&userIp=".$amped_sense->ip."&startDate=$start&endDate=$end&useTimezoneReporting=true&dimension=$dimension&$metricclause"); //echo $returnedjson; $apiresult = json_decode($returnedjson,true); if(count($apiresult) && empty($apiresult["error"])) { $google_success = true; $apiresults[$fromdate] = $apiresult; } else { $google_success = false; echo "Error: $returnedjson"; break; } usleep(100000); //.1 second delay for quota mgmt } } } } //foreach segment, list out recipes and how they're doing foreach($amped_sense->settings['segments'] as $i=>$segment) { //only if not hidden if(!(isset($segment['hide']) && $segment['hide']==1)) { $fromdate = $amped_sense->get_ir_fromdate($i); $statsheaderrow = "| Recipe | Date Started | Status | # Ads | Stats $irdate | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
";
echo " ";
echo " ";
echo " ";
if($recipe['active']) echo " ";
else echo " ";
echo " | ";
//name
echo "$recipe[recipename] | "; //date echo "".date("m/d/Y",$recipe['whenstarted'])." | "; //status echo ""; if($recipe['active']) echo "Active"; else echo "Paused"; echo " | "; //ad count echo "".count($recipe['ads'])." | "; //show stats, or link to stats if($google_success) { if(isset($recipe['channelid']) && $recipe['channelid']>0) { //find corresponding report row $reportrow = null; if(isset($apiresults[$fromdate]['rows']) && count($apiresults[$fromdate]['rows'])) { foreach($apiresults[$fromdate]['rows'] as $row) { if($row[0]==$recipe['channelname']) { $reportrow = $row; break; } } } if($reportrow==null) { echo "No data yet (may be delayed up to 1 hour) | "; } else { echo "$reportrow[1] | "; //views echo "$reportrow[2] | "; //clicks echo "".$amped_sense->toPercent($reportrow[3])."% | "; //ctr echo "\$$reportrow[4] | "; //rpm echo "\$$reportrow[5] | "; //earnings } } else { echo "Couldn't find channel - please add New Custom Channel named \"$recipe[channelname]\". Click when done | ";
}
}
else
{
echo "Google Error. View stats manually or reauthenticate | "; } } } else { echo "||||||||||||
| No ad recipes yet. | ||||||||||||||||||||||||
| Create new recipe | ||||||||||||||||||||||||
Need help? Creating your first split test
'; } //modal for segment selection on clones // this is taken outside of 'ampedsense' div, so must re-add class for bootstrap to take effect ?>