/// <summary> /// Creates the ad group in a Shopping campaign. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">The campaign ID.</param> /// <returns>The ad group.</returns> private static AdGroup CreateAdGroup(AdWordsUser user, long campaignId) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201809.AdGroupService)) { // Create ad group. AdGroup adGroup = new AdGroup { campaignId = campaignId, name = "Ad Group #" + ExampleUtilities.GetRandomString() }; // Create operation. AdGroupOperation operation = new AdGroupOperation { operand = adGroup, @operator = Operator.ADD }; // Make the mutate request. AdGroupReturnValue retval = adGroupService.mutate(new AdGroupOperation[] { operation }); return(retval.value[0]); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="budgetId">The budget id.</param> /// <param name="merchantId">The Merchant Center account id.</param> public void Run(AdWordsUser user, long budgetId, long merchantId) { // Get the required services. CampaignService campaignService = (CampaignService)user.GetService( AdWordsService.v201506.CampaignService); AdGroupService adGroupService = (AdGroupService)user.GetService( AdWordsService.v201506.AdGroupService); AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService( AdWordsService.v201506.AdGroupAdService); try { Campaign campaign = CreateCampaign(budgetId, merchantId, campaignService); Console.WriteLine("Campaign with name '{0}' and ID '{1}' was added.", campaign.name, campaign.id); AdGroup adGroup = CreateAdGroup(adGroupService, campaign); Console.WriteLine("Ad group with name '{0}' and ID '{1}' was added.", adGroup.name, adGroup.id); AdGroupAd adGroupAd = CreateProductAd(adGroupAdService, adGroup); Console.WriteLine("Product ad with ID {0}' was added.", adGroupAd.ad.id); } catch (Exception e) { throw new System.ApplicationException("Failed to create shopping campaign.", e); } }
/// <summary> /// Adds an experiment. /// </summary> /// <param name="user">The user.</param> /// <param name="campaignId">The campaign id.</param> /// <param name="adGroupId">The ad group id.</param> /// <param name="criterionId">The criterion id.</param> /// <returns>The experiment id.</returns> public long AddExperiment(AdWordsUser user, long campaignId, long adGroupId, long criterionId) { // Get the ExperimentService. ExperimentService experimentService = (ExperimentService)user.GetService(AdWordsService.v201406.ExperimentService); // Get the AdGroupService. AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201406.AdGroupService); // Get the AdGroupCriterionService. AdGroupCriterionService adGroupCriterionService = (AdGroupCriterionService)user.GetService(AdWordsService.v201406.AdGroupCriterionService); // Create the experiment. Experiment experiment = new Experiment(); experiment.campaignId = campaignId; experiment.name = "Interplanetary Cruise #" + GetTimeStamp(); experiment.queryPercentage = 10; experiment.startDateTime = DateTime.Now.AddDays(1).ToString("yyyyMMdd HHmmss"); // Create the operation. ExperimentOperation experimentOperation = new ExperimentOperation(); experimentOperation.@operator = Operator.ADD; experimentOperation.operand = experiment; // Add the experiment. ExperimentReturnValue experimentRetVal = experimentService.mutate( new ExperimentOperation[] { experimentOperation }); return(experimentRetVal.value[0].id); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group to be updated.</param> public void Run(AdWordsUser user, long adGroupId) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201705.AdGroupService)) { // Create the ad group. AdGroup adGroup = new AdGroup(); adGroup.status = AdGroupStatus.PAUSED; adGroup.id = adGroupId; // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.@operator = Operator.SET; operation.operand = adGroup; try { // Update the ad group. AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] { operation }); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { AdGroup pausedAdGroup = retVal.value[0]; Console.WriteLine("Ad group with id = '{0}' was successfully updated.", pausedAdGroup.id); } else { Console.WriteLine("No ad groups were updated."); } } catch (Exception e) { throw new System.ApplicationException("Failed to update ad group.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group to be removed.</param> public void Run(AdWordsUser user, long adGroupId) { using (AdGroupService adGroupService = (AdGroupService)user.GetService( AdWordsService.v201702.AdGroupService)) { // Create ad group with REMOVED status. AdGroup adGroup = new AdGroup(); adGroup.id = adGroupId; adGroup.status = AdGroupStatus.REMOVED; // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.operand = adGroup; operation.@operator = Operator.SET; try { // Remove the ad group. AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] { operation }); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { AdGroup removedAdGroup = retVal.value[0]; Console.WriteLine("Ad group with id = \"{0}\" and name = \"{1}\" was removed.", removedAdGroup.id, removedAdGroup.name); } else { Console.WriteLine("No ad groups were removed."); } } catch (Exception e) { throw new System.ApplicationException("Failed to remove ad group.", e); } } }
public static AdGroupReturnValue SetAdGroupStatus(AdWordsUser user, long adGroupId, AdGroupStatus adGroupStatus) { using (AdGroupService adGroupService = (AdGroupService)user.GetService( AdWordsService.v201710.AdGroupService)) { // Create ad group with REMOVED status. AdGroup adGroup = new AdGroup(); adGroup.id = adGroupId; adGroup.status = adGroupStatus; // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.operand = adGroup; operation.@operator = Operator.SET; AdGroupReturnValue retVal; try { // Remove the ad group. retVal = adGroupService.mutate(new AdGroupOperation[] { operation }); } catch (Exception e) { throw new System.ApplicationException("Failed to set ad group status.", e); } return(retVal); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which ad groups are /// retrieved.</param> public void Run(AdWordsUser user, long campaignId) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201809.AdGroupService)) { // Create the selector. Selector selector = new Selector() { fields = new string[] { AdGroup.Fields.Id, AdGroup.Fields.Name }, predicates = new Predicate[] { Predicate.Equals(AdGroup.Fields.CampaignId, campaignId) }, paging = Paging.Default, ordering = new OrderBy[] { OrderBy.Asc(AdGroup.Fields.Name) } }; AdGroupPage page = new AdGroupPage(); try { do { // Get the ad groups. page = adGroupService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = selector.paging.startIndex; foreach (AdGroup adGroup in page.entries) { Console.WriteLine("{0}) Ad group name is '{1}' and id is {2}.", i + 1, adGroup.name, adGroup.id); i++; } } // Note: You can also use selector.paging.IncrementOffsetBy(customPageSize) selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of ad groups found: {0}", page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve ad groups.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which ad groups are /// retrieved.</param> public void Run(AdWordsUser user, long campaignId) { // Get the AdGroupService. AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201409.AdGroupService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] { "Id", "Name" }; // Create the filters. Predicate predicate = new Predicate(); predicate.field = "CampaignId"; predicate.@operator = PredicateOperator.EQUALS; predicate.values = new string[] { campaignId.ToString() }; selector.predicates = new Predicate[] { predicate }; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; AdGroupPage page = new AdGroupPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get the ad groups. page = adGroupService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (AdGroup adGroup in page.entries) { Console.WriteLine("{0}) Ad group name is '{1}' and id is {2}.", i + 1, adGroup.name, adGroup.id); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of ad groups found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve ad groups.", ex); } }
/// <summary> /// Creates a test ad group for running further tests. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">The campaign id for which the adgroup is created.</param> /// <param name="adGroupType">The ad group type.</param> /// <param name="isCpmBid">True, if a ManualCPM bid is to be used.</param> /// <returns>The ad group ID.</returns> public long CreateAdGroup(AdWordsUser user, long campaignId, AdGroupType adGroupType, bool isCpmBid) { AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201806.AdGroupService); AdGroupOperation adGroupOperation = new AdGroupOperation(); adGroupOperation.@operator = Operator.ADD; adGroupOperation.operand = new AdGroup(); adGroupOperation.operand.campaignId = campaignId; adGroupOperation.operand.name = string.Format("AdGroup {0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")); adGroupOperation.operand.status = AdGroupStatus.ENABLED; if (adGroupType != AdGroupType.UNKNOWN) { adGroupOperation.operand.adGroupType = adGroupType; } if (isCpmBid) { BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); CpmBid cpmBid = new CpmBid(); cpmBid.bid = new Money(); cpmBid.bid.microAmount = 10000000; biddingConfig.bids = new Bids[] { cpmBid }; adGroupOperation.operand.biddingStrategyConfiguration = biddingConfig; } else { BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); CpcBid cpcBid = new CpcBid(); cpcBid.bid = new Money(); cpcBid.bid.microAmount = 10000000; biddingConfig.bids = new Bids[] { cpcBid }; adGroupOperation.operand.biddingStrategyConfiguration = biddingConfig; } AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] { adGroupOperation }); return(retVal.value[0].id); }
/// <summary> /// Creates an ad group. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">The campaign ID.</param> /// <returns>the newly created ad group.</returns> private static AdGroup CreateAdGroup(AdWordsUser user, long campaignId) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201806.AdGroupService)) { // Create the ad group. AdGroup adGroup = new AdGroup { // Required: Set the ad group's type to Dynamic Search Ads. adGroupType = AdGroupType.SEARCH_DYNAMIC_ADS, name = string.Format("Earth to Mars Cruises #{0}", ExampleUtilities.GetRandomString()), campaignId = campaignId, status = AdGroupStatus.PAUSED, // Recommended: Set a tracking URL template for your ad group if you want to use URL // tracking software. trackingUrlTemplate = "http://tracker.example.com/traveltracker/{escapedlpurl}" }; // Set the ad group bids. BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); CpcBid cpcBid = new CpcBid { bid = new Money { microAmount = 3000000 } }; biddingConfig.bids = new Bids[] { cpcBid }; adGroup.biddingStrategyConfiguration = biddingConfig; // Create the operation. AdGroupOperation operation = new AdGroupOperation { @operator = Operator.ADD, operand = adGroup }; try { // Create the ad group. AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] { operation }); // Display the results. AdGroup newAdGroup = retVal.value[0]; Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.", newAdGroup.id, newAdGroup.name); return(newAdGroup); } catch (Exception e) { throw new System.ApplicationException("Failed to create ad group.", e); } } }
public static List <AdGroup> GetAdGroups(AdWordsUser user, long campaignId, bool getAllAdGroups) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201710.AdGroupService)) { // Create the selector. Selector selector = new Selector() { fields = new string[] { AdGroup.Fields.Id, AdGroup.Fields.Name, AdGroup.Fields.CampaignId, AdGroup.Fields.Status }, predicates = new Predicate[] { Predicate.Equals(AdGroup.Fields.CampaignId, campaignId) }, paging = Paging.Default, ordering = new OrderBy[] { OrderBy.Asc(AdGroup.Fields.Name) } }; AdGroupPage page = new AdGroupPage(); List <AdGroup> result = new List <AdGroup>(); try { // Get the ad groups. page = adGroupService.get(selector); if (page.entries != null) { foreach (AdGroup item in page.entries) { if (!getAllAdGroups) { if (item.status == AdGroupStatus.PAUSED) { result.Add(item); } } else { result.Add(item); } } } } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve ad groups.", e); } return(result); } }
/// <summary> /// Gets the ad group for policy checks. /// </summary> /// <param name="user">The user.</param> /// <param name="campaignId">The campaign identifier.</param> /// <returns></returns> /// <exception cref="System.ApplicationException">Failed to retrieve ad /// group for policy checks.</exception> private long GetAdGroupForPolicyChecks(AdWordsUser user, long campaignId) { AdGroupService adGroupService = (AdGroupService)user.GetService( AdWordsService.v201607.AdGroupService); string query = string.Format("Select AdGroupId where CampaignId = {0}", campaignId); try { AdGroupPage page = adGroupService.query(query); return(page.entries[0].id); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve ad group for policy checks.", e); } }
/// <summary> /// Creates the ad group in a Shopping campaign. /// </summary> /// <param name="user">The AdWords user for which the ad group is created.</param> /// <param name="campaign">The Shopping campaign.</param> /// <returns>The newly created ad group.</returns> private static AdGroup CreateAdGroup(AdWordsUser user, Campaign campaign) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201809.AdGroupService)) { // Create ad group. AdGroup adGroup = new AdGroup { campaignId = campaign.id, name = "Ad Group #" + ExampleUtilities.GetRandomString(), // Required: Set the ad group type to SHOPPING_SHOWCASE_ADS. adGroupType = AdGroupType.SHOPPING_SHOWCASE_ADS }; // Required: Set the ad group's bidding strategy configuration. BiddingStrategyConfiguration biddingConfiguration = new BiddingStrategyConfiguration { // Optional: Set the bids. bids = new Bids[] { new CpcBid() { bid = new Money() { microAmount = 100000 } } } }; adGroup.biddingStrategyConfiguration = biddingConfiguration; // Create the operation. AdGroupOperation operation = new AdGroupOperation { operand = adGroup, @operator = Operator.ADD }; // Make the mutate request. AdGroupReturnValue retval = adGroupService.mutate(new AdGroupOperation[] { operation }); return(retval.value[0]); } }
/// <summary> /// Creates an ad group in the specified campaign. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaign">The campaign to which the ad group should be attached.</param> /// <returns>The ad group that was created.</returns> private static AdGroup CreateAdGroup(AdWordsUser user, Campaign campaign) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201806.AdGroupService)) { AdGroup group = new AdGroup(); group.name = "Dynamic remarketing ad group"; group.campaignId = campaign.id; group.status = AdGroupStatus.ENABLED; AdGroupOperation op = new AdGroupOperation(); op.operand = group; op.@operator = Operator.ADD; AdGroupReturnValue result = adGroupService.mutate(new AdGroupOperation[] { op }); return(result.value[0]); } }
/// <summary> /// Creates the ad group in a Shopping campaign. /// </summary> /// <param name="user">The AdWords user for which the ad group is created.</param> /// <param name="campaign">The Shopping campaign.</param> /// <returns>The newly created ad group.</returns> private static AdGroup CreateAdGroup(AdWordsUser user, Campaign campaign) { AdGroupService adGroupService = (AdGroupService)user.GetService( AdWordsService.v201702.AdGroupService); // Create ad group. AdGroup adGroup = new AdGroup(); adGroup.campaignId = campaign.id; adGroup.name = "Ad Group #" + ExampleUtilities.GetRandomString(); // Required: Set the ad group type to SHOPPING_SHOWCASE_ADS. adGroup.adGroupType = AdGroupType.SHOPPING_SHOWCASE_ADS; // Required: Set the ad group's bidding strategy configuration. BiddingStrategyConfiguration biddingConfiguration = new BiddingStrategyConfiguration(); // Showcase ads require either ManualCpc or EnhancedCpc. biddingConfiguration.biddingStrategyType = BiddingStrategyType.MANUAL_CPC; // Optional: Set the bids. biddingConfiguration.bids = new Bids[] { new CpcBid() { bid = new Money() { microAmount = 100000 } } }; adGroup.biddingStrategyConfiguration = biddingConfiguration; // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.operand = adGroup; operation.@operator = Operator.ADD; // Make the mutate request. AdGroupReturnValue retval = adGroupService.mutate(new AdGroupOperation[] { operation }); return(retval.value[0]); }
/// <summary> /// Creates the ad group in a Shopping campaign. /// </summary> /// <param name="adGroupService">The AdGroupService instance.</param> /// <param name="campaign">The Shopping campaign.</param> /// <returns>The ad group.</returns> private static AdGroup CreateAdGroup(AdGroupService adGroupService, Campaign campaign) { // Create ad group. AdGroup adGroup = new AdGroup(); adGroup.campaignId = campaign.id; adGroup.name = "Ad Group #" + ExampleUtilities.GetRandomString(); // Create operation. AdGroupOperation operation = new AdGroupOperation(); operation.operand = adGroup; operation.@operator = Operator.ADD; // Make the mutate request. AdGroupReturnValue retval = adGroupService.mutate(new AdGroupOperation[] { operation }); return(retval.value[0]); }
/// <summary> /// Creates the ad group in a Shopping campaign. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">The campaign ID.</param> /// <returns>The ad group.</returns> private static AdGroup CreateAdGroup(AdWordsUser user, long campaignId) { AdGroupService adGroupService = (AdGroupService)user.GetService( AdWordsService.v201710.AdGroupService); // Create ad group. AdGroup adGroup = new AdGroup(); adGroup.campaignId = campaignId; adGroup.name = "Ad Group #" + ExampleUtilities.GetRandomString(); // Create operation. AdGroupOperation operation = new AdGroupOperation(); operation.operand = adGroup; operation.@operator = Operator.ADD; // Make the mutate request. AdGroupReturnValue retval = adGroupService.mutate(new AdGroupOperation[] { operation }); adGroupService.Close(); return(retval.value[0]); }
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="adGroupId">Id of the ad group to be updated.</param> /// <param name="bidMicroAmount">The CPC bid amount in micros.</param> public void Run(AdWordsUser user, long adGroupId, long?bidMicroAmount) { using (AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201710.AdGroupService)) { // Create an ad group with the specified ID. AdGroup adGroup = new AdGroup(); adGroup.id = adGroupId; // Pause the ad group. adGroup.status = AdGroupStatus.PAUSED; // Update the CPC bid if specified. if (bidMicroAmount != null) { BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration(); Money cpcBidMoney = new Money(); cpcBidMoney.microAmount = bidMicroAmount.Value; CpcBid cpcBid = new CpcBid(); cpcBid.bid = cpcBidMoney; biddingStrategyConfiguration.bids = new Bids[] { cpcBid }; adGroup.biddingStrategyConfiguration = biddingStrategyConfiguration; } // Create the operation. AdGroupOperation operation = new AdGroupOperation(); operation.@operator = Operator.SET; operation.operand = adGroup; try { // Update the ad group. AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] { operation }); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { AdGroup adGroupResult = retVal.value[0]; BiddingStrategyConfiguration bsConfig = adGroupResult.biddingStrategyConfiguration; // Find the CpcBid in the bidding strategy configuration's bids collection. long cpcBidMicros = 0L; if (bsConfig != null && bsConfig.bids != null) { foreach (Bids bid in bsConfig.bids) { if (bid is CpcBid) { cpcBidMicros = ((CpcBid)bid).bid.microAmount; break; } } } Console.WriteLine("Ad group with ID {0} and name '{1}' updated to have status '{2}'" + " and CPC bid {3}", adGroupResult.id, adGroupResult.name, adGroupResult.status, cpcBidMicros); } else { Console.WriteLine("No ad groups were updated."); } } catch (Exception e) { throw new System.ApplicationException("Failed to update ad group.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to which experiments are /// added.</param> /// <param name="adGroupId">Id of the ad group to which experiments are /// added.</param> /// <param name="criterionId">Id of the criterion for which experiments /// are added.</param> public void Run(AdWordsUser user, long campaignId, long adGroupId, long criterionId) { // Get the ExperimentService. ExperimentService experimentService = (ExperimentService)user.GetService(AdWordsService.v201607.ExperimentService); // Get the AdGroupService. AdGroupService adGroupService = (AdGroupService)user.GetService(AdWordsService.v201607.AdGroupService); // Get the AdGroupCriterionService. AdGroupCriterionService adGroupCriterionService = (AdGroupCriterionService)user.GetService(AdWordsService.v201607.AdGroupCriterionService); // Create the experiment. Experiment experiment = new Experiment(); experiment.campaignId = campaignId; experiment.name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(); experiment.queryPercentage = 10; experiment.startDateTime = DateTime.Now.AddDays(1).ToString("yyyyMMdd HHmmss"); // Optional: Set the end date. experiment.endDateTime = DateTime.Now.AddDays(30).ToString("yyyyMMdd HHmmss"); // Optional: Set the status. experiment.status = ExperimentStatus.ENABLED; // Create the operation. ExperimentOperation experimentOperation = new ExperimentOperation(); experimentOperation.@operator = Operator.ADD; experimentOperation.operand = experiment; try { // Add the experiment. ExperimentReturnValue experimentRetVal = experimentService.mutate( new ExperimentOperation[] { experimentOperation }); // Display the results. if (experimentRetVal != null && experimentRetVal.value != null && experimentRetVal.value. Length > 0) { long experimentId = 0; Experiment newExperiment = experimentRetVal.value[0]; Console.WriteLine("Experiment with name = \"{0}\" and id = \"{1}\" was added.\n", newExperiment.name, newExperiment.id); experimentId = newExperiment.id; // Set ad group for the experiment. AdGroup adGroup = new AdGroup(); adGroup.id = adGroupId; // Create experiment bid multiplier rule that will modify ad group bid // for the experiment. ManualCPCAdGroupExperimentBidMultipliers adGroupBidMultiplier = new ManualCPCAdGroupExperimentBidMultipliers(); adGroupBidMultiplier.maxCpcMultiplier = new BidMultiplier(); adGroupBidMultiplier.maxCpcMultiplier.multiplier = 1.5; // Set experiment data to the ad group. AdGroupExperimentData adGroupExperimentData = new AdGroupExperimentData(); adGroupExperimentData.experimentId = experimentId; adGroupExperimentData.experimentDeltaStatus = ExperimentDeltaStatus.MODIFIED; adGroupExperimentData.experimentBidMultipliers = adGroupBidMultiplier; adGroup.experimentData = adGroupExperimentData; // Create the operation. AdGroupOperation adGroupOperation = new AdGroupOperation(); adGroupOperation.operand = adGroup; adGroupOperation.@operator = Operator.SET; // Update the ad group. AdGroupReturnValue adGroupRetVal = adGroupService.mutate(new AdGroupOperation[] { adGroupOperation }); // Display the results. if (adGroupRetVal != null && adGroupRetVal.value != null && adGroupRetVal.value.Length > 0) { AdGroup updatedAdGroup = adGroupRetVal.value[0]; Console.WriteLine("Ad group with name = \"{0}\", id = \"{1}\" and status = \"{2}\" " + "was updated for the experiment.\n", updatedAdGroup.name, updatedAdGroup.id, updatedAdGroup.status); } else { Console.WriteLine("No ad groups were updated."); } // Set ad group criteria for the experiment. Criterion criterion = new Criterion(); criterion.id = criterionId; BiddableAdGroupCriterion adGroupCriterion = new BiddableAdGroupCriterion(); adGroupCriterion.adGroupId = adGroupId; adGroupCriterion.criterion = criterion; // Create experiment bid multiplier rule that will modify criterion bid // for the experiment. ManualCPCAdGroupCriterionExperimentBidMultiplier bidMultiplier = new ManualCPCAdGroupCriterionExperimentBidMultiplier(); bidMultiplier.maxCpcMultiplier = new BidMultiplier(); bidMultiplier.maxCpcMultiplier.multiplier = 1.5; // Set experiment data to the criterion. BiddableAdGroupCriterionExperimentData adGroupCriterionExperimentData = new BiddableAdGroupCriterionExperimentData(); adGroupCriterionExperimentData.experimentId = experimentId; adGroupCriterionExperimentData.experimentDeltaStatus = ExperimentDeltaStatus.MODIFIED; adGroupCriterionExperimentData.experimentBidMultiplier = bidMultiplier; adGroupCriterion.experimentData = adGroupCriterionExperimentData; // Create the operation. AdGroupCriterionOperation adGroupCriterionOperation = new AdGroupCriterionOperation(); adGroupCriterionOperation.operand = adGroupCriterion; adGroupCriterionOperation.@operator = Operator.SET; // Update the ad group criteria. AdGroupCriterionReturnValue adGroupCriterionRetVal = adGroupCriterionService.mutate( new AdGroupCriterionOperation[] { adGroupCriterionOperation }); // Display the results. if (adGroupCriterionRetVal != null && adGroupCriterionRetVal.value != null && adGroupCriterionRetVal.value.Length > 0) { AdGroupCriterion updatedAdGroupCriterion = adGroupCriterionRetVal.value[0]; Console.WriteLine("Ad group criterion with ad group id = \"{0}\", criterion id = " + "\"{1}\" and type = \"{2}\" was updated for the experiment.\n", updatedAdGroupCriterion.adGroupId, updatedAdGroupCriterion.criterion.id, updatedAdGroupCriterion.criterion.CriterionType); } else { Console.WriteLine("No ad group criteria were updated."); } } else { Console.WriteLine("No experiments were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to add experiment.", e); } }
/// <summary> /// Creates the ad group in a Shopping campaign. /// </summary> /// <param name="adGroupService">The AdGroupService instance.</param> /// <param name="campaign">The Shopping campaign.</param> /// <returns>The ad group.</returns> private static AdGroup CreateAdGroup(AdGroupService adGroupService, Campaign campaign) { // Create ad group. AdGroup adGroup = new AdGroup(); adGroup.campaignId = campaign.id; adGroup.name = "Ad Group #" + ExampleUtilities.GetRandomString(); // Create operation. AdGroupOperation operation = new AdGroupOperation(); operation.operand = adGroup; operation.@operator = Operator.ADD; // Make the mutate request. AdGroupReturnValue retval = adGroupService.mutate(new AdGroupOperation[] { operation }); return retval.value[0]; }
/// <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); } }
private void GetAgSettings2_Click(object sender, EventArgs e) { Dictionary <string, string> headers = new Dictionary <string, string>() { { "DeveloperToken", this.DeveloperToken.Text }, { "UserAgent", String.Format("Edge File Manager (version {0})", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()) }, { "EnableGzipCompression", this.EnableGzipCompression.Text }, { "ClientCustomerId", this.ClientCustomerId.Text }, { "Email", this.Email.Text } }; User = new AdWordsUser(headers); try { //Getting AuthToken (User.Config as AdWordsAppConfig).AuthToken = AdwordsUtill.GetAuthToken(User); } catch (Exception exc) { this.rchtxt.Text = exc.Message + " #### " + exc.InnerException != null ? exc.InnerException.Message : string.Empty; } AdGroupService agService = (AdGroupService)User.GetService(AdWordsService.v201302.AdGroupService); ConstantDataService constData = (ConstantDataService)User.GetService(AdWordsService.v201302.ConstantDataService); Language[] lang = constData.getLanguageCriterion(); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] { "Id", "Status", "Clicks" }; // Set the filters. // Predicate predicate = new Predicate(); // predicate.field = "CampaignId"; // predicate.@operator = PredicateOperator.EQUALS; // predicate.values = new string[] { campaignId.ToString() }; // selector.predicates = new Predicate[] { predicate }; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; AdGroupPage page = new AdGroupPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get all campaign targets. page = agService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (AdGroup adGroup in page.entries) { i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of ad groups criteria found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to get adgroup targeting criteria.", ex); } }