/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which shopping channel /// is set.</param> public void Run(AdWordsUser user, long campaignId) { // Get the CampaignCriterionService. CampaignCriterionService campaignCriterionService = (CampaignCriterionService) user.GetService( AdWordsService.v201402.CampaignCriterionService); // ProductSalesChannel is a fixed id criterion, with the possible values // defined here. // ONLINE: 200 // LOCAL: 201 ProductSalesChannel productSalesChannel = new ProductSalesChannel(); productSalesChannel.id = 200; CampaignCriterion campaignCriterion = new CampaignCriterion(); campaignCriterion.campaignId = campaignId; campaignCriterion.criterion = productSalesChannel; // Create operation. CampaignCriterionOperation operation = new CampaignCriterionOperation(); operation.operand = campaignCriterion; operation.@operator = Operator.ADD; try { // Make the mutate request. CampaignCriterionReturnValue retVal = campaignCriterionService.mutate( new CampaignCriterionOperation[] { operation }); if (retVal != null && retVal.value != null) { // Display campaign targets. foreach (CampaignCriterion criterion in retVal.value) { Console.WriteLine("Campaign criteria of type '{0}' was set to campaign with" + " id = '{1}'.", criterion.criterion.CriterionType, criterion.campaignId); } } } catch (Exception ex) { throw new System.ApplicationException("Failed to set shopping product channel.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">The campaign id to add product scope.</param> public void Run(AdWordsUser user, long campaignId) { // Get the CampaignCriterionService. CampaignCriterionService campaignCriterionService = (CampaignCriterionService) user.GetService( AdWordsService.v201402.CampaignCriterionService); ProductScope productScope = new ProductScope(); // This set of dimensions is for demonstration purposes only. It would be // extremely unlikely that you want to include so many dimensions in your // product scope. ProductBrand nexusBrand = new ProductBrand(); nexusBrand.value = "Nexus"; ProductCanonicalCondition newProducts = new ProductCanonicalCondition(); newProducts.condition = ProductCanonicalConditionCondition.NEW; ProductCustomAttribute customAttribute = new ProductCustomAttribute(); customAttribute.type = ProductDimensionType.CUSTOM_ATTRIBUTE_0; customAttribute.value = "my attribute value"; ProductOfferId bookOffer = new ProductOfferId(); bookOffer.value = "book1"; ProductType mediaProducts = new ProductType(); mediaProducts.type = ProductDimensionType.PRODUCT_TYPE_L1; mediaProducts.value = "Media"; ProductType bookProducts = new ProductType(); bookProducts.type = ProductDimensionType.PRODUCT_TYPE_L2; bookProducts.value = "Books"; // The value for the bidding category is a fixed ID for the // 'Luggage & Bags' category. You can retrieve IDs for categories from // the ConstantDataService. See the 'GetProductCategoryTaxonomy' example // for more details. ProductBiddingCategory luggageBiddingCategory = new ProductBiddingCategory(); luggageBiddingCategory.type = ProductDimensionType.BIDDING_CATEGORY_L1; luggageBiddingCategory.value = -5914235892932915235; productScope.dimensions = new ProductDimension[] {nexusBrand, newProducts, bookOffer, mediaProducts, luggageBiddingCategory}; CampaignCriterion campaignCriterion = new CampaignCriterion(); campaignCriterion.campaignId = campaignId; campaignCriterion.criterion = productScope; // Create operation. CampaignCriterionOperation operation = new CampaignCriterionOperation(); operation.operand = campaignCriterion; operation.@operator = Operator.ADD; try { // Make the mutate request. CampaignCriterionReturnValue result = campaignCriterionService.mutate( new CampaignCriterionOperation[] { operation }); Console.WriteLine("Created a ProductScope criterion with ID '{0}'", result.value[0].criterion.id); } catch (Exception ex) { throw new System.ApplicationException("Failed to set shopping product scope.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to which targeting criteria /// are added.</param> public void Run(AdWordsUser user, long campaignId) { // Get the CampaignCriterionService. CampaignCriterionService campaignCriterionService = (CampaignCriterionService) user.GetService( AdWordsService.v201402.CampaignCriterionService); // Create language criteria. // See http://code.google.com/apis/adwords/docs/appendix/languagecodes.html // for a detailed list of language codes. Language language1 = new Language(); language1.id = 1002; // French CampaignCriterion languageCriterion1 = new CampaignCriterion(); languageCriterion1.campaignId = campaignId; languageCriterion1.criterion = language1; Language language2 = new Language(); language2.id = 1005; // Japanese CampaignCriterion languageCriterion2 = new CampaignCriterion(); languageCriterion2.campaignId = campaignId; languageCriterion2.criterion = language2; // Target Tier 3 income group near Miami, Florida. LocationGroups incomeLocationGroups = new LocationGroups(); IncomeOperand incomeOperand = new IncomeOperand(); // Tiers are numbered 1-10, and represent 10% segments of earners. // For example, TIER_1 is the top 10%, TIER_2 is the 80-90%, etc. // Tiers 6 through 10 are grouped into TIER_6_TO_10. incomeOperand.tier = IncomeTier.TIER_3; GeoTargetOperand geoTargetOperand1 = new GeoTargetOperand(); geoTargetOperand1.locations = new long[] {1015116}; // Miami, FL. incomeLocationGroups.matchingFunction = new Function(); incomeLocationGroups.matchingFunction.lhsOperand = new FunctionArgumentOperand[] {incomeOperand}; incomeLocationGroups.matchingFunction.@operator = FunctionOperator.AND; incomeLocationGroups.matchingFunction.rhsOperand = new FunctionArgumentOperand[] {geoTargetOperand1}; CampaignCriterion locationGroupCriterion1 = new CampaignCriterion(); locationGroupCriterion1.campaignId = campaignId; locationGroupCriterion1.criterion = incomeLocationGroups; // Target places of interest near Downtown Miami, Florida. LocationGroups interestLocationGroups = new LocationGroups(); PlacesOfInterestOperand placesOfInterestOperand = new PlacesOfInterestOperand(); placesOfInterestOperand.category = PlacesOfInterestOperandCategory.DOWNTOWN; GeoTargetOperand geoTargetOperand2 = new GeoTargetOperand(); geoTargetOperand2.locations = new long[] { 1015116 }; // Miami, FL. interestLocationGroups.matchingFunction = new Function(); interestLocationGroups.matchingFunction.lhsOperand = new FunctionArgumentOperand[] {placesOfInterestOperand}; interestLocationGroups.matchingFunction.@operator = FunctionOperator.AND; interestLocationGroups.matchingFunction.rhsOperand = new FunctionArgumentOperand[] {geoTargetOperand2}; CampaignCriterion locationGroupCriterion2 = new CampaignCriterion(); locationGroupCriterion2.campaignId = campaignId; locationGroupCriterion2.criterion = interestLocationGroups; // Create location criteria. // See http://code.google.com/apis/adwords/docs/appendix/countrycodes.html // for a detailed list of country codes. Location location1 = new Location(); location1.id = 2840; // USA CampaignCriterion locationCriterion1 = new CampaignCriterion(); locationCriterion1.campaignId = campaignId; locationCriterion1.criterion = location1; Location location2 = new Location(); location2.id = 2392; // Japan CampaignCriterion locationCriterion2 = new CampaignCriterion(); locationCriterion2.campaignId = campaignId; locationCriterion2.criterion = location2; // Add a negative campaign keyword. NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion(); negativeCriterion.campaignId = campaignId; Keyword keyword = new Keyword(); keyword.matchType = KeywordMatchType.BROAD; keyword.text = "jupiter cruise"; negativeCriterion.criterion = keyword; CampaignCriterion[] criteria = new CampaignCriterion[] {languageCriterion1, languageCriterion2, locationCriterion1, locationCriterion2, negativeCriterion, locationGroupCriterion1, locationGroupCriterion2}; List<CampaignCriterionOperation> operations = new List<CampaignCriterionOperation>(); foreach (CampaignCriterion criterion in criteria) { CampaignCriterionOperation operation = new CampaignCriterionOperation(); operation.@operator = Operator.ADD; operation.operand = criterion; operations.Add(operation); } try { // Set the campaign targets. CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray()); if (retVal != null && retVal.value != null) { // Display campaign targets. foreach (CampaignCriterion criterion in retVal.value) { Console.WriteLine("Campaign criteria of type '{0}' was set to campaign with" + " id = '{1}'.", criterion.criterion.CriterionType, criterion.campaignId); } } } catch (Exception ex) { throw new System.ApplicationException("Failed to set Campaign criteria.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to which targeting criteria /// are added.</param> public void Run(AdWordsUser user, long campaignId) { // Get the CampaignCriterionService. CampaignCriterionService campaignCriterionService = (CampaignCriterionService) user.GetService( AdWordsService.v201402.CampaignCriterionService); // Create language criteria. // See http://code.google.com/apis/adwords/docs/appendix/languagecodes.html // for a detailed list of language codes. Language language1 = new Language(); language1.id = 1002; // French CampaignCriterion languageCriterion1 = new CampaignCriterion(); languageCriterion1.campaignId = campaignId; languageCriterion1.criterion = language1; Language language2 = new Language(); language2.id = 1005; // Japanese CampaignCriterion languageCriterion2 = new CampaignCriterion(); languageCriterion2.campaignId = campaignId; languageCriterion2.criterion = language2; // Create location criteria. // See http://code.google.com/apis/adwords/docs/appendix/countrycodes.html // for a detailed list of country codes. Location location1 = new Location(); location1.id = 2840; // USA CampaignCriterion locationCriterion1 = new CampaignCriterion(); locationCriterion1.campaignId = campaignId; locationCriterion1.criterion = location1; Location location2 = new Location(); location2.id = 2392; // Japan CampaignCriterion locationCriterion2 = new CampaignCriterion(); locationCriterion2.campaignId = campaignId; locationCriterion2.criterion = location2; // Add a negative campaign placement. NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion(); negativeCriterion.campaignId = campaignId; Placement placement = new Placement(); placement.url = "http://mars.google.com"; negativeCriterion.criterion = placement; CampaignCriterion[] criteria = new CampaignCriterion[] {languageCriterion1, languageCriterion2, locationCriterion1, locationCriterion2, negativeCriterion}; List<CampaignCriterionOperation> operations = new List<CampaignCriterionOperation>(); foreach (CampaignCriterion criterion in criteria) { CampaignCriterionOperation operation = new CampaignCriterionOperation(); operation.@operator = Operator.ADD; operation.operand = criterion; operations.Add(operation); } try { // Set the campaign targets. CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray()); if (retVal != null && retVal.value != null) { // Display campaign targets. foreach (CampaignCriterion criterion in retVal.value) { Console.WriteLine("Campaign criteria of type '{0}' was set to campaign with" + " id = '{1}'.", criterion.criterion.CriterionType, criterion.campaignId); } } } catch (Exception ex) { throw new System.ApplicationException("Failed to set Campaign criteria.", ex); } }
/// <summary> /// Adds the campaign targeting criteria to a campaign. /// </summary> /// <param name="user">The user.</param> /// <param name="campaignId">The campaign id.</param> /// <returns>The campaign criteria id.</returns> public long AddCampaignTargetingCriteria(AdWordsUser user, long campaignId) { // Get the CampaignCriterionService. CampaignCriterionService campaignCriterionService = (CampaignCriterionService) user.GetService( AdWordsService.v201402.CampaignCriterionService); // Create language criteria. // See http://code.google.com/apis/adwords/docs/appendix/languagecodes.html // for a detailed list of language codes. Language language1 = new Language(); language1.id = 1002; // French CampaignCriterion languageCriterion1 = new CampaignCriterion(); languageCriterion1.campaignId = campaignId; languageCriterion1.criterion = language1; CampaignCriterion[] criteria = new CampaignCriterion[] {languageCriterion1}; List<CampaignCriterionOperation> operations = new List<CampaignCriterionOperation>(); foreach (CampaignCriterion criterion in criteria) { CampaignCriterionOperation operation = new CampaignCriterionOperation(); operation.@operator = Operator.ADD; operation.operand = criterion; operations.Add(operation); } CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray()); return retVal.value[0].criterion.id; }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the campaign whose bid should be modified. /// </param> /// <param name="bidModifier">The bid modifier.</param> public void Run(AdWordsUser user, long campaignId, double bidModifier) { // Get the CampaignCriterionService. CampaignCriterionService campaignCriterionService = (CampaignCriterionService) user.GetService( AdWordsService.v201402.CampaignCriterionService); // Create mobile platform. The ID can be found in the documentation. // https://developers.google.com/adwords/api/docs/appendix/platforms Platform mobile = new Platform(); mobile.id = 30001; // Create criterion with modified bid. CampaignCriterion criterion = new CampaignCriterion(); criterion.campaignId = campaignId; criterion.criterion = mobile; criterion.bidModifier = bidModifier; // Create SET operation. CampaignCriterionOperation operation = new CampaignCriterionOperation(); operation.@operator = Operator.SET; operation.operand = criterion; try { // Update campaign criteria. CampaignCriterionReturnValue result = campaignCriterionService.mutate( new CampaignCriterionOperation[] {operation}); // Display campaign criteria. if (result.value != null) { foreach (CampaignCriterion newCriterion in result.value) { Console.WriteLine("Campaign criterion with campaign id '{0}', criterion id '{1}', " + "and type '{2}' was modified with bid {3:F2}.", newCriterion.campaignId, newCriterion.criterion.id, newCriterion.criterion.type, newCriterion.bidModifier); } } else { Console.WriteLine("No campaign criteria were modified."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to set bid modifier for campaign.", ex); } }