How to load statistics data

If you want to get statistical data that is used in the Traffic stats widget or in reports (Quick, Trends), you can use class Pap_Merchants_Reports_TrafficStatsData.
 
In case you wish to load the data for a particular affiliate, then you can log in as an affiliate via api or use 'userid' filter:
$filters[] = array("userid", Gpf_Data_Filter::EQUALS, '11111111');
 
 
Loading traffic stats data:
 
 
<?php

include 'PapApi.class.php'; //the PapApi.class.php can be found at the PAP installation folder, in the 'api' directory

$session = new Pap_Api_Session("https://your_pap_url/scripts/server.php");

if(!$session->login("merchant login","pass")) {
  die("Cannot login. Message: ". $session->getMessage());
}

$request = new Gpf_Rpc_Request('Pap_Merchants_Reports_TrafficStatsData', 'load', $session);
// set filter
$filters = array();

//datetime filter is mandatory, no value '' mean all
$filters[] = array("datetime", Gpf_Data_Filter::DATERANGE_IS, ''); 
/*instead of '' you can use:
Gpf_Data_Filter::RANGE_TODAY
Gpf_Data_Filter::RANGE_YESTERDAY
Gpf_Data_Filter::RANGE_LAST_7_DAYS
Gpf_Data_Filter::RANGE_LAST_30_DAYS
Gpf_Data_Filter::RANGE_LAST_90_DAYS
Gpf_Data_Filter::RANGE_THIS_WEEK
Gpf_Data_Filter::RANGE_LAST_WEEK
Gpf_Data_Filter::RANGE_LAST_2WEEKS
Gpf_Data_Filter::RANGE_LAST_WORKING_WEEK
Gpf_Data_Filter::RANGE_THIS_MONTH
Gpf_Data_Filter::RANGE_LAST_MONTH
Gpf_Data_Filter::RANGE_THIS_YEAR
Gpf_Data_Filter::RANGE_LAST_YEAR

e.g.: $filters[] = array("datetime", Gpf_Data_Filter::DATERANGE_IS, Gpf_Data_Filter::RANGE_THIS_MONTH);
*/

//status: A - approved, P - pending, D - declined use value "A,P,D" for all or remove rstatus filter
$filters[] = array("rstatus", "IN", 'A');  
//campaign id, remove this filter, if you want data for all campaigns 
$filters[] = array("campaignid", Gpf_Data_Filter::EQUALS, '11111111');  

$request->addParam('filters', new Gpf_Rpc_Array($filters));

try  {
    // Send the request to PAP
    $request->sendNow();
} catch(Exception $e){
    die("API call error: " . $e->getMessage());
}

// Get the response as normal array
$response = $request->getStdResponse();

foreach ($response as $responseValue) {
    switch ($responseValue[0]) {
        case 'countImpressions':
            echo 'countImpressions: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'countClicks':
            echo 'countClicks: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'countSales':
            echo 'countSales: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'sumSales':
            echo 'sumSales: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'sumCommissions':
            echo 'sumCommissions: ' . $responseValue[1];
            echo '<br>';
            break;
    }
}

?>
 
Loading additional stats data:
 
<?php

include 'PapApi.class.php'; //the PapApi.class.php can be found at the PAP installation folder, in the 'api' directory

$session = new Pap_Api_Session("https://your_pap_url/scripts/server.php");

if(!$session->login("merchant login","pass")) {
  die("Cannot login. Message: ". $session->getMessage());
}

$request = new Gpf_Rpc_Request('Pap_Merchants_Reports_TrafficStatsData', 'getClicksData', $session);
// set filter
$filters = array();
//datetime filter is mandatory, no value '' mean all
$filters[] = array("datetime", Gpf_Data_Filter::DATERANGE_IS, ''); 
/*instead of '' you can use:
Gpf_Data_Filter::RANGE_TODAY
Gpf_Data_Filter::RANGE_YESTERDAY
Gpf_Data_Filter::RANGE_LAST_7_DAYS
Gpf_Data_Filter::RANGE_LAST_30_DAYS
Gpf_Data_Filter::RANGE_LAST_90_DAYS
Gpf_Data_Filter::RANGE_THIS_WEEK
Gpf_Data_Filter::RANGE_LAST_WEEK
Gpf_Data_Filter::RANGE_LAST_2WEEKS
Gpf_Data_Filter::RANGE_LAST_WORKING_WEEK
Gpf_Data_Filter::RANGE_THIS_MONTH
Gpf_Data_Filter::RANGE_LAST_MONTH
Gpf_Data_Filter::RANGE_THIS_YEAR
Gpf_Data_Filter::RANGE_LAST_YEAR

e.g.: $filters[] = array("datetime", Gpf_Data_Filter::DATERANGE_IS, Gpf_Data_Filter::RANGE_THIS_MONTH);if you want to use filter for certain date (2012-02-07) you can use:
$filters[] = array("datetime", "D>=", "2012-02-07");
$filters[] = array("datetime", "D<=", "2012-02-07");
*/

//campaign id, remove this filter, if you want data for all campaigns 
$filters[] = array("campaignid", Gpf_Data_Filter::EQUALS, '11111111');  

$request->addParam('filters', new Gpf_Rpc_Array($filters));

try  {
    // Send the request to PAP
    $request->sendNow();
} catch(Exception $e){
    die("API call error: " . $e->getMessage());
}

// Get the response as normal array
$response = $request->getStdResponse();

foreach ($response as $responseValue) {
    switch ($responseValue[0]) {
        case 'clicks':
            echo 'clicks: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'clicksDeclined':
            echo 'clicksDeclined: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'clicksRaw':
            echo 'clicksRaw: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'clicksUnique':
            echo 'clicksUnique: ' . $responseValue[1];
            echo '<br>';
            break;
    }
}

$request = new Gpf_Rpc_Request('Pap_Merchants_Reports_TrafficStatsData', 'getImpressionsData', $session);

$request->addParam('filters', new Gpf_Rpc_Array($filters));

try  {
    // Send the request to PAP
    $request->sendNow();
} catch(Exception $e){
    die("API call error: " . $e->getMessage());
}

// Get the response as normal array
$response = $request->getStdResponse();

foreach ($response as $responseValue) {
    switch ($responseValue[0]) {
        case 'impressions':
            echo 'impressions: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'impressionsRaw':
            echo 'impressionsRaw: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'impressionsUnique':
            echo 'impressionsUnique: ' . $responseValue[1];
            echo '<br>';
            break;
    }
}

$request = new Gpf_Rpc_Request('Pap_Merchants_Reports_TrafficStatsData', 'getTransactionsData', $session);

$request->addParam('filters', new Gpf_Rpc_Array($filters));

try  {
    // Send the request to PAP
    $request->sendNow();
} catch(Exception $e){
    die("API call error: " . $e->getMessage());
}

// Get the response as normal array
$response = $request->getStdResponse();

foreach ($response as $responseValue) {
    switch ($responseValue[0]) {
        case 'transactionsCount':
            echo 'transactionsCount: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsCountApproved':
            echo 'transactionsCountApproved: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsCountDeclined':
            echo 'transactionsCountDeclined: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsCountPaid':
            echo 'transactionsCountPaid: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsCountPending':
            echo 'transactionsCountPending: ' . $responseValue[1];
            echo '<br>';
            break;

        case 'transactionsTotalCost':
            echo 'transactionsTotalCost: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsTotalCostApproved':
            echo 'transactionsTotalCostApproved: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsTotalCostDeclined':
            echo 'transactionsTotalCostDeclined: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsTotalCostPaid':
            echo 'transactionsTotalCostPaid: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionTotalCostPending':
            echo 'transactionTotalCostPending: ' . $responseValue[1];
            echo '<br>';
            break;


        case 'transactionsCommission':
            echo 'transactionsCommission: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsCommissionApproved':
            echo 'transactionsCommissionApproved: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsCommissionDeclined':
            echo 'transactionsCommissionDeclined: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsCommissionPaid':
            echo 'transactionsCommissionPaid: ' . $responseValue[1];
            echo '<br>';
            break;
        case 'transactionsCommissionPending':
            echo 'transactionsCommissionPending: ' . $responseValue[1];
            echo '<br>';
            break;
    }
}

?>
 
×