If name is not present, a default name of the form
"Ad Group #n" is used.
If the parent campaign uses CPC bidding, then only
keywordContentMaxCpc, keywordMaxCpc, and siteMaxCpc can be set.
Similarly, if the parent campaign uses CPM bidding, then only
siteMaxCpm can be set.
The ID field is ignored; ID is set by AdGroupService.
// Create new ad group structure.
int campaignId = Integer.parseInt("INSERT_CAMPAIGN_ID_HERE");
AdGroup adGroup = new AdGroup();
adGroup.setName("Sample Ad Group");
adGroup.setKeywordMaxCpc(new Long(100000));
// Add ad group.
adGroup = service.addAdGroup(campaignId, adGroup);
// Create new ad group structure.
int campaignId = int.Parse("INSERT_CAMPAIGN_ID_HERE");
AdGroup adGroup = new AdGroup();
adGroup.name = "Sample Ad Group";
adGroup.keywordMaxCpc = 100000L;
adGroup.keywordMaxCpcSpecified = true;
// Add ad group.
adGroup = service.addAdGroup(campaignId, adGroup);
<!-- Creates a new ad group given an existing campaign. -->
<addAdGroup>
<campaignID>INSERT_CAMPAIGN_ID_HERE</campaignID>
<newData>
<keywordMaxCpc>100000</keywordMaxCpc>
<name>Sample Ad Group</name>
<status>Enabled</status>
</newData>
</addAdGroup>
Array of AdGroup data objects, each representing an ad group.
The returned objects will be in the same order as their IDs in the
input array.
getAdGroupStats
Get statistics for a list of ad groups in a campaign. See
StatsRecord
for details about the statistics returned. The time granularity is one day,
and is always with respect to the account's local timezone.
Parameters
Parameter name
Parameter type
Parameter description
campaignId
int
The campaign in which to find the ad groups
adGroupIds
long[]
The ad groups whose statistics are being queried
startDay
date
The starting day of the period for which statistics are
to be collected (xsd:date).
endDay
date
The ending day of the period for which statistics are to be
collected, inclusive (xsd:date).
an array of
StatsRecords
containing information about the activity on the ad groups.
The order of StatsRecord objects returned may be different from
the order in which the IDs were requested.
getAllAdGroups
Returns all information about the ad groups associated with a campaign.
Parameters
Parameter name
Parameter type
Parameter description
campaignID
int
ID of the campaign whose ad groups will be retrieved.
// Get all campaigns.
Campaign[] campaigns = campaignService.getAllAdWordsCampaigns(0);
int count = 0;
if (campaigns != null) {
for (Campaign campaign : campaigns) {
// Get all ad groups.
AdGroup[] adGroups = adGroupService.getAllAdGroups(campaign.getId());
if (adGroups != null) {
for (AdGroup adGroup : adGroups) {
// Get all criteria.
Criterion[] criteria =
criterionService.getAllCriteria(adGroup.getId());
// Get all campaigns.
Campaign[] campaigns = campaignService.getAllAdWordsCampaigns(0);
int count = 0;
if (campaigns != null) {
for (int i = 0; i < campaigns.Length; i++) {
// Get all ad groups.
AdGroup[] adGroups = adGroupService.getAllAdGroups(campaigns[i].id);
if (adGroups != null) {
for (int j = 0; j < adGroups.Length; j++) {
// Get all criteria.
Criterion[] criteria =
criterionService.getAllCriteria(adGroups[j].id);
# Get all campaigns.
my $dummy = SOAP::Data->name('dummy' => 0);
my $response = $campaign_service->call('getAllAdWordsCampaigns' => $dummy,
@headers);
my @campaigns = ($response->result(), $response->paramsout());
my $count = 0;
foreach my $campaign (@campaigns) {
# Get all ad groups.
my $campaign_id = SOAP::Data->name('campaignID' => $campaign->{'id'});
$response = $ad_group_service->call('getAllAdGroups' => $campaign_id,
@headers);
my @ad_groups = ($response->result(), $response->paramsout());
for my $ad_group (@ad_groups) {
# Get all criteria.
my $ad_group_id = SOAP::Data->name('adGroupId' => $ad_group->{'id'});
$response = $criterion_service->call('getAllCriteria' => $ad_group_id,
@headers);
my @criteria = ($response->result(), $response->paramsout());
# Get all campaigns.
campaigns = campaign_service.getAllAdWordsCampaigns(0)
# Convert to a list if we get back a single object.
if len(campaigns) > 0 and not isinstance(campaigns, list):
campaigns = [campaigns]
count = 0
for campaign in campaigns:
# Get all ad groups.
ad_groups = ad_group_service.getAllAdGroups(int(campaign['id']))
# Convert to a list if we get back a single object.
if len(ad_groups) > 0 and not isinstance(ad_groups, list):
ad_groups = [ad_groups]
for ad_group in ad_groups:
# Get all criteria.
criteria = criterion_service.getAllCriteria(
SOAPpy.Types.untypedType(str(ad_group['id'])))
# Get all campaigns.
campaigns = campaign_service.getAllAdWordsCampaigns(:dummy => 0
).getAllAdWordsCampaignsReturn
# Convert to a list if we get back a single object.
if ! campaigns.respond_to?('each')
campaigns = [campaigns]
end
count = 0
campaigns.each do |campaign|
# Get all ad groups.
ad_groups = ad_group_service.getAllAdGroups(:campaignID => campaign['id'])
if ad_groups.respond_to?('getAllAdGroupsReturn')
ad_groups = ad_groups.getAllAdGroupsReturn
end
# Convert to a list if we get back a single object.
if ! ad_groups.respond_to?('each')
ad_groups = [ad_groups]
end
ad_groups.each do |ad_group|
# Get all criteria.
criteria = criterion_service.getAllCriteria(:adGroupId => ad_group['id'])
if criteria.respond_to?('getAllCriteriaReturn')
criteria = criteria.getAllCriteriaReturn
# Get all campaigns.
$request_xml =
'<getAllAdWordsCampaigns><dummy>0</dummy></getAllAdWordsCampaigns>';
$campaigns = $campaign_service->call('getAllAdWordsCampaigns', $request_xml);
$campaigns = $campaigns['getAllAdWordsCampaignsReturn'];
if ($debug) show_xml($campaign_service);
if ($campaign_service->fault) show_fault($campaign_service);
# Convert to a list if we get back a single object.
if (!$campaigns[0]) {
$campaigns = array($campaigns);
}
$count = 0;
for ($i = 0; $i < count($campaigns); $i++) {
if (!$campaigns[$i]) {
continue;
}
# Get all ad groups.
$request_xml =
'<getAllAdGroups>' .
'<campaignId>' . $campaigns[$i]['id'] . '</campaignId>' .
'</getAllAdGroups>';
$ad_groups = $ad_group_service->call('getAllAdGroups', $request_xml);
$ad_groups = $ad_groups['getAllAdGroupsReturn'];
if ($debug) show_xml($ad_group_service);
if ($ad_group_service->fault) show_fault($ad_group_service);
# Convert to a list if we get back a single object.
if (!$ad_groups[0]) {
$ad_groups = array($ad_groups);
}
for ($j = 0; $j < count($ad_groups); $j++) {
if (!$ad_groups[$j]) {
continue;
}
# Get all criteria.
$request_xml =
'<getAllCriteria>' .
'<adGroupId>' . $ad_groups[$j]['id'] . '</adGroupId>' .
'</getAllCriteria>';
$criteria = $criterion_service->call('getAllCriteria', $request_xml);
$criteria = $criteria['getAllCriteriaReturn'];
<!-- Retrieves info about all ad groups given an existing campaign. -->
<getAllAdGroups>
<campaignID>INSERT_CAMPAIGN_ID_HERE</campaignID>
</getAllAdGroups>
Data to update.
The ad group whose ID matches changedData.id will be updated
with the values specified in changedData. name,
status, and the bid-related fields are mutable;
id is immutable. Omitted fields will be left
unchanged.