API Example Admin Daily Performance Report
From InClickAdServer
Administrator Report - Daily Performance
This API Service Reqeust will generate the Daily Performance Report data based on the provided filter options. =The Code Example
<?php require_once "../globals/globals.php"; require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_NetworkPerformanceReportManagerClient.php"); require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_NetworkDailyPerformanceReportRequest.php"); require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_NetworkDailyPerformanceReportResult.php"); require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_NetworkDailyPerformanceReportRow.php"); //THE BASE URL OF YOUR AD SERVER DEPLOYMENT $base_url = INCLICK_WEB_URL; //THE SERVICE KEY TO ACCESS THE API $service_key = "YOUR_API_SERVICE_KEY"; //INSTANTIATE THE API CLIENT $network_report_manager = new IMG_NetworkPerformanceReportManagerClient($base_url,$service_key); $report_request = new IMG_NetworkDailyPerformanceReportRequest(); //SET THE REQUEST FOR THE LAST 14 DAYS OF STATISTICS $report_request->setDateRange($time_in_past, $time_now); $report_request->setResultsPerPage(7); $report_request->setCurrentPage(1); $report_request->setAdvertiserID(1001); $report_request->setChannelIDFilter(2); $report_request->setPublisherID(1002); //SEND THE REQUEST TO THE API $report_result = $network_report_manager->getDailyReport($report_request); if ($report_result->Succeeded()) { } else { } ?>
Breaking Down the Code
require "../globals/globals.php";
This require references the local inClick Ad Server deployment configuration files allowing your code to utilize the pre-packaged API Objects as well as the bundled PHPOlait services.
require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_NetworkPerformanceReportManagerClient.php"); require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_NetworkDailyPerformanceReportRequest.php"); require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_NetworkDailyPerformanceReportResult.php"); require_once (INCLICK_CORE_DIR . "/external/classes/reporting/IMG_NetworkDailyPerformanceReportRow.php");
These requires (includes) contain the API Objects and Classes needed for this API Service Request.
$base_url = INCLICK_WEB_URL; $service_key = "YOUR_API_SERVICE_KEY";
The $base_url is the URL to your inClick Ad Server deployment, the ad server root URL. For local host API usage, the constant of INCLICK_WEB_URL is defined in the globals.php file referenced earlier. Remote deployments, deployments where the ad server and API Request Location are not on the same server, would change this to the fully qualified URL to the ad server root directory.
The $service_key is one of the the api_service_keys values you created for your ad server. (more information)
$network_report_manager = new IMG_NetworkPerformanceReportManagerClient($base_url,$service_key); $report_request = new IMG_NetworkDailyPerformanceReportRequest();
This is where we create an instance of the classes needed to perform this service request.
$time_in_past = mktime(0, 0, 0, date("m"), date("d") - 13, date("Y")); $time_now = time(); $report_request->setDateRange($time_in_past, $time_now);
These three lines are used to set the date range. Line one is to set the date in the past. In this case, it is set for 13 days ago. Line two is the current server time. The third line sets the date range object with two parameters, the starting date and the ending date. in this example, we are looking at the last 14 days of data (including today).
- WARNING: Values for $report_request->setDateRange are integer timestamps. Do not enter date formatted values! For example, the timestamp value for May 24, 2023 is 1684900800.
$report_request->setResultsPerPage(7); $report_request->setCurrentPage(1); $report_request->setAdvertiserID(1001); $report_request->setChannelIDFilter(2); $report_request->setPublisherID(1002);
These five lines are used to set the various optional filter options:
| Object | Required | Description |
|---|---|---|
| setResultsPerPage | No | This numeric value will determine how man results will be returned in this request. Typically, this is the number of results to show in a page. |
| setCurrentPage | No | This numeric value will tell the server what page to retrieve. |
| setAdvertiserID | No | This numeric value, the advertisers account number, will filter the report to this advertisers activity |
| setChannelIDFilter | No | This numeric value, the channel ID, will filter the report to this channels activity |
| setPublisherID | No | This numeric value, the publishers account number, will filter the report to this publishers activity. |
$report_result = $network_report_manager->getDailyReport($report_request);
This line is the API Service Request that sends the request for this report to your inClick Ad Server deployment. If a failure occurs, the error code and corresponding error message are returned as objects:
- $report_result->getErrorCode()
- $report_result->getErrorMessage()
If this request is successful, the report data assigned is available in the following object:
- $report_result->getReturnValue()
if ($report_result->Succeeded()) { print_r($report_result->getReturnValue()); } else { echo ("Failed while requesting a report"); print_r($report_result); }
This section of code is provided to give you a visual confirmation of what occurred, or to let you know what error occurred.
