You're going to need to add a negative placement criterion. It's basically
the same as adding a negative keyword.
Here is basically what we did, hope that helps:
<?php
require 'vendor/autoload.php';
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSession;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201705\cm\CampaignCriterion;
use Google\AdsApi\AdWords\v201705\cm\CampaignCriterionOperation;
use Google\AdsApi\AdWords\v201705\cm\CampaignCriterionService;
use Google\AdsApi\AdWords\v201705\cm\ConstantOperand;
use Google\AdsApi\AdWords\v201705\cm\ConstantOperandConstantType;
use Google\AdsApi\AdWords\v201705\cm\ConstantOperandUnit;
use Google\AdsApi\AdWords\v201705\cm\FunctionOperator;
use Google\AdsApi\AdWords\v201705\cm\Placement;
use Google\AdsApi\AdWords\v201705\cm\PlacementMatchType;
use Google\AdsApi\AdWords\v201705\cm\Location;
use Google\AdsApi\AdWords\v201705\cm\LocationExtensionOperand;
use Google\AdsApi\AdWords\v201705\cm\LocationGroups;
use Google\AdsApi\AdWords\v201705\cm\Language;
use Google\AdsApi\AdWords\v201705\cm\MatchingFunction;
use Google\AdsApi\AdWords\v201705\cm\NegativeCampaignCriterion;
use Google\AdsApi\AdWords\v201705\cm\Operator;
use Google\AdsApi\Common\OAuth2TokenBuilder;
/**
* This example adds various types of targeting criteria to a campaign.
* To get campaigns, run BasicOperations/GetCampaigns.php.
*/
class AddCampaignTargetingCrtieria {
const CAMPAIGN_ID = '869044770';
public static function runExample(AdWordsServices $adWordsServices,
AdWordsSession $session, $campaignId) {
$campaignCriterionService =
$adWordsServices->get($session, CampaignCriterionService::class);
$campaignCriteria = [];
$operations = [];
foreach ($campaignCriteria as $campaignCriterion) {
$operation = new CampaignCriterionOperation();
$operation->setOperator(Operator::ADD);
$operation->setOperand($campaignCriterion);
$operations[] = $operation;
}
// Add a negative campaign criterion.
$negativePlacement = new Placement();
$negativePlacement->setUrl('lovebscott.com');
//$negativePlacement->setCriterionType(PlacementMatchType::BROAD);
$negativeCriterion = new NegativeCampaignCriterion();
$negativeCriterion->setCampaignId($campaignId);
$negativeCriterion->setCriterion($negativePlacement);
$operation = new CampaignCriterionOperation();
$operation->setOperator(Operator::ADD);
$operation->setOperand($negativeCriterion);
$operations[] = $operation;
$result = $campaignCriterionService->mutate($operations);
// Print out some information about added campaign criteria.
foreach ($result->getValue() as $campaignCriterion) {
printf(
"Campaign targeting criterion with ID %d and type '%s' was
added.\n",
$campaignCriterion->getCriterion()->getId(),
$campaignCriterion->getCriterion()->getType());
}
}
public static function main() {
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile()
->build();
// Construct an API session configured from a properties file and the
OAuth2
// credentials above.
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
self::runExample(
new AdWordsServices(), $session, intval(self::CAMPAIGN_ID));
}
}
AddCampaignTargetingCrtieria::main();
On Saturday, August 5, 2017 at 5:35:02 AM UTC+8, Maferyt Letakol wrote:
>
> Hi everyone,
>
> Actually I'm setting some BiddableAdGroupCriterion with userStatus =
> 'PAUSED', but I want "placements" to be "excluded".
> ;
> My code :
> private function createAdGroupCriterionOperation(array $criterion)
> {
> $adGroupCriterion = new \BiddableAdGroupCriterion();
> $adGroupCriterion->adGroupId = $criterion['adGroupId'];
> $adGroupCriterion->criterion = new \Criterion($criterion['id']);
> $operator = 'SET';
>
> if ('pause' == $criterion['type']) {
> $adGroupCriterion->userStatus = 'PAUSED';
>
> if ($criterion['criterionType'] == "placement") {
> $adGroupCriterion = new \NegativeAdGroupCriterion();
> $adGroupCriterion->adGroupId = $criterion['adGroupId'];
> $adGroupCriterion->criterion = new
> \Criterion($criterion['id']);
> $operator = 'ADD';
> }
> }
>
> // Create operation.
> $operation = new \AdGroupCriterionOperation();
> $operation->operand = $adGroupCriterion;
> $operation->operator = $operator;
>
> return $operation;
> }
>
> But this is not workind, it does anything :/
>
> I've checked docs & examples but can't figure out what to do.
>
> I wish there would be an "EXCLUDED" status...
>
>
> Thanks !
>
>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/c754b1de-0be3-46b6-8ce9-5bb7d36cb09a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.