$lineItem->roadblockingType = 'ONE_OR_MORE'; // Set the creative rotation type. $lineItem->creativeRotationType = 'OPTIMIZED'; // Create the creative placeholder size. $size = new Size(); $size->width = 300; $size->height = 250; $size->isAspectRatio = false; // Create the creative placeholder. $creativePlaceholder = new CreativePlaceholder(); $creativePlaceholder->size = $size; // Set the size of creatives that can be associated with this line item. $lineItem->creativePlaceholders = array($creativePlaceholder); // Set the length of the line item to run. $lineItem->startDateTimeType = 'IMMEDIATELY'; $lineItem->endDateTime = DateTimeUtils::ToDfpDateTime(new DateTime('+30 days', new DateTimeZone('America/New_York'))); // Set the cost type. $lineItem->costType = 'CPM'; // Set the line item to use 50% of the impressions. $goal = new Goal(); $goal->goalType = 'DAILY'; $goal->unitType = 'IMPRESSIONS'; $goal->units = 50; $lineItem->primaryGoal = $goal; // Get forecast for prospective line item. $prospectiveLineItem = new ProspectiveLineItem(); $prospectiveLineItem->lineItem = $lineItem; $options = new AvailabilityForecastOptions(); $options->includeContendingLineItems = true; $options->includeTargetingCriteriaBreakdown = true; $forecast = $forecastService->getAvailabilityForecast($prospectiveLineItem, $options);
set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once 'Google/Api/Ads/Dfp/Util/v201605/DateTimeUtils.php'; require_once 'Google/Api/Ads/Dfp/Util/v201605/StatementBuilder.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the LineItemService. $lineItemService = $user->GetService('LineItemService', 'v201605'); // Create a statement to select only recently updated line items. $statementBuilder = new StatementBuilder(); $statementBuilder->Where('lastModifiedDateTime >= :lastModifiedDateTime')->OrderBy('id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT)->WithBindVariableValue('lastModifiedDateTime', DateTimeUtils::ToDfpDateTime(new DateTime('-1 day', new DateTimeZone('America/New_York')))); // Default for total result set size. $totalResultSetSize = 0; do { // Get line items by statement. $page = $lineItemService->getLineItemsByStatement($statementBuilder->ToStatement()); // Display results. if (isset($page->results)) { $totalResultSetSize = $page->totalResultSetSize; $i = $page->startIndex; foreach ($page->results as $lineItem) { printf("%d) Line item with ID %d, belonging to order %d, and name '%s' " . "was found.\n", $i++, $lineItem->id, $lineItem->orderId, $lineItem->name); } } $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT); } while ($statementBuilder->GetOffset() < $totalResultSetSize);
/** * @covers DateTimeUtils::ToStringForTimeZone */ public function testToStringForTimeZone() { $this->assertEquals($this->stringDateTime1, DateTimeUtils::ToStringForTimeZone($this->dfpDateTime1, self::TIME_ZONE_ID1)); $this->assertEquals($this->stringDateTime2, DateTimeUtils::ToStringForTimeZone($this->dfpDateTime2, self::TIME_ZONE_ID2)); $this->assertEquals($this->stringDateTime3, DateTimeUtils::ToStringForTimeZone($this->dfpDateTime3, self::TIME_ZONE_ID3)); $this->assertEquals($this->stringDateTime1, DateTimeUtils::ToStringForTimeZone(DateTimeUtils::ToDfpDateTime($this->dateTime1->setTimeZone(new DateTimeZone(self::TIME_ZONE_ID2))), self::TIME_ZONE_ID1)); $this->assertEquals($this->stringDateTime2, DateTimeUtils::ToStringForTimeZone(DateTimeUtils::ToDfpDateTime($this->dateTime2->setTimeZone(new DateTimeZone(self::TIME_ZONE_ID1))), self::TIME_ZONE_ID2)); $this->assertEquals($this->stringDateTime3, DateTimeUtils::ToStringForTimeZone(DateTimeUtils::ToDfpDateTime($this->dateTime3->setTimeZone(new DateTimeZone(self::TIME_ZONE_ID1))), self::TIME_ZONE_ID3)); }
$adUnitTargeting->adUnitId = $rootAdUnitId; $adUnitTargeting->includeDescendants = true; $inventoryTargeting->targetedAdUnits = array($adUnitTargeting); // Create targeting. $targeting = new Targeting(); $targeting->inventoryTargeting = $inventoryTargeting; // Create a proposal line item. $proposalLineItem = new ProposalLineItem(); $proposalLineItem->name = sprintf('Proposal line item #%s', uniqid()); $proposalLineItem->proposalId = $proposalId; $proposalLineItem->rateCardId = $rateCardId; $proposalLineItem->productId = $productId; $proposalLineItem->targeting = $targeting; // Set the length of the proposal line item to run. $proposalLineItem->startDateTime = DateTimeUtils::ToDfpDateTime(new DateTime('now', new DateTimeZone('America/New_York'))); $proposalLineItem->endDateTime = DateTimeUtils::ToDfpDateTime(new DateTime('+1 month', new DateTimeZone('America/New_York'))); // Set delivery specifications for the proposal line item. $proposalLineItem->deliveryRateType = 'EVENLY'; $proposalLineItem->creativeRotationType = 'OPTIMIZED'; // Set billing specifications for the proposal line item. $proposalLineItem->billingCap = 'CAPPED_CUMULATIVE'; $proposalLineItem->billingSource = 'THIRD_PARTY_VOLUME'; // Set pricing for the proposal line item for 1000 impressions at a CPM of $2 // for a total value of $2. $goal = new Goal(); $goal->units = 1000; $goal->unitType = 'IMPRESSIONS'; $proposalLineItem->goal = $goal; $proposalLineItem->cost = new Money('USD', 2000000); $proposalLineItem->costPerUnit = new Money('USD', 2000000); $proposalLineItem->rateType = 'CPM';
require_once 'Google/Api/Ads/Dfp/Util/v201511/StatementBuilder.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the ReconciliationReportService. $reconciliationReportService = $user->GetService('ReconciliationReportService', 'v201511'); // Get the NetworkService. $networkService = $user->GetService('NetworkService', 'v201511'); $network = $networkService->getCurrentNetwork(); // Create a statement to select the last month's reconciliation report. $statementBuilder = new StatementBuilder(); $statementBuilder->Where('startDate = :startDate')->OrderBy('id ASC')->Limit(1)->WithBindVariableValue('startDate', DateTimeUtils::ToString(DateTimeUtils::ToDfpDateTime(new DateTime('first day of last month', new DateTimeZone($network->timeZone)))->date)); // Default for total result set size. $totalResultSetSize = 0; do { // Get reconciliation reports by statement. $page = $reconciliationReportService->getReconciliationReportsByStatement($statementBuilder->ToStatement()); // Display results. if (isset($page->results)) { $totalResultSetSize = $page->totalResultSetSize; $i = $page->startIndex; foreach ($page->results as $reconciliationReport) { printf("%d) Reconciliation report with ID %d for month %s/%s was found.\n", $i++, $reconciliationReport->id, $reconciliationReport->startDate->month, $reconciliationReport->startDate->year); } } $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT); } while ($statementBuilder->GetOffset() < $totalResultSetSize);
// Get the ReportService. $reportService = $user->GetService('ReportService', 'v201605'); // Create report query. $reportQuery = new ReportQuery(); $reportQuery->dimensions = array('ORDER_ID', 'ORDER_NAME'); $reportQuery->dimensionAttributes = array('ORDER_TRAFFICKER', 'ORDER_START_DATE_TIME', 'ORDER_END_DATE_TIME'); $reportQuery->columns = array('AD_SERVER_IMPRESSIONS', 'AD_SERVER_CLICKS', 'AD_SERVER_CTR', 'AD_SERVER_CPM_AND_CPC_REVENUE', 'AD_SERVER_WITHOUT_CPD_AVERAGE_ECPM'); // Create statement to filter for an order. $statementBuilder = new StatementBuilder(); $statementBuilder->Where('order_id = :orderId')->WithBindVariableValue('orderId', $orderId); // Set the filter statement. $reportQuery->statement = $statementBuilder->ToStatement(); // Set the start and end dates or choose a dynamic date range type. $reportQuery->dateRangeType = 'CUSTOM_DATE'; $reportQuery->startDate = DateTimeUtils::ToDfpDateTime(new DateTime('-10 days', new DateTimeZone('America/New_York')))->date; $reportQuery->endDate = DateTimeUtils::ToDfpDateTime(new DateTime('now', new DateTimeZone('America/New_York')))->date; // Create report job. $reportJob = new ReportJob(); $reportJob->reportQuery = $reportQuery; // Run report job. $reportJob = $reportService->runReportJob($reportJob); // Create report downloader. $reportDownloader = new ReportDownloader($reportService, $reportJob->id); // Wait for the report to be ready. $reportDownloader->waitForReportReady(); // Change to your file location. $filePath = sprintf('%s.csv.gz', tempnam(sys_get_temp_dir(), 'delivery-report-')); printf("Downloading report to %s ...\n", $filePath); // Download the report. $reportDownloader->downloadReport('CSV_DUMP', $filePath); printf("done.\n");
$path = dirname(__FILE__) . '/../../../../lib'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once 'Google/Api/Ads/Dfp/Util/v201508/StatementBuilder.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogAll(); // Get the OrderService. $orderService = $user->GetService('OrderService', 'v201508'); // Create a statement to select only orders that are starting soon. $statementBuilder = new StatementBuilder(); $statementBuilder->Where('status = :status AND startDateTime >= :now AND startDateTime <= :soon')->OrderBy('id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT)->WithBindVariableValue('status', 'APPROVED')->WithBindVariableValue('now', DateTimeUtils::ToDfpDateTime(new DateTime('now', new DateTimeZone('America/New_York'))))->WithBindVariableValue('soon', DateTimeUtils::ToDfpDateTime(new DateTime('5 day', new DateTimeZone('America/New_York')))); // Default for total result set size. $totalResultSetSize = 0; do { // Get orders by statement. $page = $orderService->getOrdersByStatement($statementBuilder->ToStatement()); // Display results. if (isset($page->results)) { $totalResultSetSize = $page->totalResultSetSize; $i = $page->startIndex; foreach ($page->results as $order) { printf("%d) Order with ID %d, name '%s', and advertiser ID %d was " . "found.\n", $i++, $order->id, $order->name, $order->advertiserId); } } $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT); } while ($statementBuilder->GetOffset() < $totalResultSetSize);
/** * Since this method doesn't support by google, they suggest this step : * 1) Get the line item using LineItemService.getLineItemsByStatement method * 2) Remove the id field from the LineItem object * 3) Use the LineItemService.createLineItems method with that new object * 4) Capture the new line item in the response * 5) Get all line item creative associations for the old line item using LineItemCreativeAssociationService * 6) For each LineItemCreativeAssociation object, replace the old line item ID with the new one * 7) Pass each LineItemCreativeAssociation object into the LineItemCreativeAssociationService.createLineItemCreativeAssociations method */ public function copyLineItems($dtToCopy) { // Get the LineItemService. $lineItemService = $this->dfp_user->GetService('LineItemService', 'v201508'); $statementBuilder = new StatementBuilder(); $statementBuilder->Where('id = :id')->Limit(1)->WithBindVariableValue('id', $dtToCopy['lineItemId']); // Get the line item. $page = $lineItemService->getLineItemsByStatement($statementBuilder->ToStatement()); if (isset($page->results)) { //echo "<br/>BEFORE<br/>"; //echopre($page->results); //$newLineItem = $lineItemService->createLineItems($page->results); //echopre($newLineItem); /* Adjust name, startDateTime and endDateTime to keep the lineitem unique */ $randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); $page->results[0]->name = $page->results[0]->name . "(copy-{$randomString})"; $page->results[0]->startDateTime = DateTimeUtils::ToDfpDateTime(new DateTime('+1 day', new DateTimeZone('Asia/Jakarta'))); $page->results[0]->endDateTime = DateTimeUtils::ToDfpDateTime(new DateTime('+2 day', new DateTimeZone('Asia/Jakarta'))); $page->results[0]->allowOverbook = true; $newLineItem = $lineItemService->createLineItems($page->results); #echo "<br/>New Lineitems<br/>"; #echopre($newLineItem); /*if line item copied with all creative below it*/ if ($dtToCopy['withCreative'] > 0) { $licaService = $this->dfp_user->GetService('LineItemCreativeAssociationService', 'v201508'); $statementBuilderLicas = new StatementBuilder(); $statementBuilderLicas->Where('lineItemId = :lineItemId')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT)->WithBindVariableValue('lineItemId', $dtToCopy['lineItemId']); // Get LICAs by statement. $pageLicas = $licaService->getLineItemCreativeAssociationsByStatement($statementBuilderLicas->ToStatement()); if (isset($pageLicas->results)) { #echo "<br/>data licas<br/>"; #echopre($pageLicas); foreach ($pageLicas->results as $key => $val) { $val->lineItemId = $newLineItem[0]->id; // Create the LICAs on the server. $licas = $licaService->createLineItemCreativeAssociations($val); #echo $key . "<br/>"; #echopre($licas); } } } } }