diff --git a/CHANGELOG.md b/CHANGELOG.md index 756d157..38d064d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,23 @@ All notable changes to `fopost/sdk` are documented here. `BlogWebsiteTest`, `BlogKeyword`, `BlogArticle`, `BlogArticleFull`, `BlogArticleImage` and `BlogArticleWebhookPayload` models, and `WebhookEvent::article()`. The API no longer serves them; articles are ordinary posts. `$client->blogs()` is unchanged. +- **Breaking:** the ads campaign tree and network objects: `accountTree()`, `createCampaign()`, + `campaign()`, `updateCampaign()`, `deleteCampaign()`, `duplicateCampaign()`, `createAdSet()`, + `adSet()`, `updateAdSet()`, `deleteAdSet()`, `duplicateAdSet()`, `createNetworkAd()`, + `networkAd()`, `updateNetworkAd()`, `deleteNetworkAd()` and `duplicateNetworkAd()`, with the + `AdAccountTree`, `AdCampaign`, `AdSet` and `NetworkAd` models. The API no longer serves them. + `bulkSetStatus()` and the `$client->ads()` methods on `/ads` and `/ads/{id}` are unchanged. +- **Breaking:** creatives (`creatives()`, `createCreative()`, `creative()`, `deleteCreative()` and + `AdCreative`), product catalogs (`catalogs()`, `createCatalog()`, `getCatalog()`, + `updateCatalog()`, `deleteCatalog()`, `catalogProducts()`, `writeCatalogProducts()`, + `productFeeds()`, `createProductFeed()`, `deleteProductFeed()`, `feedUploads()`, + `startFeedUpload()`, `productSets()`, `createProductSet()`, `updateProductSet()`, + `deleteProductSet()` and their models) and the Ad Library (`library()`, `AdLibraryPage`, + `AdLibraryEntry`). The API no longer serves them. +- **Breaking:** the Google keyword, search term, negative keyword list, asset, asset group, + recommendation and optimization score methods on `$client->ads()->google()`, with their + `Google*` models. Bid strategies, the ad schedule, Local Services leads, conversions and + `query()` are unchanged. ## 0.4.0 - 2026-10-18 diff --git a/CLAUDE.md b/CLAUDE.md index 0cc3b6c..66e9678 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -69,7 +69,7 @@ src/ Ad.php AdInsights.php ExternalAd.php AdConnection.php AdSource.php BoostablePost.php Audience.php AudiencesResult.php CreatedAudience.php TargetingOption.php LeadForm.php LeadFormSource.php Lead.php LeadsPage.php LeadFormDetail.php FeedLead.php LeadsFeedPage.php LeadPage.php - AdAccountTree.php AdCampaign.php AdSet.php NetworkAd.php AdCreative.php BulkAdStatusResult.php + BulkAdStatusResult.php AdInsightsReport.php InsightsMetrics.php InsightsRow.php ReachEstimate.php AdPixel.php AdPixelDetail.php AdPixelStats.php AdPixelEventCount.php EventMatchQuality.php EventMatchKey.php ConversionUploadResult.php ConversionBatch.php ConversionBatchEvent.php CustomConversion.php CustomConversionRule.php @@ -120,17 +120,17 @@ resource is added. `scripts/sdk-gaps.mjs` in `fopost-api-collections` lists what own `PageMeta`. A recipient's `skipReason` is the messaging window's record: `window_closed` means the network's 24-hour window had shut and nothing was attempted, so a sent count lower than the audience is correct rather than a failure. -- `ads` (scope `ads`) covers the full `/ads` family: ads, external ads, boostable posts, - connections (+ Meta authorize), sources, boost, create, refresh, status, delete, audiences, - targeting search, lead forms and leads, plus the campaign tree (campaigns, ad sets, network ads, - duplicate, bulk status), creatives, audience detail and users, reach, insights, and the stored leads - feed with Page subscriptions, plus pixels (`pixels`, `createPixel`, `pixel`, `updatePixel`, `sharePixel`, - `pixelStats`, `eventMatchQuality`), the Conversions API (`uploadConversions`, `sendConversions` with a required - `Idempotency-Key`, `listConversionEvents`) and custom conversions. `sendConversionEvents()` is the older - LinkedIn conversion-rule send, hence the different name. `boost()`, `create()`, `setStatus()`, `delete()`, `bulkSetStatus()` and - every campaign, ad set and network ad write also need the `publish` scope, and anything created - starts paused unless `paused` is `false`. Campaign-tree objects take Meta ids plus `connection_id` - and are read live. An empty update or duplicate body goes out as `{}` because the API rejects none. Request +- `ads` (scope `ads`) covers the `/ads` family: ads, external ads, boostable posts, + connections (+ Meta authorize), sources, boost, create, refresh, status, delete, bulk status by + network id, audiences, targeting search, lead forms and leads, audience detail and users, reach, + insights, and the stored leads feed with Page subscriptions, plus pixels (`pixels`, `createPixel`, + `pixel`, `updatePixel`, `sharePixel`, `pixelStats`, `eventMatchQuality`), the Conversions API + (`uploadConversions`, `sendConversions` with a required `Idempotency-Key`, `listConversionEvents`) + and custom conversions. `ads()->google()` covers bid strategies, the ad schedule, Local Services + leads, conversions and GAQL. `sendConversionEvents()` is the older LinkedIn conversion-rule send, + hence the different name. `boost()`, `create()`, `setStatus()`, `delete()` and `bulkSetStatus()` + also need the `publish` scope, and anything created starts paused unless `paused` is `false`. + An empty update body goes out as `{}` because the API rejects none. Request bodies are camelCase; query params stay snake_case. `Resource::page()` is the shared `{data, meta}` → `Page` helper. - `media` (scope `posts`) is direct upload only: `limits()` → `UploadLimits`, `presign()` → diff --git a/README.md b/README.md index 083d9b1..491e060 100644 --- a/README.md +++ b/README.md @@ -600,50 +600,18 @@ $leads = $client->ads()->leads($formId, $connectionId, '555'); $more = $client->ads()->leads($formId, $connectionId, '555', after: $leads->nextCursor); ``` -### Campaigns, ad sets and ads +### Bulk status -These are addressed by Meta's own ids plus the `connectionId`, and read live, never stored. Creating, updating, deleting or duplicating any of them, and `bulkSetStatus()`, also need `publish`. New objects start paused unless `paused: false` is passed. +Pause or resume up to 50 campaigns, ad sets or ads at once by the network's own ids. Needs `publish` as well as `ads`. ```php -$tree = $client->ads()->accountTree('act_123', $connectionId); // campaigns → adSets → ads - -$campaign = $client->ads()->createCampaign($workspaceId, $connectionId, 'act_123', 'Launch', 'traffic'); -$adSet = $client->ads()->createAdSet( - workspaceId: $workspaceId, - connectionId: $connectionId, - campaignId: $campaign->id, - pageId: '555', - name: 'US adults', - goal: 'traffic', - budget: ['minor' => 2500, 'type' => 'daily'], - targeting: ['countries' => ['US'], 'ageMin' => 18, 'ageMax' => 65, 'gender' => 'all'], -); -$creative = $client->ads()->createCreative( - workspaceId: $workspaceId, - connectionId: $connectionId, - adAccountId: 'act_123', - pageId: '555', - name: 'Hero', - format: 'image', - text: 'Meet the new plan', - destinationUrl: 'https://yourbrand.com/plans', - urlTags: 'utm_source=meta&utm_medium=paid', - mediaUrl: $asset->url, -); -$ad = $client->ads()->createNetworkAd($workspaceId, $connectionId, $adSet->id, $creative->id, 'Hero ad'); - -$client->ads()->updateAdSet($adSet->id, $workspaceId, $connectionId, budgetMinor: 5000); -$copyId = $client->ads()->duplicateCampaign($campaign->id, $workspaceId, $connectionId); $client->ads()->bulkSetStatus($workspaceId, $connectionId, 'active', [ - ['id' => $campaign->id, 'level' => 'campaign'], - ['id' => $ad->id, 'level' => 'ad'], + ['id' => $campaignId, 'level' => 'campaign'], + ['id' => $adId, 'level' => 'ad'], ]); -$client->ads()->deleteCampaign($copyId, $workspaceId, $connectionId); -// also: campaign(), adSet(), networkAd(), updateCampaign(), updateNetworkAd(), deleteAdSet(), -// deleteNetworkAd(), duplicateAdSet(), duplicateNetworkAd(), creatives(), creative(), deleteCreative() ``` -### Forecasts, conversions and the ad library +### Forecasts and conversions Available wherever the network's `capabilities` say so — `providers()` reports them. @@ -659,8 +627,6 @@ $client->ads()->attachConversionRule($ruleId, $workspaceId, $connectionId, $adSe $client->ads()->conversionMetrics($ruleId, $workspaceId, $connectionId, '2026-09-01', '2026-09-30'); // Each event needs happenedAt in epoch ms and an email or a clickId; the API hashes the address. $client->ads()->sendConversionEvents($ruleId, $workspaceId, $connectionId, $events); - -$page = $client->ads()->adLibrary($workspaceId, $connectionId, keyword: 'crm', countries: ['US']); ``` ### Pixels, the Conversions API and custom conversions @@ -715,7 +681,7 @@ $reach = $client->ads()->estimateReach($workspaceId, $connectionId, 'act_123', ' ]); // any campaign, ad set or ad by Meta id; breakdown is age, gender, placement or country -$report = $client->ads()->insights($connectionId, $campaign->id, '2026-09-01', '2026-09-07', breakdown: 'age', daily: true); +$report = $client->ads()->insights($connectionId, $campaignId, '2026-09-01', '2026-09-07', breakdown: 'age', daily: true); $report = $client->ads()->adInsights($boost->id, $workspaceId, '2026-09-01', '2026-09-07'); // a FoPost ad id ``` @@ -736,27 +702,12 @@ while ($page->nextCursor !== null) { $client->ads()->unsubscribeLeadPage('555', $workspaceId, $connectionId); ``` -Catalogs, predictions and the public archive: +Goals and predictions: ```php // Ask the connection what it can run, rather than assuming. $goals = $client->ads()->goals($connectionId, $workspaceId); -// A catalog with a product set is what a catalog ad runs from. -$catalog = $client->ads()->createCatalog($workspaceId, $connectionId, 'Shop'); -$client->ads()->writeCatalogProducts($catalog->id, $workspaceId, $connectionId, [ - [ - 'op' => 'upsert', - 'retailerId' => 'SKU-1042', - 'name' => 'Trail Runner', - 'url' => 'https://yourbrand.com/shop/trail-runner', - 'imageUrl' => 'https://yourbrand.com/img/trail-runner.jpg', - 'priceMinor' => 12900, - 'currency' => 'USD', - ], -]); -$set = $client->ads()->createProductSet($catalog->id, $workspaceId, $connectionId, 'Best sellers'); - // Price a flight before buying it. $prediction = $client->ads()->createReachFrequency( $workspaceId, @@ -770,9 +721,6 @@ $prediction = $client->ads()->createReachFrequency( '2026-10-08T00:00:00Z', ); $client->ads()->reserveReachFrequency($prediction->id, $workspaceId, $connectionId, 'act_1234567890'); - -// What anyone is running, read live and stored nowhere. -$archive = $client->ads()->library($connectionId, ['US'], $workspaceId, q: 'running shoes'); ``` ## Media @@ -1217,24 +1165,21 @@ MIT. Copyright Porter Bridge, LLC. ### Google Ads -Campaigns, ad groups, ads, audiences and insights are on `$client->ads()` and dispatch by -connection. What only Google has is under `$client->ads()->google()`: +Audiences and insights are on `$client->ads()` and dispatch by connection. What only Google +has is under `$client->ads()->google()`: ```php -$keywords = $client->ads()->google()->keywords('c4d5e6f7-…', '1234567890'); +$strategies = $client->ads()->google()->bidStrategies('c4d5e6f7-…', '1234567890'); -$client->ads()->google()->createKeyword( +$client->ads()->google()->setAdSchedule( workspaceId: '7d2b8c11-…', connectionId: 'c4d5e6f7-…', customerId: '1234567890', - adGroupId: '1234567890~adGroup~77', - text: 'running shoes', - matchType: 'EXACT', + campaignId: '1234567890~campaign~55', + slots: [['dayOfWeek' => 'MONDAY', 'startHour' => 9, 'endHour' => 18]], ); ``` -Also `keywordIdeas()`, `keywordMetrics()`, `searchTerms()`, `bidStrategies()`, -`adSchedule()` and `setAdSchedule()`, the negative keyword lists, `assets()` and -`assetGroups()`, `localServicesLeads()`, the conversion methods, and `query()` for a raw -read-only GAQL SELECT. Changes need the `publish` scope as well as `ads`; the customer id -has to name an account the connection's grant reaches. +Also `createBidStrategy()`, `adSchedule()`, `localServicesLeads()`, the conversion methods, +and `query()` for a raw read-only GAQL SELECT. Changes need the `publish` scope as well as +`ads`; the customer id has to name an account the connection's grant reaches. diff --git a/src/Model/AdAccountTree.php b/src/Model/AdAccountTree.php deleted file mode 100644 index 8374a8a..0000000 --- a/src/Model/AdAccountTree.php +++ /dev/null @@ -1,33 +0,0 @@ - $campaigns */ - private function __construct( - array $raw, - public readonly string $adAccountId, - public readonly ?string $currency, - public readonly ?string $workspaceId, - public readonly array $campaigns, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::requiredStr($data, 'ad_account_id'), - self::str($data, 'currency'), - self::str($data, 'workspace_id'), - AdCampaign::listFrom(self::seq($data, 'campaigns')), - ); - } -} diff --git a/src/Model/AdCampaign.php b/src/Model/AdCampaign.php deleted file mode 100644 index 7a90499..0000000 --- a/src/Model/AdCampaign.php +++ /dev/null @@ -1,46 +0,0 @@ - $adSets */ - private function __construct( - array $raw, - public readonly string $id, - public readonly string $name, - public readonly string $status, - public readonly ?string $effectiveStatus, - public readonly ?string $objective, - public readonly ?int $budgetMinor, - public readonly ?string $budgetType, - public readonly ?string $createdAt, - public readonly array $adSets, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::requiredStr($data, 'id'), - self::requiredStr($data, 'name'), - self::requiredStr($data, 'status'), - self::str($data, 'effective_status'), - self::str($data, 'objective'), - self::int($data, 'budget_minor'), - self::str($data, 'budget_type'), - self::str($data, 'created_at'), - AdSet::listFrom(self::seq($data, 'ad_sets')), - ); - } -} diff --git a/src/Model/AdCreative.php b/src/Model/AdCreative.php deleted file mode 100644 index af14679..0000000 --- a/src/Model/AdCreative.php +++ /dev/null @@ -1,44 +0,0 @@ - $bodies - * @param array $titles - * @param array $linkUrls - * @param array $publisherPlatforms - */ - private function __construct( - array $raw, - public readonly string $id, - public readonly ?string $pageId, - public readonly ?string $pageName, - public readonly array $bodies, - public readonly array $titles, - public readonly array $linkUrls, - public readonly ?string $snapshotUrl, - public readonly array $publisherPlatforms, - public readonly ?string $startedAt, - public readonly ?string $endedAt, - /** Only on the archive's disclosure entries. */ - public readonly ?string $currency, - public readonly ?int $spendLower, - public readonly ?int $spendUpper, - public readonly ?int $impressionsLower, - public readonly ?int $impressionsUpper, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::requiredStr($data, 'id'), - self::str($data, 'page_id'), - self::str($data, 'page_name'), - self::seq($data, 'bodies'), - self::seq($data, 'titles'), - self::seq($data, 'link_urls'), - self::str($data, 'snapshot_url'), - self::seq($data, 'publisher_platforms'), - self::str($data, 'started_at'), - self::str($data, 'ended_at'), - self::str($data, 'currency'), - self::int($data, 'spend_lower'), - self::int($data, 'spend_upper'), - self::int($data, 'impressions_lower'), - self::int($data, 'impressions_upper'), - ); - } -} diff --git a/src/Model/AdLibraryPage.php b/src/Model/AdLibraryPage.php deleted file mode 100644 index 85340cd..0000000 --- a/src/Model/AdLibraryPage.php +++ /dev/null @@ -1,29 +0,0 @@ - $entries */ - private function __construct( - array $raw, - public readonly array $entries, - public readonly ?string $nextCursor, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - AdLibraryEntry::listFrom(self::seq($data, 'entries')), - self::str($data, 'next_cursor'), - ); - } -} diff --git a/src/Model/AdSet.php b/src/Model/AdSet.php deleted file mode 100644 index 52bc4b4..0000000 --- a/src/Model/AdSet.php +++ /dev/null @@ -1,47 +0,0 @@ - $ads */ - private function __construct( - array $raw, - public readonly string $id, - public readonly string $name, - public readonly ?string $campaignId, - public readonly string $status, - public readonly ?string $effectiveStatus, - public readonly ?int $budgetMinor, - public readonly ?string $budgetType, - public readonly ?string $endAt, - public readonly ?string $optimizationGoal, - public readonly ?string $createdAt, - public readonly array $ads, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::requiredStr($data, 'id'), - self::requiredStr($data, 'name'), - self::str($data, 'campaign_id'), - self::requiredStr($data, 'status'), - self::str($data, 'effective_status'), - self::int($data, 'budget_minor'), - self::str($data, 'budget_type'), - self::str($data, 'end_at'), - self::str($data, 'optimization_goal'), - self::str($data, 'created_at'), - NetworkAd::listFrom(self::seq($data, 'ads')), - ); - } -} diff --git a/src/Model/CatalogBatchResult.php b/src/Model/CatalogBatchResult.php deleted file mode 100644 index 5a6dbb4..0000000 --- a/src/Model/CatalogBatchResult.php +++ /dev/null @@ -1,25 +0,0 @@ - $handles */ - private function __construct( - array $raw, - public readonly array $handles, - public readonly int $accepted, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self($data, self::seq($data, 'handles'), self::int($data, 'accepted') ?? 0); - } -} diff --git a/src/Model/CatalogProduct.php b/src/Model/CatalogProduct.php deleted file mode 100644 index 587f3a7..0000000 --- a/src/Model/CatalogProduct.php +++ /dev/null @@ -1,44 +0,0 @@ - $products */ - private function __construct( - array $raw, - public readonly array $products, - public readonly ?string $nextCursor, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - CatalogProduct::listFrom(self::seq($data, 'products')), - self::str($data, 'next_cursor'), - ); - } -} diff --git a/src/Model/GoogleAsset.php b/src/Model/GoogleAsset.php deleted file mode 100644 index de42ca1..0000000 --- a/src/Model/GoogleAsset.php +++ /dev/null @@ -1,34 +0,0 @@ - */ - public readonly array $finalUrls, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::requiredStr($data, 'id'), - self::requiredStr($data, 'campaignId'), - self::requiredStr($data, 'name'), - self::requiredStr($data, 'status'), - array_values(array_filter(self::seq($data, 'finalUrls'), 'is_string')), - ); - } -} diff --git a/src/Model/GoogleAssetLink.php b/src/Model/GoogleAssetLink.php deleted file mode 100644 index 4074d40..0000000 --- a/src/Model/GoogleAssetLink.php +++ /dev/null @@ -1,36 +0,0 @@ - $assets - * @param array $links - */ - private function __construct( - array $raw, - public readonly array $assets, - public readonly array $links, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - GoogleAsset::listFrom(self::seq($data, 'assets')), - GoogleAssetLink::listFrom(self::seq($data, 'links')), - ); - } -} diff --git a/src/Model/GoogleKeyword.php b/src/Model/GoogleKeyword.php deleted file mode 100644 index 3182831..0000000 --- a/src/Model/GoogleKeyword.php +++ /dev/null @@ -1,38 +0,0 @@ -~keyword~~`. */ -final class GoogleKeyword extends Model -{ - private function __construct( - array $raw, - public readonly string $id, - public readonly string $adGroupId, - public readonly string $text, - public readonly string $matchType, - public readonly string $status, - public readonly ?int $cpcBidMinor, - public readonly ?bool $negative, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::requiredStr($data, 'id'), - self::requiredStr($data, 'adGroupId'), - self::requiredStr($data, 'text'), - self::requiredStr($data, 'matchType'), - self::requiredStr($data, 'status'), - self::int($data, 'cpcBidMinor'), - self::bool($data, 'negative'), - ); - } -} diff --git a/src/Model/GoogleKeywordIdea.php b/src/Model/GoogleKeywordIdea.php deleted file mode 100644 index 416b658..0000000 --- a/src/Model/GoogleKeywordIdea.php +++ /dev/null @@ -1,34 +0,0 @@ - $campaigns */ - private function __construct( - array $raw, - public readonly ?float $score, - public readonly ?float $weight, - public readonly array $campaigns, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::float($data, 'score'), - self::float($data, 'weight'), - GoogleOptimizationScoreCampaign::listFrom($data['campaigns'] ?? []), - ); - } -} diff --git a/src/Model/GoogleOptimizationScoreCampaign.php b/src/Model/GoogleOptimizationScoreCampaign.php deleted file mode 100644 index 441a344..0000000 --- a/src/Model/GoogleOptimizationScoreCampaign.php +++ /dev/null @@ -1,30 +0,0 @@ - */ - public readonly array $metrics, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::requiredStr($data, 'term'), - self::str($data, 'adGroupId'), - self::str($data, 'status'), - self::map($data, 'metrics'), - ); - } -} diff --git a/src/Model/GoogleSharedSet.php b/src/Model/GoogleSharedSet.php deleted file mode 100644 index ee5e305..0000000 --- a/src/Model/GoogleSharedSet.php +++ /dev/null @@ -1,32 +0,0 @@ - $catalogs */ - private function __construct( - array $raw, - public readonly array $catalogs, - public readonly ?string $workspaceId, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - ProductCatalog::listFrom(self::seq($data, 'catalogs')), - self::str($data, 'workspace_id'), - ); - } -} diff --git a/src/Model/ProductFeed.php b/src/Model/ProductFeed.php deleted file mode 100644 index 6fbc6bf..0000000 --- a/src/Model/ProductFeed.php +++ /dev/null @@ -1,34 +0,0 @@ - $filter */ - private function __construct( - array $raw, - public readonly string $id, - public readonly string $name, - public readonly ?int $productCount, - public readonly array $filter, - ) { - parent::__construct($raw); - } - - public static function fromArray(mixed $data): static - { - $data = is_array($data) ? $data : []; - - return new self( - $data, - self::requiredStr($data, 'id'), - self::requiredStr($data, 'name'), - self::int($data, 'product_count'), - self::map($data, 'filter'), - ); - } -} diff --git a/src/Resource/AdsResource.php b/src/Resource/AdsResource.php index cfe0bc6..b3efd03 100644 --- a/src/Resource/AdsResource.php +++ b/src/Resource/AdsResource.php @@ -6,22 +6,17 @@ use DateTimeInterface; use Fopost\Sdk\Model\Ad; -use Fopost\Sdk\Model\AdAccountTree; use Fopost\Sdk\Model\AdActivityResult; use Fopost\Sdk\Model\AdBusinessCenter; -use Fopost\Sdk\Model\AdCampaign; use Fopost\Sdk\Model\AdCommentsPage; use Fopost\Sdk\Model\AdConnection; -use Fopost\Sdk\Model\AdCreative; use Fopost\Sdk\Model\AdIdentity; use Fopost\Sdk\Model\AdInsightsReport; -use Fopost\Sdk\Model\AdLibraryPage; use Fopost\Sdk\Model\AdProvider; use Fopost\Sdk\Model\AdLabel; use Fopost\Sdk\Model\AdPixel; use Fopost\Sdk\Model\AdPixelDetail; use Fopost\Sdk\Model\AdPixelStats; -use Fopost\Sdk\Model\AdSet; use Fopost\Sdk\Model\AdSource; use Fopost\Sdk\Model\AdStudy; use Fopost\Sdk\Model\Audience; @@ -34,8 +29,6 @@ use Fopost\Sdk\Model\ConversionRule; use Fopost\Sdk\Model\ConversionUploadResult; use Fopost\Sdk\Model\CustomConversion; -use Fopost\Sdk\Model\CatalogBatchResult; -use Fopost\Sdk\Model\CatalogProductsPage; use Fopost\Sdk\Model\CreatedAudience; use Fopost\Sdk\Model\EventMatchQuality; use Fopost\Sdk\Model\ExternalAd; @@ -46,13 +39,7 @@ use Fopost\Sdk\Model\LeadPage; use Fopost\Sdk\Model\LeadsFeedPage; use Fopost\Sdk\Model\LeadsPage; -use Fopost\Sdk\Model\NetworkAd; use Fopost\Sdk\Model\PartnershipCreator; -use Fopost\Sdk\Model\ProductCatalog; -use Fopost\Sdk\Model\ProductCatalogsResult; -use Fopost\Sdk\Model\ProductFeed; -use Fopost\Sdk\Model\ProductFeedUpload; -use Fopost\Sdk\Model\ProductSet; use Fopost\Sdk\Model\ReachEstimate; use Fopost\Sdk\Model\SupplyForecast; use Fopost\Sdk\Model\SparkPost; @@ -62,20 +49,18 @@ use Fopost\Sdk\Model\ValueRuleSet; /** - * $client->ads(): ads, catalogs, audiences, the ad archive and lead forms. + * $client->ads(): ads, audiences and lead forms. * * Meta is what this resource covers; the Google-only surface is ads()->google(). * - * Every call needs the `ads` scope. boost(), create(), setStatus(), delete(), bulkSetStatus() and the - * create, update, delete and duplicate calls on campaigns, ad sets and network ads spend money and - * also need the `publish` scope. Campaigns, ad sets, network ads and creatives are addressed by the - * network's own ids and read live, never stored. + * Every call needs the `ads` scope. boost(), create(), setStatus(), delete() and bulkSetStatus() + * spend money and also need the `publish` scope. */ final class AdsResource extends Resource { private ?GoogleAdsResource $google = null; - /** The Search surface no other network has: keywords, assets, conversions, GAQL. */ + /** The Google-only surface: bid strategies, ad schedule, Local Services leads, conversions, GAQL. */ public function google(): GoogleAdsResource { return $this->google ??= new GoogleAdsResource($this->http); @@ -759,234 +744,6 @@ public function deleteComment( ]); } - /** Every campaign on the ad account with its ad sets and ads, read live. */ - public function accountTree(string $adAccountId, string $connectionId, ?string $workspaceId = null): AdAccountTree - { - return AdAccountTree::fromArray(self::unwrap($this->http->get( - "/ads/accounts/{$adAccountId}/tree", - self::scope($workspaceId, $connectionId), - ))); - } - - /** - * Needs the `publish` scope as well as `ads`. Starts paused unless $paused is false. - * Goal is engagement, traffic, awareness or video_views. - */ - public function createCampaign( - string $workspaceId, - string $connectionId, - string $adAccountId, - string $name, - string $goal, - ?bool $paused = null, - ?bool $smartPlus = null, - ): AdCampaign { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'adAccountId' => $adAccountId, - 'name' => $name, - 'goal' => $goal, - 'paused' => $paused, - 'smartPlus' => $smartPlus, - ]); - - return AdCampaign::fromArray(self::unwrap($this->http->post('/ads/campaigns', $body))); - } - - public function campaign(string $campaignId, string $connectionId, ?string $workspaceId = null): AdCampaign - { - return AdCampaign::fromArray(self::unwrap( - $this->http->get("/ads/campaigns/{$campaignId}", self::scope($workspaceId, $connectionId)), - )); - } - - /** Needs the `publish` scope as well as `ads`. Status is `active` or `paused`. */ - public function updateCampaign( - string $campaignId, - string $workspaceId, - string $connectionId, - ?string $name = null, - ?string $status = null, - ): AdCampaign { - $body = self::object(['name' => $name, 'status' => $status]); - - return AdCampaign::fromArray(self::unwrap($this->http->request( - 'PATCH', - "/ads/campaigns/{$campaignId}", - $body, - self::scope($workspaceId, $connectionId), - ))); - } - - /** Needs the `publish` scope as well as `ads`. */ - public function deleteCampaign(string $campaignId, string $workspaceId, string $connectionId): void - { - $this->http->request('DELETE', "/ads/campaigns/{$campaignId}", null, self::scope($workspaceId, $connectionId)); - } - - /** Copy the campaign with everything under it and return the copy's id. Needs the `publish` scope. */ - public function duplicateCampaign( - string $campaignId, - string $workspaceId, - string $connectionId, - ?bool $paused = null, - ): string { - return $this->duplicate("/ads/campaigns/{$campaignId}/duplicate", $workspaceId, $connectionId, $paused); - } - - /** - * Needs the `publish` scope as well as `ads`. Starts paused unless $paused is false. - * - * @param array $budget `{minor, type: daily|lifetime, endAt?}` - * @param array $targeting countries, ageMin, ageMax, gender, audienceIds, locations, ... - */ - public function createAdSet( - string $workspaceId, - string $connectionId, - string $campaignId, - string $pageId, - string $name, - string $goal, - array $budget, - array $targeting, - ?bool $paused = null, - ): AdSet { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'campaignId' => $campaignId, - 'pageId' => $pageId, - 'name' => $name, - 'goal' => $goal, - 'budget' => $budget, - 'targeting' => $targeting, - 'paused' => $paused, - ]); - - return AdSet::fromArray(self::unwrap($this->http->post('/ads/ad-sets', $body))); - } - - public function adSet(string $adSetId, string $connectionId, ?string $workspaceId = null): AdSet - { - return AdSet::fromArray(self::unwrap( - $this->http->get("/ads/ad-sets/{$adSetId}", self::scope($workspaceId, $connectionId)), - )); - } - - /** - * Needs the `publish` scope as well as `ads`. The budget type set at creation stays. - * - * @param array|null $targeting replaces the whole targeting spec - */ - public function updateAdSet( - string $adSetId, - string $workspaceId, - string $connectionId, - ?string $name = null, - ?string $status = null, - ?int $budgetMinor = null, - string|DateTimeInterface|null $endAt = null, - ?array $targeting = null, - ): AdSet { - $body = self::object([ - 'name' => $name, - 'status' => $status, - 'budgetMinor' => $budgetMinor, - 'endAt' => self::iso($endAt), - 'targeting' => $targeting, - ]); - - return AdSet::fromArray(self::unwrap($this->http->request( - 'PATCH', - "/ads/ad-sets/{$adSetId}", - $body, - self::scope($workspaceId, $connectionId), - ))); - } - - /** Needs the `publish` scope as well as `ads`. */ - public function deleteAdSet(string $adSetId, string $workspaceId, string $connectionId): void - { - $this->http->request('DELETE', "/ads/ad-sets/{$adSetId}", null, self::scope($workspaceId, $connectionId)); - } - - /** Copy the ad set with its ads and return the copy's id. Needs the `publish` scope. */ - public function duplicateAdSet( - string $adSetId, - string $workspaceId, - string $connectionId, - ?bool $paused = null, - ): string { - return $this->duplicate("/ads/ad-sets/{$adSetId}/duplicate", $workspaceId, $connectionId, $paused); - } - - /** - * Create an ad inside an ad set from a creative. Distinct from create(), the one-call ad. - * Needs the `publish` scope as well as `ads`. Starts paused unless $paused is false. - */ - public function createNetworkAd( - string $workspaceId, - string $connectionId, - string $adSetId, - string $creativeId, - string $name, - ?bool $paused = null, - ): NetworkAd { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'adSetId' => $adSetId, - 'creativeId' => $creativeId, - 'name' => $name, - 'paused' => $paused, - ]); - - return NetworkAd::fromArray(self::unwrap($this->http->post('/ads/ads', $body))); - } - - public function networkAd(string $adId, string $connectionId, ?string $workspaceId = null): NetworkAd - { - return NetworkAd::fromArray(self::unwrap( - $this->http->get("/ads/ads/{$adId}", self::scope($workspaceId, $connectionId)), - )); - } - - /** Needs the `publish` scope as well as `ads`. Status is `active` or `paused`. */ - public function updateNetworkAd( - string $adId, - string $workspaceId, - string $connectionId, - ?string $name = null, - ?string $status = null, - ?string $creativeId = null, - ): NetworkAd { - $body = self::object(['name' => $name, 'status' => $status, 'creativeId' => $creativeId]); - - return NetworkAd::fromArray(self::unwrap($this->http->request( - 'PATCH', - "/ads/ads/{$adId}", - $body, - self::scope($workspaceId, $connectionId), - ))); - } - - /** Needs the `publish` scope as well as `ads`. */ - public function deleteNetworkAd(string $adId, string $workspaceId, string $connectionId): void - { - $this->http->request('DELETE', "/ads/ads/{$adId}", null, self::scope($workspaceId, $connectionId)); - } - - /** Copy the ad and return the copy's id. Needs the `publish` scope. */ - public function duplicateNetworkAd( - string $adId, - string $workspaceId, - string $connectionId, - ?bool $paused = null, - ): string { - return $this->duplicate("/ads/ads/{$adId}/duplicate", $workspaceId, $connectionId, $paused); - } - /** * Set up to 50 campaigns, ad sets or ads `active` or `paused` in one call. Needs the `publish` scope. * @@ -1005,71 +762,6 @@ public function bulkSetStatus(string $workspaceId, string $connectionId, string return BulkAdStatusResult::listFrom(self::unwrap($this->http->post('/ads/status', $body))); } - /** @return array */ - public function creatives(string $connectionId, string $adAccountId, ?string $workspaceId = null): array - { - $result = self::unwrap($this->http->get('/ads/creatives', [ - 'workspace_id' => $workspaceId, - 'connection_id' => $connectionId, - 'ad_account_id' => $adAccountId, - ])); - - return AdCreative::listFrom(is_array($result) ? ($result['creatives'] ?? []) : []); - } - - /** - * Format is image, video or carousel. A video needs $mediaUrl; a carousel needs 2 to 10 $cards. - * - * @param array>|null $cards `{mediaUrl, destinationUrl?, headline?, description?}` - */ - public function createCreative( - string $workspaceId, - string $connectionId, - string $adAccountId, - string $pageId, - string $name, - string $format, - string $text, - ?string $headline = null, - ?string $destinationUrl = null, - ?string $callToAction = null, - ?string $urlTags = null, - ?string $mediaUrl = null, - ?string $thumbnailMediaUrl = null, - ?array $cards = null, - ): AdCreative { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'adAccountId' => $adAccountId, - 'pageId' => $pageId, - 'name' => $name, - 'format' => $format, - 'text' => $text, - 'headline' => $headline, - 'destinationUrl' => $destinationUrl, - 'callToAction' => $callToAction, - 'urlTags' => $urlTags, - 'mediaUrl' => $mediaUrl, - 'thumbnailMediaUrl' => $thumbnailMediaUrl, - 'cards' => $cards !== null ? array_values($cards) : null, - ]); - - return AdCreative::fromArray(self::unwrap($this->http->post('/ads/creatives', $body))); - } - - public function creative(string $creativeId, string $connectionId, ?string $workspaceId = null): AdCreative - { - return AdCreative::fromArray(self::unwrap( - $this->http->get("/ads/creatives/{$creativeId}", self::scope($workspaceId, $connectionId)), - )); - } - - public function deleteCreative(string $creativeId, string $workspaceId, string $connectionId): void - { - $this->http->request('DELETE', "/ads/creatives/{$creativeId}", null, self::scope($workspaceId, $connectionId)); - } - public function audience(string $audienceId, string $connectionId, ?string $workspaceId = null): Audience { return Audience::fromArray(self::unwrap( @@ -1464,259 +1156,6 @@ public function goals(string $connectionId, ?string $workspaceId = null): array return is_array($result) ? array_values(array_filter($result, 'is_string')) : []; } - // ─── Product catalogs ─────────────────────────────────────────── - - /** Catalogs the connection's business portfolios reach. Read live, never stored. */ - public function catalogs(string $connectionId, ?string $workspaceId = null): ProductCatalogsResult - { - return ProductCatalogsResult::fromArray( - self::unwrap($this->http->get('/ads/catalogs', self::scope($workspaceId, $connectionId))) - ); - } - - /** Created on the connection's business portfolio. Also needs the `publish` scope. */ - public function createCatalog( - string $workspaceId, - string $connectionId, - string $name, - ?string $vertical = null, - ): ProductCatalog { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'name' => $name, - 'vertical' => $vertical, - ]); - - return ProductCatalog::fromArray(self::unwrap($this->http->post('/ads/catalogs', $body))); - } - - public function getCatalog(string $catalogId, string $connectionId, ?string $workspaceId = null): ProductCatalog - { - return ProductCatalog::fromArray( - self::unwrap($this->http->get("/ads/catalogs/{$catalogId}", self::scope($workspaceId, $connectionId))) - ); - } - - /** Also needs the `publish` scope. */ - public function updateCatalog( - string $catalogId, - string $workspaceId, - string $connectionId, - string $name, - ): ProductCatalog { - $body = ['workspaceId' => $workspaceId, 'connectionId' => $connectionId, 'name' => $name]; - - return ProductCatalog::fromArray(self::unwrap($this->http->request( - 'PATCH', - "/ads/catalogs/{$catalogId}", - $body, - self::scope($workspaceId, $connectionId), - ))); - } - - /** Deletes every product, feed and set in it. Also needs the `publish` scope. */ - public function deleteCatalog(string $catalogId, string $workspaceId, string $connectionId): void - { - $this->http->request('DELETE', "/ads/catalogs/{$catalogId}", null, self::scope($workspaceId, $connectionId)); - } - - /** One page of products; pass `nextCursor` back as `$after`. */ - public function catalogProducts( - string $catalogId, - string $connectionId, - ?string $workspaceId = null, - ?string $after = null, - ): CatalogProductsPage { - $query = self::scope($workspaceId, $connectionId) + ['after' => $after]; - - return CatalogProductsPage::fromArray( - self::unwrap($this->http->get("/ads/catalogs/{$catalogId}/products", $query)) - ); - } - - /** - * Up to 500 upserts and deletes in one batch, keyed by your own `retailerId`. - * Also needs the `publish` scope. - * - * @param array> $products - */ - public function writeCatalogProducts( - string $catalogId, - string $workspaceId, - string $connectionId, - array $products, - ): CatalogBatchResult { - $body = [ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'products' => array_values($products), - ]; - - return CatalogBatchResult::fromArray( - self::unwrap($this->http->post("/ads/catalogs/{$catalogId}/products", $body)) - ); - } - - /** @return array */ - public function productFeeds(string $catalogId, string $connectionId, ?string $workspaceId = null): array - { - return ProductFeed::listFrom( - self::unwrap($this->http->get("/ads/catalogs/{$catalogId}/feeds", self::scope($workspaceId, $connectionId))) - ); - } - - /** `$schedule` is HOURLY, DAILY or WEEKLY and needs `$url`. Also needs the `publish` scope. */ - public function createProductFeed( - string $catalogId, - string $workspaceId, - string $connectionId, - string $name, - ?string $url = null, - ?string $schedule = null, - ): ProductFeed { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'name' => $name, - 'url' => $url, - 'schedule' => $schedule, - ]); - - return ProductFeed::fromArray(self::unwrap($this->http->post("/ads/catalogs/{$catalogId}/feeds", $body))); - } - - /** Also needs the `publish` scope. */ - public function deleteProductFeed( - string $catalogId, - string $feedId, - string $workspaceId, - string $connectionId, - ): void { - $this->http->request( - 'DELETE', - "/ads/catalogs/{$catalogId}/feeds/{$feedId}", - null, - self::scope($workspaceId, $connectionId), - ); - } - - /** - * Each run the network made of the feed. - * - * @return array - */ - public function feedUploads( - string $catalogId, - string $feedId, - string $connectionId, - ?string $workspaceId = null, - ): array { - return ProductFeedUpload::listFrom(self::unwrap($this->http->get( - "/ads/catalogs/{$catalogId}/feeds/{$feedId}/uploads", - self::scope($workspaceId, $connectionId), - ))); - } - - /** Fetches the feed now; the id of the run. Also needs the `publish` scope. */ - public function startFeedUpload( - string $catalogId, - string $feedId, - string $workspaceId, - string $connectionId, - ?string $url = null, - ): string { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'url' => $url, - ]); - $result = self::unwrap($this->http->post("/ads/catalogs/{$catalogId}/feeds/{$feedId}/uploads", $body)); - $id = is_array($result) ? ($result['id'] ?? null) : null; - - return is_string($id) ? $id : ''; - } - - /** - * A catalog ad runs from a product set, not the whole catalog. - * - * @return array - */ - public function productSets(string $catalogId, string $connectionId, ?string $workspaceId = null): array - { - return ProductSet::listFrom(self::unwrap($this->http->get( - "/ads/catalogs/{$catalogId}/product-sets", - self::scope($workspaceId, $connectionId), - ))); - } - - /** - * Without a `$filter` the set is the whole catalog. Also needs the `publish` scope. - * - * @param array|null $filter - */ - public function createProductSet( - string $catalogId, - string $workspaceId, - string $connectionId, - string $name, - ?array $filter = null, - ): ProductSet { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'name' => $name, - 'filter' => $filter, - ]); - - return ProductSet::fromArray( - self::unwrap($this->http->post("/ads/catalogs/{$catalogId}/product-sets", $body)) - ); - } - - /** - * Also needs the `publish` scope. - * - * @param array|null $filter - */ - public function updateProductSet( - string $catalogId, - string $setId, - string $workspaceId, - string $connectionId, - string $name, - ?array $filter = null, - ): ProductSet { - $body = self::compact([ - 'workspaceId' => $workspaceId, - 'connectionId' => $connectionId, - 'name' => $name, - 'filter' => $filter, - ]); - - return ProductSet::fromArray(self::unwrap($this->http->request( - 'PATCH', - "/ads/catalogs/{$catalogId}/product-sets/{$setId}", - $body, - self::scope($workspaceId, $connectionId), - ))); - } - - /** Also needs the `publish` scope. */ - public function deleteProductSet( - string $catalogId, - string $setId, - string $workspaceId, - string $connectionId, - ): void { - $this->http->request( - 'DELETE', - "/ads/catalogs/{$catalogId}/product-sets/{$setId}", - null, - self::scope($workspaceId, $connectionId), - ); - } - // ─── Reach and frequency ──────────────────────────────────────── public function reachFrequency( @@ -1796,37 +1235,6 @@ public function cancelReachFrequency( return $this->reachFrequencyAction($predictionId, 'cancel', $workspaceId, $connectionId, $adAccountId); } - // ─── Ad Library ───────────────────────────────────────────────── - - /** - * The public ad archive: ads anyone is running, by keyword or by Page. Read live on - * every call and stored nowhere, so an ad that stops running is simply absent next time. - * - * @param array $countries - * @param array|null $pageIds - */ - public function library( - string $connectionId, - array $countries, - ?string $workspaceId = null, - ?string $q = null, - ?array $pageIds = null, - ?string $activeStatus = null, - ?int $limit = null, - ?string $after = null, - ): AdLibraryPage { - $query = self::scope($workspaceId, $connectionId) + [ - 'countries' => implode(',', $countries), - 'q' => $q, - 'page_ids' => $pageIds !== null ? implode(',', $pageIds) : null, - 'active_status' => $activeStatus, - 'limit' => $limit !== null ? (string) $limit : null, - 'after' => $after, - ]; - - return AdLibraryPage::fromArray(self::unwrap($this->http->get('/ads/library', $query))); - } - // ─── Partnership ads ──────────────────────────────────────────── /** @@ -2213,16 +1621,4 @@ private static function object(array $body): array|\stdClass return $body === [] ? new \stdClass() : $body; } - - private function duplicate(string $path, string $workspaceId, string $connectionId, ?bool $paused): string - { - $result = self::unwrap($this->http->request( - 'POST', - $path, - self::object(['paused' => $paused]), - self::scope($workspaceId, $connectionId), - )); - - return is_array($result) && is_string($result['id'] ?? null) ? $result['id'] : ''; - } } diff --git a/src/Resource/GoogleAdsResource.php b/src/Resource/GoogleAdsResource.php index 91ded0d..1b9a23b 100644 --- a/src/Resource/GoogleAdsResource.php +++ b/src/Resource/GoogleAdsResource.php @@ -5,24 +5,16 @@ namespace Fopost\Sdk\Resource; use Fopost\Sdk\Model\GoogleAdScheduleSlot; -use Fopost\Sdk\Model\GoogleAssetGroup; -use Fopost\Sdk\Model\GoogleAssetsResult; use Fopost\Sdk\Model\GoogleBidStrategy; use Fopost\Sdk\Model\GoogleConversionAction; -use Fopost\Sdk\Model\GoogleKeyword; -use Fopost\Sdk\Model\GoogleKeywordIdea; use Fopost\Sdk\Model\GoogleLocalServicesLead; -use Fopost\Sdk\Model\GoogleOptimizationScore; -use Fopost\Sdk\Model\GoogleRecommendation; -use Fopost\Sdk\Model\GoogleSearchTerm; -use Fopost\Sdk\Model\GoogleSharedSet; /** * $client->ads()->google(): the Google Ads surface no other network has. * - * Campaigns, ad groups, ads, audiences and insights are on the ads resource itself and dispatch by - * connection. What is here — keywords, assets, Performance Max asset groups, Local Services leads, - * conversions and raw GAQL — is Google only, and a connection on another network answers 400. + * Audiences and insights are on the ads resource itself and dispatch by connection. What is here + * (bid strategies, the ad schedule, Local Services leads, conversions and raw GAQL) is Google only, + * and a connection on another network answers 400. * * Every call needs the `ads` scope; anything that changes what a live account serves or bids also * needs `publish`. $customerId is digits only and has to name an account the connection's grant @@ -30,139 +22,6 @@ */ final class GoogleAdsResource extends Resource { - // ── Keywords ── - - /** - * Keywords on the account, or on one ad group. - * - * @return array - */ - public function keywords( - string $connectionId, - string $customerId, - ?string $workspaceId = null, - ?string $adGroupId = null, - ): array { - return GoogleKeyword::listFrom(self::unwrap($this->http->get( - '/ads/google/keywords', - self::params($connectionId, $customerId, $workspaceId, ['ad_group_id' => $adGroupId]), - ))); - } - - /** The new keyword's id. Needs the `publish` scope as well as `ads`. */ - public function createKeyword( - string $workspaceId, - string $connectionId, - string $customerId, - string $adGroupId, - string $text, - string $matchType, - ?int $cpcBidMinor = null, - ): string { - $body = self::scope($workspaceId, $connectionId, $customerId) + self::compact([ - 'adGroupId' => $adGroupId, - 'text' => $text, - 'matchType' => $matchType, - 'cpcBidMinor' => $cpcBidMinor, - ]); - - return self::id($this->http->post('/ads/google/keywords', $body)); - } - - /** $status is `active` or `paused`. Needs the `publish` scope as well as `ads`. */ - public function updateKeyword( - string $keywordId, - string $workspaceId, - string $connectionId, - string $customerId, - ?string $status = null, - ?int $cpcBidMinor = null, - ): string { - $body = self::scope($workspaceId, $connectionId, $customerId) + self::compact([ - 'status' => $status, - 'cpcBidMinor' => $cpcBidMinor, - ]); - - return self::id($this->http->request('PATCH', "/ads/google/keywords/{$keywordId}", $body)); - } - - /** Needs the `publish` scope as well as `ads`. */ - public function deleteKeyword( - string $keywordId, - string $workspaceId, - string $connectionId, - string $customerId, - ): void { - $this->http->request( - 'DELETE', - "/ads/google/keywords/{$keywordId}", - self::scope($workspaceId, $connectionId, $customerId), - ); - } - - /** - * Ideas from seed keywords, a landing page, or both. - * - * @param array|null $seeds - * @param array|null $geoTargetIds - * @return array - */ - public function keywordIdeas( - string $workspaceId, - string $connectionId, - string $customerId, - ?array $seeds = null, - ?string $url = null, - ?string $languageId = null, - ?array $geoTargetIds = null, - ): array { - $body = self::scope($workspaceId, $connectionId, $customerId) + self::compact([ - 'seeds' => $seeds, - 'url' => $url, - 'languageId' => $languageId, - 'geoTargetIds' => $geoTargetIds, - ]); - - return GoogleKeywordIdea::listFrom( - self::unwrap($this->http->post('/ads/google/keyword-ideas', $body)), - ); - } - - /** - * @param array $keywords - * @return array - */ - public function keywordMetrics( - string $workspaceId, - string $connectionId, - string $customerId, - array $keywords, - ): array { - $body = self::scope($workspaceId, $connectionId, $customerId) + ['keywords' => $keywords]; - - return GoogleKeywordIdea::listFrom( - self::unwrap($this->http->post('/ads/google/keyword-metrics', $body)), - ); - } - - /** - * What people actually searched, with the metrics each term earned. - * - * @return array - */ - public function searchTerms( - string $connectionId, - string $customerId, - string $since, - string $until, - ?string $workspaceId = null, - ): array { - return GoogleSearchTerm::listFrom(self::unwrap($this->http->get( - '/ads/google/search-terms', - self::params($connectionId, $customerId, $workspaceId, ['since' => $since, 'until' => $until]), - ))); - } - // ── Bid strategies and ad schedule ── /** @return array */ @@ -230,204 +89,6 @@ public function setAdSchedule( return is_array($result) && is_int($result['slots'] ?? null) ? $result['slots'] : 0; } - // ── Negative keyword lists ── - - /** @return array */ - public function negativeKeywordLists( - string $connectionId, - string $customerId, - ?string $workspaceId = null, - ): array { - return GoogleSharedSet::listFrom(self::unwrap($this->http->get( - '/ads/google/negative-keywords', - self::params($connectionId, $customerId, $workspaceId), - ))); - } - - /** Needs the `publish` scope as well as `ads`. */ - public function createNegativeKeywordList( - string $workspaceId, - string $connectionId, - string $customerId, - string $name, - ): string { - $body = self::scope($workspaceId, $connectionId, $customerId) + ['name' => $name]; - - return self::id($this->http->post('/ads/google/negative-keywords', $body)); - } - - /** - * How many were added. Needs the `publish` scope as well as `ads`. - * - * @param array> $keywords - */ - public function addNegativeKeywords( - string $workspaceId, - string $connectionId, - string $customerId, - string $sharedSetId, - array $keywords, - ): int { - $body = self::scope($workspaceId, $connectionId, $customerId) + [ - 'sharedSetId' => $sharedSetId, - 'keywords' => $keywords, - ]; - $result = self::unwrap($this->http->post('/ads/google/negative-keywords/keywords', $body)); - - return is_array($result) && is_int($result['added'] ?? null) ? $result['added'] : 0; - } - - /** Needs the `publish` scope as well as `ads`. */ - public function attachNegativeKeywordList( - string $workspaceId, - string $connectionId, - string $customerId, - string $sharedSetId, - string $campaignId, - ): void { - $body = self::scope($workspaceId, $connectionId, $customerId) + [ - 'sharedSetId' => $sharedSetId, - 'campaignId' => $campaignId, - ]; - $this->http->post('/ads/google/negative-keywords/attach', $body); - } - - // ── Assets ── - - /** Sitelinks, callouts and snippets, with the links that put each one under an ad. */ - public function assets( - string $connectionId, - string $customerId, - ?string $workspaceId = null, - ): GoogleAssetsResult { - return GoogleAssetsResult::fromArray(self::unwrap($this->http->get( - '/ads/google/assets', - self::params($connectionId, $customerId, $workspaceId), - ))); - } - - /** - * $spec is a sitelink, callout or snippet. Needs the `publish` scope as well as `ads`. - * - * @param array $spec - */ - public function createAsset( - string $workspaceId, - string $connectionId, - string $customerId, - array $spec, - ): string { - $body = self::scope($workspaceId, $connectionId, $customerId) + ['spec' => $spec]; - - return self::id($this->http->post('/ads/google/assets', $body)); - } - - /** Attaches to the account when $campaignId is left out. Needs `publish`. */ - public function attachAsset( - string $workspaceId, - string $connectionId, - string $customerId, - string $assetId, - string $fieldType, - ?string $campaignId = null, - ): void { - $body = self::scope($workspaceId, $connectionId, $customerId) + self::compact([ - 'assetId' => $assetId, - 'fieldType' => $fieldType, - 'campaignId' => $campaignId, - ]); - $this->http->post('/ads/google/assets/attach', $body); - } - - /** - * Removes the links that put the asset under an ad; on Google the asset itself is permanent. - * Needs the `publish` scope as well as `ads`. - */ - public function deleteAsset( - string $assetId, - string $workspaceId, - string $connectionId, - string $customerId, - ): void { - $this->http->request( - 'DELETE', - "/ads/google/assets/{$assetId}", - self::scope($workspaceId, $connectionId, $customerId), - ); - } - - // ── Performance Max asset groups ── - - /** @return array */ - public function assetGroups( - string $connectionId, - string $customerId, - ?string $workspaceId = null, - ?string $campaignId = null, - ): array { - return GoogleAssetGroup::listFrom(self::unwrap($this->http->get( - '/ads/google/asset-groups', - self::params($connectionId, $customerId, $workspaceId, ['campaign_id' => $campaignId]), - ))); - } - - /** - * Starts paused unless $status says otherwise. Needs `publish` as well as `ads`. - * - * @param array $finalUrls - */ - public function createAssetGroup( - string $workspaceId, - string $connectionId, - string $customerId, - string $campaignId, - string $name, - array $finalUrls, - ?string $status = null, - ): string { - $body = self::scope($workspaceId, $connectionId, $customerId) + self::compact([ - 'campaignId' => $campaignId, - 'name' => $name, - 'finalUrls' => $finalUrls, - 'status' => $status, - ]); - - return self::id($this->http->post('/ads/google/asset-groups', $body)); - } - - /** Needs the `publish` scope as well as `ads`. */ - public function updateAssetGroup( - string $assetGroupId, - string $workspaceId, - string $connectionId, - string $customerId, - ?string $name = null, - ?string $status = null, - ): string { - $body = self::scope($workspaceId, $connectionId, $customerId) + self::compact([ - 'name' => $name, - 'status' => $status, - ]); - - return self::id( - $this->http->request('PATCH', "/ads/google/asset-groups/{$assetGroupId}", $body), - ); - } - - /** Needs the `publish` scope as well as `ads`. */ - public function deleteAssetGroup( - string $assetGroupId, - string $workspaceId, - string $connectionId, - string $customerId, - ): void { - $this->http->request( - 'DELETE', - "/ads/google/asset-groups/{$assetGroupId}", - self::scope($workspaceId, $connectionId, $customerId), - ); - } - // ── Local Services leads ── /** @@ -448,75 +109,6 @@ public function localServicesLeads( ))); } - // ── Recommendations ── - - /** - * Google's own read on what the account should change next. - * - * @param array $types narrows to those recommendation types - * @return array - */ - public function recommendations( - string $connectionId, - string $customerId, - array $types = [], - ?string $workspaceId = null, - ): array { - $extra = $types === [] ? [] : ['types' => implode(',', $types)]; - - return GoogleRecommendation::listFrom(self::unwrap($this->http->get( - '/ads/google/recommendations', - self::params($connectionId, $customerId, $workspaceId, $extra), - ))); - } - - /** The account's score and weight, and the score of each live campaign. */ - public function optimizationScore( - string $connectionId, - string $customerId, - ?string $workspaceId = null, - ): GoogleOptimizationScore { - return GoogleOptimizationScore::fromArray(self::unwrap($this->http->get( - '/ads/google/optimization-score', - self::params($connectionId, $customerId, $workspaceId), - ))); - } - - /** - * Applies each one, which changes what the live account serves or bids, and - * reports how many landed. Needs `publish` as well as `ads`. - * - * @param array $ids - */ - public function applyRecommendations( - string $workspaceId, - string $connectionId, - string $customerId, - array $ids, - ): int { - $body = self::scope($workspaceId, $connectionId, $customerId) + ['ids' => array_values($ids)]; - $result = self::unwrap($this->http->post('/ads/google/recommendations/apply', $body)); - - return is_array($result) && is_int($result['applied'] ?? null) ? $result['applied'] : 0; - } - - /** - * Hides each one so Google stops surfacing it. Needs `publish` as well as `ads`. - * - * @param array $ids - */ - public function dismissRecommendations( - string $workspaceId, - string $connectionId, - string $customerId, - array $ids, - ): int { - $body = self::scope($workspaceId, $connectionId, $customerId) + ['ids' => array_values($ids)]; - $result = self::unwrap($this->http->post('/ads/google/recommendations/dismiss', $body)); - - return is_array($result) && is_int($result['dismissed'] ?? null) ? $result['dismissed'] : 0; - } - // ── Conversions ── /** @return array */ diff --git a/tests/AdsDepthTest.php b/tests/AdsDepthTest.php index bf29f08..46d4364 100644 --- a/tests/AdsDepthTest.php +++ b/tests/AdsDepthTest.php @@ -6,84 +6,6 @@ final class AdsDepthTest extends TestCase { - public function testAccountTreeParsesCampaignsAdSetsAndAds(): void - { - $this->transport->push(200, ['data' => [ - 'adAccountId' => 'act_123', - 'currency' => 'USD', - 'workspaceId' => 'w_1', - 'campaigns' => [[ - 'id' => '120', - 'name' => 'Launch', - 'status' => 'PAUSED', - 'objective' => 'OUTCOME_TRAFFIC', - 'budgetMinor' => null, - 'adSets' => [[ - 'id' => '121', - 'name' => 'US adults', - 'campaignId' => '120', - 'status' => 'ACTIVE', - 'budgetMinor' => 2500, - 'budgetType' => 'daily', - 'ads' => [['id' => '122', 'name' => 'Ad A', 'adSetId' => '121', 'status' => 'ACTIVE']], - ]], - ]], - ]]); - - $tree = $this->client()->ads()->accountTree('act_123', 'conn_1', 'w_1'); - - $this->assertSame('GET', $this->transport->last()['method']); - $this->assertSame( - 'https://api.fopost.com/v1/ads/accounts/act_123/tree?workspace_id=w_1&connection_id=conn_1', - $this->transport->last()['url'], - ); - $this->assertSame('USD', $tree->currency); - $this->assertNull($tree->campaigns[0]->budgetMinor); - $this->assertSame(2500, $tree->campaigns[0]->adSets[0]->budgetMinor); - $this->assertSame('121', $tree->campaigns[0]->adSets[0]->ads[0]->adSetId); - } - - public function testCampaignWritesCarryTheConnectionInTheQuery(): void - { - $this->transport->push(201, ['data' => ['id' => '120', 'name' => 'Launch', 'status' => 'PAUSED']]); - $campaign = $this->client()->ads()->createCampaign('w_1', 'conn_1', 'act_123', 'Launch', 'traffic'); - $this->assertSame('https://api.fopost.com/v1/ads/campaigns', $this->transport->last()['url']); - $this->assertSame([ - 'workspaceId' => 'w_1', - 'connectionId' => 'conn_1', - 'adAccountId' => 'act_123', - 'name' => 'Launch', - 'goal' => 'traffic', - ], $this->transport->lastJson()); - $this->assertSame('120', $campaign->id); - - $this->transport->push(200, ['data' => ['id' => '120', 'name' => 'Launch', 'status' => 'ACTIVE']]); - $this->client()->ads()->updateCampaign('120', 'w_1', 'conn_1', status: 'active'); - $this->assertSame('PATCH', $this->transport->last()['method']); - $this->assertSame( - 'https://api.fopost.com/v1/ads/campaigns/120?workspace_id=w_1&connection_id=conn_1', - $this->transport->last()['url'], - ); - $this->assertSame(['status' => 'active'], $this->transport->lastJson()); - - $this->transport->push(201, ['data' => ['id' => '130']]); - $copy = $this->client()->ads()->duplicateCampaign('120', 'w_1', 'conn_1'); - $this->assertSame( - 'https://api.fopost.com/v1/ads/campaigns/120/duplicate?workspace_id=w_1&connection_id=conn_1', - $this->transport->last()['url'], - ); - $this->assertSame('{}', $this->transport->last()['body']); - $this->assertSame('130', $copy); - - $this->transport->push(200, ['message' => 'deleted']); - $this->client()->ads()->deleteNetworkAd('122', 'w_1', 'conn_1'); - $this->assertSame('DELETE', $this->transport->last()['method']); - $this->assertSame( - 'https://api.fopost.com/v1/ads/ads/122?workspace_id=w_1&connection_id=conn_1', - $this->transport->last()['url'], - ); - } - public function testBulkStatusReturnsOneResultPerObject(): void { $this->transport->push(200, ['data' => [ @@ -180,36 +102,8 @@ public function testLeadsFeedPagesByCursor(): void $this->assertNull($next->nextCursor); } - public function testCreativesAudiencesAndLeadPages(): void + public function testAudienceUsersAndLeadPages(): void { - $this->transport->push(200, ['data' => [ - 'creatives' => [['id' => 'cr_1', 'name' => 'Hero', 'format' => 'image', 'urlTags' => 'utm_source=meta']], - 'workspaceId' => 'w_1', - ]]); - $creatives = $this->client()->ads()->creatives('conn_1', 'act_123'); - $this->assertSame( - 'https://api.fopost.com/v1/ads/creatives?connection_id=conn_1&ad_account_id=act_123', - $this->transport->last()['url'], - ); - $this->assertSame('utm_source=meta', $creatives[0]->urlTags); - - $this->transport->push(201, ['data' => ['id' => 'cr_2', 'name' => 'Carousel', 'format' => 'carousel']]); - $this->client()->ads()->createCreative( - workspaceId: 'w_1', - connectionId: 'conn_1', - adAccountId: 'act_123', - pageId: '555', - name: 'Carousel', - format: 'carousel', - text: 'Two looks', - urlTags: 'utm_medium=paid', - cards: [['mediaUrl' => 'https://cdn/a.png'], ['mediaUrl' => 'https://cdn/b.png']], - ); - $body = $this->transport->lastJson(); - $this->assertSame('utm_medium=paid', $body['urlTags']); - $this->assertCount(2, $body['cards']); - $this->assertArrayNotHasKey('mediaUrl', $body); - $this->transport->push(200, ['data' => ['added' => 2]]); $emails = ['a@example.invalid', 'b@example.invalid']; $added = $this->client()->ads()->addAudienceUsers('aud_1', 'w_1', 'conn_1', $emails); diff --git a/tests/AdsTikTokTest.php b/tests/AdsTikTokTest.php index 6be2c3b..95e0ca2 100644 --- a/tests/AdsTikTokTest.php +++ b/tests/AdsTikTokTest.php @@ -30,7 +30,7 @@ public function testIdentitiesAndSparkPostsReadTheRightPaths(): void $this->assertStringContainsString('identity_id=idt_1', $this->transport->last()['url']); } - public function testSparkPostIdAndSmartPlusTravelInTheBody(): void + public function testSparkPostIdTravelsInTheBody(): void { $this->transport->push(201, ['data' => [ 'id' => 'ad_1', @@ -53,10 +53,6 @@ public function testSparkPostIdAndSmartPlusTravelInTheBody(): void sparkPostId: 'item_99', ); $this->assertSame('item_99', $this->transport->lastJson()['sparkPostId']); - - $this->transport->push(201, ['data' => ['id' => 'c1', 'name' => 'Smart', 'status' => 'PAUSED']]); - $this->client()->ads()->createCampaign('w_1', 'conn_1', '7011', 'Smart', 'traffic', smartPlus: true); - $this->assertTrue($this->transport->lastJson()['smartPlus']); } public function testConversionsReportWhatTheNetworkAccepted(): void diff --git a/tests/GoogleAdsTest.php b/tests/GoogleAdsTest.php index 8c2f273..3e48a97 100644 --- a/tests/GoogleAdsTest.php +++ b/tests/GoogleAdsTest.php @@ -6,69 +6,6 @@ final class GoogleAdsTest extends TestCase { - public function testKeywordsNameTheConnectionAndTheCustomer(): void - { - $this->transport->push(200, ['data' => [[ - 'id' => '1234567890~keyword~77~99', - 'adGroupId' => '1234567890~adGroup~77', - 'text' => 'running shoes', - 'matchType' => 'EXACT', - 'status' => 'ENABLED', - 'cpcBidMinor' => 180, - 'negative' => false, - ]]]); - - $keywords = $this->client()->ads()->google()->keywords( - 'conn_1', - '1234567890', - 'ws_1', - '1234567890~adGroup~77', - ); - - $this->assertCount(1, $keywords); - $this->assertSame('running shoes', $keywords[0]->text); - $this->assertSame(180, $keywords[0]->cpcBidMinor); - - $url = $this->transport->last()['url']; - $this->assertStringContainsString('/ads/google/keywords', $url); - $this->assertStringContainsString('connection_id=conn_1', $url); - $this->assertStringContainsString('customer_id=1234567890', $url); - } - - public function testCreateKeywordSendsACamelCaseBody(): void - { - $this->transport->push(201, ['data' => ['id' => '1234567890~keyword~77~99']]); - - $id = $this->client()->ads()->google()->createKeyword( - 'ws_1', - 'conn_1', - '1234567890', - '1234567890~adGroup~77', - 'running shoes', - 'EXACT', - ); - - $this->assertSame('1234567890~keyword~77~99', $id); - $body = $this->transport->lastJson(); - $this->assertSame('1234567890~adGroup~77', $body['adGroupId']); - $this->assertSame('EXACT', $body['matchType']); - $this->assertSame('1234567890', $body['customerId']); - } - - public function testDeleteCarriesTheScopeInTheBody(): void - { - $this->transport->push(204, null); - - $this->client()->ads()->google()->deleteAsset('1234567890~asset~4321', 'ws_1', 'conn_1', '1234567890'); - - $this->assertSame('DELETE', $this->transport->last()['method']); - $this->assertSame([ - 'workspaceId' => 'ws_1', - 'connectionId' => 'conn_1', - 'customerId' => '1234567890', - ], $this->transport->lastJson()); - } - public function testAdScheduleIsReplacedWithPut(): void { $this->transport->push(200, ['data' => ['slots' => 2]]); @@ -99,42 +36,6 @@ public function testQueryReturnsRowsAsGoogleSendsThem(): void $this->assertStringContainsString('/ads/insights/query', $this->transport->last()['url']); } - public function testRecommendationsJoinTheTypesFilter(): void - { - $this->transport->push(200, ['data' => [[ - 'id' => 'customers/1234567890/recommendations/ABC~1', - 'type' => 'KEYWORD', - 'campaignId' => '1234567890~campaign~55', - 'dismissed' => false, - 'impact' => ['baseClicks' => 10, 'potentialClicks' => 25], - ]]]); - - $rows = $this->client()->ads()->google()->recommendations( - 'conn_1', - '1234567890', - ['KEYWORD', 'TARGET_CPA_OPT_IN'], - ); - - $this->assertSame('KEYWORD', $rows[0]->type); - $this->assertSame(25.0, $rows[0]->impact?->potentialClicks); - $this->assertStringContainsString('types=KEYWORD%2CTARGET_CPA_OPT_IN', $this->transport->last()['url']); - } - - public function testApplyRecommendationsSendsTheIds(): void - { - $this->transport->push(200, ['data' => ['applied' => 1]]); - - $applied = $this->client()->ads()->google()->applyRecommendations( - 'ws_1', - 'conn_1', - '1234567890', - ['customers/1234567890/recommendations/ABC~1'], - ); - - $this->assertSame(1, $applied); - $this->assertStringContainsString('/ads/google/recommendations/apply', $this->transport->last()['url']); - } - public function testAuthorizeGoogleHasItsOwnRoute(): void { $this->transport->push(200, ['data' => ['url' => 'https://accounts.google.com/o/x']]);