/// <summary> /// Creates the ad group. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="campaignId">The campaign ID.</param> /// <returns>The newly created ad group instance.</returns> private static gagvr::AdGroup CreateAdGroup(GoogleAdsClient client, long customerId, long campaignId) { // Get the AdGroupService. gagvs::AdGroupServiceClient adGroupService = client.GetService( Services.V10.AdGroupService); // Create the ad group. gagvr::AdGroup adGroup = new gagvr::AdGroup() { Name = $"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}", Status = gag__AdGroupStatus.Enabled, Campaign = gagver::ResourceNames.Campaign(customerId, campaignId), // Set the ad group bids. CpcBidMicros = 10000000, // Optional: Set the rotation mode. AdRotationMode = gag__AdGroupAdRotationMode.Optimize }; // Create the operation. gagvs::AdGroupOperation operation = new gagvs::AdGroupOperation() { Create = adGroup }; // Create the ad groups. gagvs::MutateAdGroupsResponse response = adGroupService.MutateAdGroups( customerId.ToString(), new gagvs::AdGroupOperation[] { operation }); // Retrieve the newly created ad group. string newResourceName = response.Results.First().ResourceName; gagvr::AdGroup newAdGroup = GetAdGroup(client, customerId, newResourceName); // Display the results. Console.WriteLine($"Ad group with ID={newAdGroup.Id} and name=" + $"'{newAdGroup.Name}' was created."); // Return the newly created ad group. return(newAdGroup); }