Last active
August 29, 2015 14:04
-
-
Save jamesmills/af9206f88b1e0880b281 to your computer and use it in GitHub Desktop.
This will associate a given FeedItem with an AdGroup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
protected function createCallAdGroupFeed(AdWordsUser $user, $feed, $feed_item, $adgroup) | |
{ | |
// Get the CampaignFeedService, which loads the required classes. | |
$adGroupFeedService = $user->GetService('AdGroupFeedService'); | |
$feedFunctionRequestContextOperand = new RequestContextOperand(); | |
$feedFunctionRequestContextOperand->contextType = 'FEED_ITEM_ID'; | |
$feedItemFunction = new FeedFunction(); | |
$feedItemFunction->lhsOperand = array($feedFunctionRequestContextOperand); | |
$feedItemFunction->operator = 'IN'; | |
$constantOperand = new ConstantOperand(); | |
$constantOperand->longValue = $feed_item->feedItemId; | |
$constantOperand->type = 'LONG'; | |
$operands[] = $constantOperand; | |
$feedItemFunction->rhsOperand = $operands; | |
# Optional: to target to a platform, define a function and 'AND' it with the feed item ID link: | |
$platformRequestContextOperand = new RequestContextOperand(); | |
$platformRequestContextOperand->contextType = 'DEVICE_PLATFORM'; | |
$platformOperand = new ConstantOperand(); | |
$platformOperand->type = 'STRING'; | |
$platformOperand->stringValue = 'Mobile'; | |
$platformFunction = new FeedFunction(); | |
$platformFunction->operator = 'EQUALS'; | |
$platformFunction->lhsOperand = array($platformRequestContextOperand); | |
$platformFunction->rhsOperand = array($platformOperand); | |
$feedItemFunctionOperand = new FunctionOperand(); | |
$feedItemFunctionOperand->value = $feedItemFunction; | |
$platformFunctionOperand = new FunctionOperand(); | |
$platformFunctionOperand->value = $platformFunction; | |
$combinedFunction = new FeedFunction(); | |
$combinedFunction->operator = 'AND'; | |
$combinedFunction->lhsOperand = array($feedItemFunctionOperand, $platformFunctionOperand); | |
$adGroupFeed = new AdGroupFeed(); | |
$adGroupFeed->feedId = $feed->id; | |
$adGroupFeed->adGroupId = $adgroup->id; | |
$adGroupFeed->matchingFunction = $combinedFunction; | |
$adGroupFeed->placeholderTypes = array(PLACEHOLDER_CALL); | |
$operation = new AdGroupFeedOperation(); | |
$operation->operand = $adGroupFeed; | |
$operation->operator = 'ADD'; | |
$result = $adGroupFeedService->mutate($operation); | |
return $result->value[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment