Skip to content

Commit

Permalink
Update to v201811 & universal Creative
Browse files Browse the repository at this point in the history
  • Loading branch information
gchicoye committed Jan 11, 2019
1 parent cd45cdb commit 70242bb
Show file tree
Hide file tree
Showing 17 changed files with 519 additions and 335 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ adsapi_php.ini
/vendor
sftp-config.json
/.php_cs.cache
/customerConfig
17 changes: 8 additions & 9 deletions app/Dfp/CompanyManager.php → app/AdManager/CompanyManager.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace App\Dfp;
namespace App\AdManager;

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\Dfp\v201802\Company;
use Google\AdsApi\Dfp\v201802\CompanyService;
use Google\AdsApi\Dfp\v201802\CompanyType;
use Google\AdsApi\Dfp\Util\v201802\StatementBuilder;
use Google\AdsApi\AdManager\v201811\Company;
use Google\AdsApi\AdManager\v201811\CompanyType;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;

class CompanyManager extends DfpManager
class CompanyManager extends Manager
{
public function setUpCompany($companyName)
{
Expand All @@ -24,7 +23,7 @@ public function createCompany($companyName)
{
$output = [];

$companyService = $this->dfpServices->get($this->session, CompanyService::class);
$companyService = $this->serviceFactory->createCompanyService($this->session);
$company = new Company();
$company->setName($companyName);
$company->setType(CompanyType::ADVERTISER);
Expand All @@ -45,7 +44,7 @@ public function createCompany($companyName)
public function getAllCompanies()
{
$output = [];
$companyService = $this->dfpServices->get($this->session, CompanyService::class);
$companyService = $this->serviceFactory->createCompanyService($this->session);
$statementBuilder = (new StatementBuilder())->orderBy('id ASC');
$data = $companyService->getCompaniesByStatement($statementBuilder->toStatement());
if (null !== $data->getResults()) {
Expand All @@ -64,7 +63,7 @@ public function getAllCompanies()
public function getCompany($companyName)
{
$output = [];
$companyService = $this->dfpServices->get($this->session, CompanyService::class);
$companyService = $this->serviceFactory->createCompanyService($this->session);
$statementBuilder = (new StatementBuilder())
->orderBy('id ASC')
->where('name = :name')
Expand Down
80 changes: 71 additions & 9 deletions app/Dfp/CreativeManager.php → app/AdManager/CreativeManager.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

namespace App\Dfp;
namespace App\AdManager;

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\Dfp\Util\v201802\StatementBuilder;
use Google\AdsApi\Dfp\v201802\CreativeService;
use Google\AdsApi\Dfp\v201802\ThirdPartyCreative;
use Google\AdsApi\Dfp\v201802\Size;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201811\CreativeService;
use Google\AdsApi\AdManager\v201811\ThirdPartyCreative;
use Google\AdsApi\AdManager\v201811\Size;

class CreativeManager extends DfpManager
class CreativeManager extends Manager
{
protected $ssp;
protected $advertiserId;
Expand Down Expand Up @@ -44,6 +44,8 @@ public function setUpCreatives()
foreach ($creativeNameList as $creativeName) {
if (empty(($foo = $this->getCreative($creativeName)))) {
$foo = $this->createCreative($creativeName, $this->createSnippet(), $this->advertiserId);
} else {
$foo = $this->updateCreative($creativeName, $this->createSnippet(), $this->advertiserId);
}
array_push($output, $foo[0]);
}
Expand All @@ -54,7 +56,7 @@ public function setUpCreatives()
public function getAllCreatives()
{
$output = [];
$creativeService = $this->dfpServices->get($this->session, CreativeService::class);
$creativeService = $this->serviceFactory->createCreativeService($this->session);
$pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
$statementBuilder = (new StatementBuilder())->orderBy('id ASC')
->limit($pageSize);
Expand Down Expand Up @@ -82,7 +84,7 @@ public function getAllCreatives()
public function getCreative($creativeName)
{
$output = [];
$creativeService = $this->dfpServices->get($this->session, CreativeService::class);
$creativeService = $this->serviceFactory->createCreativeService($this->session);
$statementBuilder = (new StatementBuilder())
->orderBy('id ASC')
->where('name = :name AND advertiserId = :advertiserId')
Expand All @@ -105,7 +107,7 @@ public function getCreative($creativeName)
public function createCreative($creativeName, $snippet, $advertiserId)
{
$output = [];
$creativeService = $this->dfpServices->get($this->session, CreativeService::class);
$creativeService = $this->serviceFactory->createCreativeService($this->session);
$size = new Size();
$size->setWidth(1);
$size->setHeight(1);
Expand All @@ -132,6 +134,64 @@ public function createCreative($creativeName, $snippet, $advertiserId)
return $output;
}

public function updateCreative($creativeName, $snippet, $advertiserId)
{
$output = [];
$creativeService = $this->serviceFactory->createCreativeService($this->session);
$statementBuilder = (new StatementBuilder())->where('name = :name')
->orderBy('id ASC')
->limit(1)
->withBindVariableValue('name', $creativeName);
// Get the creative.
$page = $creativeService->getCreativesByStatement(
$statementBuilder->toStatement()
);

$creative = $page->getResults()[0];
$size = new Size();
$size->setWidth(1);
$size->setHeight(1);
$size->setIsAspectRatio(false);

$creative->setName($creativeName)
->setAdvertiserId($advertiserId)
->setIsSafeFrameCompatible(true)
->setSnippet($snippet)
->setSize($size);

// Create the order on the server.
$results = $creativeService->updateCreatives([$creative]);
foreach ($results as $creative) {
$foo = [
'creativeId' => $creative->getId(),
'creativeName' => $creative->getName(),
];
array_push($output, $foo);
}

return $output;
}


private function createSnippet()
{
$snippet = "<script src = 'https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/creative.js'></script>\n";
$snippet .= "<script>\n";
$snippet .= "\tvar ucTagData = {};\n";
$snippet .= "\tucTagData.adServerDomain = '';\n";
$snippet .= "\tucTagData.pubUrl = '%%PATTERN:url%%';\n";
$snippet .= "\tucTagData.targetingMap = %%PATTERN:TARGETINGMAP%%;\n";
$snippet .= "\ttry {\n";
$snippet .= "\t\tucTag.renderAd(document, ucTagData);\n";
$snippet .= "\t} catch (e) {\n";
$snippet .= "\t\tconsole.log(e);\n";
$snippet .= "\t}\n";
$snippet .= "</script>\n";

return $snippet;

}
/*
private function createSnippet()
{
if (empty($this->ssp)) {
Expand All @@ -156,4 +216,6 @@ private function createSnippet()
return $snippet;
}
*/
}
18 changes: 9 additions & 9 deletions app/Dfp/KeyManager.php → app/AdManager/KeyManager.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

namespace App\Dfp;
namespace App\AdManager;

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\Dfp\v201802\CustomTargetingKey;
use Google\AdsApi\Dfp\v201802\CustomTargetingKeyType;
use Google\AdsApi\Dfp\v201802\CustomTargetingService;
use Google\AdsApi\Dfp\Util\v201802\StatementBuilder;
use Google\AdsApi\AdManager\v201811\CustomTargetingKey;
use Google\AdsApi\AdManager\v201811\CustomTargetingKeyType;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;

class KeyManager extends DfpManager

class KeyManager extends Manager
{
public function setUpCustomTargetingKey($keyName)
{
Expand All @@ -23,7 +23,7 @@ public function setUpCustomTargetingKey($keyName)
public function createCustomTargetingKey($keyName)
{
$output = [];
$customTargetingService = $this->dfpServices->get($this->session, CustomTargetingService::class);
$customTargetingService = $this->serviceFactory->createCustomTargetingService($this->session);
$key = new CustomTargetingKey();
$key->setDisplayName($keyName);
$key->setName($keyName);
Expand All @@ -45,7 +45,7 @@ public function createCustomTargetingKey($keyName)
public function getAllCustomTargetingKeys()
{
$output = [];
$customTargetingService = $this->dfpServices->get($this->session, CustomTargetingService::class);
$customTargetingService = $this->serviceFactory->createCustomTargetingService($this->session);
$statementBuilder = (new StatementBuilder())->orderBy('id ASC');
$data = $customTargetingService->getCustomTargetingKeysByStatement($statementBuilder->toStatement());
if (null == $data->getResults()) {
Expand All @@ -66,7 +66,7 @@ public function getAllCustomTargetingKeys()
public function getCustomTargetingKey($keyName)
{
$output = [];
$customTargetingService = $this->dfpServices->get($this->session, CustomTargetingService::class);
$customTargetingService = $this->serviceFactory->createCustomTargetingService($this->session);
$statementBuilder = (new StatementBuilder())
->orderBy('id ASC')
->where('name = :name')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace App\Dfp;
namespace App\AdManager;

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\Dfp\v201802\LineItemCreativeAssociation;
use Google\AdsApi\Dfp\v201802\LineItemCreativeAssociationService;
use Google\AdsApi\Dfp\v201802\Size;
use Google\AdsApi\Dfp\Util\v201802\StatementBuilder;
use Google\AdsApi\Dfp\v201802\ApiException;
use Google\AdsApi\AdManager\v201811\LineItemCreativeAssociation;
use Google\AdsApi\AdManager\v201811\LineItemCreativeAssociationService;
use Google\AdsApi\AdManager\v201811\Size;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201811\ApiException;

class LineItemCreativeAssociationManager extends DfpManager
class LineItemCreativeAssociationManager extends Manager
{
protected $lineItem;
protected $creativeList;
Expand Down Expand Up @@ -60,7 +60,7 @@ public function setUpLica()

private function UpdateLicas($licasToBeUpdated)
{
$licaService = $this->dfpServices->get($this->session, LineItemCreativeAssociationService::class);
$licaService = $this->serviceFactory->createLineItemCreativeAssociationService($this->session);
$attempts = 0;

do {
Expand Down Expand Up @@ -100,7 +100,7 @@ private function UpdateLicas($licasToBeUpdated)

private function CreateLicas($licasToBeCreated)
{
$licaService = $this->dfpServices->get($this->session, LineItemCreativeAssociationService::class);
$licaService = $this->serviceFactory->createLineItemCreativeAssociationService($this->session);
$attempts = 0;
do {
try {
Expand All @@ -127,7 +127,7 @@ private function CreateLicas($licasToBeCreated)
private function GetLicasForLineItem()
{
$output = [];
$licaService = $this->dfpServices->get($this->session, LineItemCreativeAssociationService::class);
$licaService = $this->serviceFactory->createLineItemCreativeAssociationService($this->session);
$pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
$statementBuilder = (new StatementBuilder())->where('lineItemId = :lineItemId')
->orderBy('lineItemId ASC, creativeId ASC')
Expand Down
54 changes: 27 additions & 27 deletions app/Dfp/LineItemManager.php → app/AdManager/LineItemManager.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?php

namespace App\Dfp;
namespace App\AdManager;

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\Dfp\v201802\AdUnitTargeting;
use Google\AdsApi\Dfp\v201802\CostType;
use Google\AdsApi\Dfp\v201802\CreativePlaceholder;
use Google\AdsApi\Dfp\v201802\CreativeRotationType;
use Google\AdsApi\Dfp\v201802\CustomCriteria;
use Google\AdsApi\Dfp\v201802\CustomCriteriaComparisonOperator;
use Google\AdsApi\Dfp\v201802\CustomCriteriaSet;
use Google\AdsApi\Dfp\v201802\CustomCriteriaSetLogicalOperator;
use Google\AdsApi\Dfp\v201802\Goal;
use Google\AdsApi\Dfp\v201802\GoalType;
use Google\AdsApi\Dfp\v201802\InventoryTargeting;
use Google\AdsApi\Dfp\v201802\LineItem;
use Google\AdsApi\Dfp\v201802\LineItemService;
use Google\AdsApi\Dfp\v201802\LineItemType;
use Google\AdsApi\Dfp\v201802\Money;
use Google\AdsApi\Dfp\v201802\Size;
use Google\AdsApi\Dfp\v201802\StartDateTimeType;
use Google\AdsApi\Dfp\v201802\Targeting;
use Google\AdsApi\Dfp\Util\v201802\StatementBuilder;
use Google\AdsApi\Dfp\v201802\ApiException;

class LineItemManager extends DfpManager
use Google\AdsApi\AdManager\v201811\AdUnitTargeting;
use Google\AdsApi\AdManager\v201811\CostType;
use Google\AdsApi\AdManager\v201811\CreativePlaceholder;
use Google\AdsApi\AdManager\v201811\CreativeRotationType;
use Google\AdsApi\AdManager\v201811\CustomCriteria;
use Google\AdsApi\AdManager\v201811\CustomCriteriaComparisonOperator;
use Google\AdsApi\AdManager\v201811\CustomCriteriaSet;
use Google\AdsApi\AdManager\v201811\CustomCriteriaSetLogicalOperator;
use Google\AdsApi\AdManager\v201811\Goal;
use Google\AdsApi\AdManager\v201811\GoalType;
use Google\AdsApi\AdManager\v201811\InventoryTargeting;
use Google\AdsApi\AdManager\v201811\LineItem;
use Google\AdsApi\AdManager\v201811\LineItemService;
use Google\AdsApi\AdManager\v201811\LineItemType;
use Google\AdsApi\AdManager\v201811\Money;
use Google\AdsApi\AdManager\v201811\Size;
use Google\AdsApi\AdManager\v201811\StartDateTimeType;
use Google\AdsApi\AdManager\v201811\Targeting;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201811\ApiException;

class LineItemManager extends Manager
{
protected $orderId;
protected $sizes;
Expand Down Expand Up @@ -117,7 +117,7 @@ public function setUpLineItem()
public function getAllLineItems()
{
$output = [];
$lineItemService = $this->dfpServices->get($this->session, LineItemService::class);
$lineItemService = $this->serviceFactory->createLineItemService($this->session);

$statementBuilder = (new StatementBuilder())->orderBy('id ASC');
$data = $lineItemService->getLineItemsByStatement($statementBuilder->toStatement());
Expand All @@ -134,7 +134,7 @@ public function getAllLineItems()
public function getLineItem()
{
$output = '';
$lineItemService = $this->dfpServices->get($this->session, LineItemService::class);
$lineItemService = $this->serviceFactory->createLineItemService($this->session);
$statementBuilder = (new StatementBuilder())
->orderBy('id ASC')
->where('name = :name AND orderId = :orderId')
Expand All @@ -153,7 +153,7 @@ public function getLineItem()
public function createLineItem()
{
$output = [];
$lineItemService = $this->dfpServices->get($this->session, LineItemService::class);
$lineItemService = $this->serviceFactory->createLineItemService($this->session);

$attempts = 0;
do {
Expand Down Expand Up @@ -195,7 +195,7 @@ public function updateLineItem($lineItem)
{
$output = [];

$lineItemService = $this->dfpServices->get($this->session, LineItemService::class);
$lineItemService = $this->serviceFactory->createLineItemService($this->session);
$attempts = 0;
do {
try {
Expand Down
Loading

0 comments on commit 70242bb

Please sign in to comment.