I want to get reach estimate based on criteria like location, gender, age,
keyword... currently I have taken reach from location, but reach from age
and Gender is not possible. Can you guys help me out. Thanks a lot.
Here is my code:
$adGroupResourceName = ResourceNames::forAdGroup($customerId, $adGroupId);
$keywordText = 'mars cruise';
$campaignId = '17688751344';
$locationId = 21167;
// Creates a positive ad group criterion for gender.
$genderAdGroupCriterion = new AdGroupCriterion([
'ad_group' => $adGroupResourceName,
// Targets male.
'gender' => new GenderInfo(['type' => GenderType::UNDETERMINED])
]);
// Creates a negative ad group criterion for age range.
$ageRangeNegativeAdGroupCriterion = new AdGroupCriterion([
'ad_group' => $adGroupResourceName,
// Makes this ad group criterion negative.
'negative' => true,
// Targets the age range of 18 to 24.
'age_range' => new AgeRangeInfo(['type' =>
AgeRangeType::AGE_RANGE_UNDETERMINED])
]);
// Creates ad group criterion operations for both ad group criteria.
$operations = [
new AdGroupCriterionOperation(['create' =>
$genderAdGroupCriterion]),
new AdGroupCriterionOperation(['create' =>
$ageRangeNegativeAdGroupCriterion])
];
// Issues a mutate request to add the ad group criteria and print
out some information.
$adGroupCriterionServiceClient =
$googleAdsClient->getAdGroupCriterionServiceClient();
$response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
$customerId,
$operations
);
printf(
"Added %d demographic ad group criteria:%s <br>",
$response->getResults()->count(),
PHP_EOL
);
foreach ($response->getResults() as $addedAdGroupCriterion) {
/** @var AdGroupCriterion $addedAdGroupCriterion */
// dd($addedAdGroupCriterion);
print $addedAdGroupCriterion->getResourceName() . PHP_EOL;
}
$googleAdsServiceClient =
$googleAdsClient->getGoogleAdsServiceClient();
// Creates a query that retrieves the targeting settings from a
given ad group.
$query = "SELECT ad_group_criterion.age_range.type, " .
"ad_group_criterion.gender.type, " .
"ad_group_criterion.keyword.text " .
"FROM ad_group_criterion " .
"WHERE " .
"ad_group_criterion.resource_name = '" .
$response->getResults()[0]->getResourceName() . "'";
// Issues a search request.
$stream = $googleAdsServiceClient->searchStream($customerId,
$query);
$paged = $googleAdsServiceClient->search($customerId, $query);
// $campaignBudget = self::createCampaignBudget($adWordsServices,
$adWordsSession);
$results = [];
foreach($stream->iterateAllElements() as $googleAdsRow){
$results[] =
json_decode($googleAdsRow->serializeToJsonString(), true);
}
dd($results);
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/ff1a29ca-b022-418a-8148-39ed64ebe71en%40googlegroups.com.