/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to which ad groups are /// added.</param> public void Run(AdWordsUser user, long campaignId) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201710.AdGroupService)) { List <AdGroupOperation> operations = new List <AdGroupOperation>(); for (int i = 0; i < NUM_ITEMS; i++) { // Create the ad group. AdGroup adGroup = new AdGroup(); adGroup.name = string.Format("Earth to Mars Cruises #{0}", ExampleUtilities.GetRandomString()); adGroup.status = AdGroupStatus.ENABLED; adGroup.campaignId = campaignId; // Set the ad group bids. BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); CpcBid cpcBid = new CpcBid(); cpcBid.bid = new Money(); cpcBid.bid.microAmount = 10000000; biddingConfig.bids = new Bids[] { cpcBid }; adGroup.biddingStrategyConfiguration = biddingConfig; // Optional: Set targeting restrictions. // Depending on the criterionTypeGroup value, most TargetingSettingDetail // only affect Display campaigns. However, the USER_INTEREST_AND_LIST value // works for RLSA campaigns - Search campaigns targeting using a // remarketing list. TargetingSetting targetingSetting = new TargetingSetting(); // Restricting to serve ads that match your ad group placements. // This is equivalent to choosing "Target and bid" in the UI. TargetingSettingDetail placementDetail = new TargetingSettingDetail(); placementDetail.criterionTypeGroup = CriterionTypeGroup.PLACEMENT; placementDetail.targetAll = false; // Using your ad group verticals only for bidding. This is equivalent // to choosing "Bid only" in the UI. TargetingSettingDetail verticalDetail = new TargetingSettingDetail(); verticalDetail.criterionTypeGroup = CriterionTypeGroup.VERTICAL; verticalDetail.targetAll = true; targetingSetting.details = new TargetingSettingDetail[] { placementDetail, verticalDetail }; adGroup.settings = new Setting[] { targetingSetting }; // Set the rotation mode. AdGroupAdRotationMode rotationMode = new AdGroupAdRotationMode(); rotationMode.adRotationMode = AdRotationMode.OPTIMIZE; adGroup.adGroupAdRotationMode = rotationMode; // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.@operator = Operator.ADD; operation.operand = adGroup; operations.Add(operation); } try { // Create the ad group. AdGroupReturnValue retVal = adGroupService.mutate(operations.ToArray()); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { foreach (AdGroup newAdGroup in retVal.value) { Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.", newAdGroup.id, newAdGroup.name); } } else { Console.WriteLine("No ad groups were created."); } } catch (Exception e) { throw new System.ApplicationException("Failed to create ad groups.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to which ad groups are /// added.</param> public void Run(AdWordsUser user, long campaignId) { // Get the AdGroupService. AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201402.AdGroupService); List <AdGroupOperation> operations = new List <AdGroupOperation>(); for (int i = 0; i < NUM_ITEMS; i++) { // Create the ad group. AdGroup adGroup = new AdGroup(); adGroup.name = string.Format("Earth to Mars Cruises #{0}", ExampleUtilities.GetRandomString()); adGroup.status = AdGroupStatus.ENABLED; adGroup.campaignId = campaignId; // Set the ad group bids. BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); CpmBid cpmBid = new CpmBid(); cpmBid.bid = new Money(); cpmBid.bid.microAmount = 10000000; biddingConfig.bids = new Bids[] { cpmBid }; adGroup.biddingStrategyConfiguration = biddingConfig; // Optional: Set targeting restrictions. // These setting only affect serving for the Display Network. TargetingSetting targetingSetting = new TargetingSetting(); TargetingSettingDetail placementDetail = new TargetingSettingDetail(); placementDetail.criterionTypeGroup = CriterionTypeGroup.PLACEMENT; placementDetail.targetAll = true; TargetingSettingDetail verticalDetail = new TargetingSettingDetail(); verticalDetail.criterionTypeGroup = CriterionTypeGroup.VERTICAL; verticalDetail.targetAll = false; targetingSetting.details = new TargetingSettingDetail[] { placementDetail, verticalDetail }; adGroup.settings = new Setting[] { targetingSetting }; // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.@operator = Operator.ADD; operation.operand = adGroup; operations.Add(operation); } try { // Create the ad group. AdGroupReturnValue retVal = adGroupService.mutate(operations.ToArray()); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { foreach (AdGroup newAdGroup in retVal.value) { Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.", newAdGroup.id, newAdGroup.name); } } else { Console.WriteLine("No ad groups were created."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to create ad groups.", ex); } }
public static AdGroupReturnValue CreateAdGroup(AdWordsUser user, AdGroupLo adGroupLo) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201710.AdGroupService)) { List <AdGroupOperation> operations = new List <AdGroupOperation>(); // Create the ad group. AdGroup adGroup = new AdGroup(); adGroup.name = adGroupLo.Name; adGroup.status = AdGroupStatus.PAUSED; adGroup.campaignId = adGroupLo.CampaignId; // Set the ad group bids. BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); CpcBid cpcBid = new CpcBid(); cpcBid.bid = new Money(); cpcBid.bid.microAmount = 10000000; biddingConfig.bids = new Bids[] { cpcBid }; adGroup.biddingStrategyConfiguration = biddingConfig; // Optional: Set targeting restrictions. // Depending on the criterionTypeGroup value, most TargetingSettingDetail // only affect Display campaigns. However, the USER_INTEREST_AND_LIST value // works for RLSA campaigns - Search campaigns targeting using a // remarketing list. TargetingSetting targetingSetting = new TargetingSetting(); // Restricting to serve ads that match your ad group placements. // This is equivalent to choosing "Target and bid" in the UI. TargetingSettingDetail placementDetail = new TargetingSettingDetail(); placementDetail.criterionTypeGroup = CriterionTypeGroup.PLACEMENT; placementDetail.targetAll = false; // Using your ad group verticals only for bidding. This is equivalent // to choosing "Bid only" in the UI. TargetingSettingDetail verticalDetail = new TargetingSettingDetail(); verticalDetail.criterionTypeGroup = CriterionTypeGroup.VERTICAL; verticalDetail.targetAll = true; targetingSetting.details = new TargetingSettingDetail[] { placementDetail, verticalDetail }; adGroup.settings = new Setting[] { targetingSetting }; // Set the rotation mode. AdGroupAdRotationMode rotationMode = new AdGroupAdRotationMode(); rotationMode.adRotationMode = AdRotationMode.OPTIMIZE; adGroup.adGroupAdRotationMode = rotationMode; // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.@operator = Operator.ADD; operation.operand = adGroup; operations.Add(operation); AdGroupReturnValue returnDGroup; try { // Create the ad group. returnDGroup = adGroupService.mutate(operations.ToArray()); } catch (Exception e) { throw new System.ApplicationException("Failed to create ad group.", e); } return(returnDGroup); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to which ad groups are /// added.</param> public void Run(AdWordsUser user, long campaignId) { // Get the AdGroupService. AdGroupService adGroupService = (AdGroupService) user.GetService(AdWordsService.v201509.AdGroupService); List<AdGroupOperation> operations = new List<AdGroupOperation>(); for (int i = 0; i < NUM_ITEMS; i++) { // Create the ad group. AdGroup adGroup = new AdGroup(); adGroup.name = string.Format("Earth to Mars Cruises #{0}", ExampleUtilities.GetRandomString()); adGroup.status = AdGroupStatus.ENABLED; adGroup.campaignId = campaignId; // Set the ad group bids. BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); CpcBid cpcBid = new CpcBid(); cpcBid.bid = new Money(); cpcBid.bid.microAmount = 10000000; biddingConfig.bids = new Bids[] {cpcBid}; adGroup.biddingStrategyConfiguration = biddingConfig; // Optional: Set targeting restrictions. // Depending on the criterionTypeGroup value, most TargetingSettingDetail // only affect Display campaigns. However, the USER_INTEREST_AND_LIST value // works for RLSA campaigns - Search campaigns targeting using a // remarketing list. TargetingSetting targetingSetting = new TargetingSetting(); // Restricting to serve ads that match your ad group placements. // This is equivalent to choosing "Target and bid" in the UI. TargetingSettingDetail placementDetail = new TargetingSettingDetail(); placementDetail.criterionTypeGroup = CriterionTypeGroup.PLACEMENT; placementDetail.targetAll = false; // Using your ad group verticals only for bidding. This is equivalent // to choosing "Bid only" in the UI. TargetingSettingDetail verticalDetail = new TargetingSettingDetail(); verticalDetail.criterionTypeGroup = CriterionTypeGroup.VERTICAL; verticalDetail.targetAll = true; targetingSetting.details = new TargetingSettingDetail[] {placementDetail, verticalDetail}; adGroup.settings = new Setting[] {targetingSetting}; // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.@operator = Operator.ADD; operation.operand = adGroup; operations.Add(operation); } try { // Create the ad group. AdGroupReturnValue retVal = adGroupService.mutate(operations.ToArray()); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { foreach (AdGroup newAdGroup in retVal.value) { Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.", newAdGroup.id, newAdGroup.name); } } else { Console.WriteLine("No ad groups were created."); } } catch (Exception e) { throw new System.ApplicationException("Failed to create ad groups.", e); } }