/// <summary> /// Creates child nodes on level 2, partitioned by the country region. /// </summary> /// <param name="customerId">The Google Ads customer ID.</param> /// <param name="adGroupId">The ad group ID to which the hotel listing group will be /// added.</param> /// <param name="parentResourceName">The resource name of the parent criterion for the nodes /// to be added at this level.</param> /// <param name="operations">A list of AdGroupCriterionOperations.</param> /// <param name="percentCpcBidMicroAmount">The CPC bid micro amount to be set on created /// ad group criteria.</param> private void AddLevel2Nodes(long customerId, long adGroupId, string parentResourceName, List <AdGroupCriterionOperation> operations, long percentCpcBidMicroAmount) { // Create hotel dimension info for hotels in Japan. The criterion ID for Japan is 2392. // See https://developers.google.com/adwords/api/docs/appendix/geotargeting for criteria // ID of other countries. ListingDimensionInfo japanListingDimensionInfo = new ListingDimensionInfo { HotelCountryRegion = new HotelCountryRegionInfo { CountryRegionCriterion = ResourceNames.GeoTargetConstant(2392) } }; // Create listing group info for hotels in Japan as a UNIT node. ListingGroupInfo japanHotelsUnit = CreateListingGroupInfo(ListingGroupType.Unit, parentResourceName, japanListingDimensionInfo); // Create an ad group criterion for hotels in Japan. AdGroupCriterion japanHotelsAdGroupCriterion = CreateAdGroupCriterion(customerId, adGroupId, japanHotelsUnit, percentCpcBidMicroAmount); // Create an operation and add it to the list of operations. operations.Add(new AdGroupCriterionOperation { Create = japanHotelsAdGroupCriterion }); // Decrement the temp ID for the next ad group criterion. nextTempId--; // Create hotel class info and dimension info for hotels in other regions. ListingDimensionInfo otherHotelRegionsListingDimensionInfo = new ListingDimensionInfo { HotelCountryRegion = new HotelCountryRegionInfo() }; // Create listing group info for hotels in other regions as a UNIT node. // The "others" node is always required for every level of the tree. ListingGroupInfo otherHotelRegionsUnit = CreateListingGroupInfo( ListingGroupType.Unit, parentResourceName, otherHotelRegionsListingDimensionInfo); // Create an ad group criterion for other hotel country regions. AdGroupCriterion otherHotelRegionsAdGroupCriterion = CreateAdGroupCriterion(customerId, adGroupId, otherHotelRegionsUnit, percentCpcBidMicroAmount); // Create an operation and add it to the list of operations. operations.Add(new AdGroupCriterionOperation { Create = otherHotelRegionsAdGroupCriterion }); // Decrement the temp ID for the next ad group criterion. nextTempId--; }
/// <summary> /// Creates the listing group info with the provided parameters. /// </summary> /// <param name="listingGroupType">The listing group type.</param> /// <param name="parentCriterionResourceName">Optional resource name of the parent criterion /// ID to set for this listing group info.</param> /// <param name="caseValue">Optional dimension info for the listing group.</param> /// <returns>A populated ListingGroupInfo.</returns> private ListingGroupInfo CreateListingGroupInfo(ListingGroupType listingGroupType, string parentCriterionResourceName = null, ListingDimensionInfo caseValue = null) { ListingGroupInfo listingGroupInfo = new ListingGroupInfo { Type = listingGroupType }; if (parentCriterionResourceName != null) { listingGroupInfo.ParentAdGroupCriterion = parentCriterionResourceName; listingGroupInfo.CaseValue = caseValue; } return(listingGroupInfo); }
/// <summary> /// Creates an ad group criterion from the provided listing group info. /// Bid amount will be set on the created ad group criterion when listing group info type is /// `UNIT`. Setting bid amount for `SUBDIVISION` types is not allowed. /// </summary> /// <param name="customerId">The Google Ads customer ID.</param> /// <param name="adGroupId">The ad group ID to which the criterion will belong.</param> /// <param name="listingGroupInfo">The listing group info to apply to the criterion.</param> /// <param name="percentCpcBidMicroAmount">The CPC bid micro amount to set for the ad group criterion.</param> /// <returns>A populated ad group criterion.</returns> private AdGroupCriterion CreateAdGroupCriterion(long customerId, long adGroupId, ListingGroupInfo listingGroupInfo, long percentCpcBidMicroAmount) { AdGroupCriterion adGroupCriterion = new AdGroupCriterion { Status = AdGroupCriterionStatus.Enabled, ListingGroup = listingGroupInfo, ResourceName = ResourceNames.AdGroupCriterion(customerId, adGroupId, nextTempId) }; // Bids are only valid for UNIT nodes. if (listingGroupInfo.Type == ListingGroupType.Unit) { adGroupCriterion.PercentCpcBidMicros = percentCpcBidMicroAmount; } return(adGroupCriterion); }
/// <summary> /// Creates the root node of the listing group tree and adds its create operation to the /// operations list. /// </summary> /// <param name="customerId">The Google Ads customer ID.</param> /// <param name="adGroupId">The ad group ID to which the hotel listing group will be /// added.</param> /// <param name="operations">A list of AdGroupCriterionOperations.</param> /// <param name="percentCpcBidMicroAmount">The CPC bid micro amount to be set on created /// ad group criteria.</param> /// <returns>The string resource name of the root of the tree.</returns> private string AddRootNode(long customerId, long adGroupId, List <AdGroupCriterionOperation> operations, long percentCpcBidMicroAmount) { // Create the root of the tree as a SUBDIVISION node. ListingGroupInfo rootListingGroupInfo = CreateListingGroupInfo(ListingGroupType.Subdivision); AdGroupCriterion rootAdGroupCriterion = CreateAdGroupCriterion(customerId, adGroupId, rootListingGroupInfo, percentCpcBidMicroAmount); // Create an operation and add it to the list of operations. operations.Add(new AdGroupCriterionOperation { Create = rootAdGroupCriterion }); // Decrement the temp ID for the next ad group criterion. nextTempId--; return(rootAdGroupCriterion.ResourceName); }
// [END add_shopping_product_ad] /// <summary> /// Creates a new default shopping listing group for the specified ad group. A listing /// group is the Google Ads API representation of a "product group" described in the /// Google Ads user interface. The listing group will be added to the ad group using an /// "ad group criterion". /// </summary> /// <param name="client">The Google Ads API client.</param> /// <param name="customerId">The client customer ID.</param> /// <param name="adGroupResourceName">The resource name of the ad group that the new /// listing group will belong to.</param> /// <returns>Resource name of the newly created ad group criterion containing the /// listing group.</returns> /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more /// service errors.</exception> private string AddDefaultShoppingListingGroup(GoogleAdsClient client, long customerId, string adGroupResourceName) { // Get the AdGroupCriterionService. AdGroupCriterionServiceClient adGroupCriterionService = client.GetService( Services.V10.AdGroupCriterionService); // Creates a new ad group criterion. This will contain the "default" listing group (All // products). AdGroupCriterion adGroupCriterion = new AdGroupCriterion() { AdGroup = adGroupResourceName, Status = AdGroupCriterionStatus.Enabled, // Creates a new listing group. This will be the top-level "root" node. // Set the type of the listing group to be a biddable unit. ListingGroup = new ListingGroupInfo() { Type = ListingGroupType.Unit }, // Set the bid for products in this listing group unit. CpcBidMicros = 500_000L }; AdGroupCriterionOperation operation = new AdGroupCriterionOperation() { Create = adGroupCriterion }; MutateAdGroupCriterionResult mutateAdGroupCriteriaResult = adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(), new AdGroupCriterionOperation[] { operation }).Results[0]; Console.WriteLine("Added an ad group criterion containing a listing group with " + "resource name: '{0}'.", mutateAdGroupCriteriaResult.ResourceName); return(mutateAdGroupCriteriaResult.ResourceName); }
/// <summary> /// Creates child nodes on level 1, partitioned by the hotel class info. /// </summary> /// <param name="customerId">The Google Ads customer ID.</param> /// <param name="adGroupId">The ad group ID to which the hotel listing group will be /// added.</param> /// <param name="rootResourceName">The string resource name of the listing group's root node.</param> /// <param name="operations">A list of AdGroupCriterionOperations.</param> /// <param name="percentCpcBidMicroAmount">The CPC bid micro amount to be set on created /// ad group criteria.</param> /// <returns>The string resource name of the "other hotel classes" node, which serves as the /// parent node for the next level of the listing tree.</returns> private string AddLevel1Nodes(long customerId, long adGroupId, string rootResourceName, List <AdGroupCriterionOperation> operations, long percentCpcBidMicroAmount) { // Create listing dimension info for 5-star class hotels. ListingDimensionInfo fiveStarredListingDimensionInfo = new ListingDimensionInfo { HotelClass = new HotelClassInfo { Value = 5 } }; // Create a listing group info for 5-star hotels as a UNIT node. ListingGroupInfo fiveStarredUnit = CreateListingGroupInfo(ListingGroupType.Unit, rootResourceName, fiveStarredListingDimensionInfo); // Create an ad group criterion for 5-star hotels. AdGroupCriterion fiveStarredAdGroupCriterion = CreateAdGroupCriterion(customerId, adGroupId, fiveStarredUnit, percentCpcBidMicroAmount); // Create an operation and add it to the list of operations. operations.Add(new AdGroupCriterionOperation { Create = fiveStarredAdGroupCriterion }); // Decrement the temp ID for the next ad group criterion. nextTempId--; // You can also create more UNIT nodes for other hotel classes by copying the above code // in this method and modifying the value passed to HotelClassInfo(). // For instance, passing 4 instead of 5 in the above code will instead create a UNIT // node of 4-star hotels. // Create hotel class info and dimension info for other hotel classes by *not* // specifying any attributes on those object. ListingDimensionInfo otherHotelsListingDimensionInfo = new ListingDimensionInfo { HotelClass = new HotelClassInfo() }; // Create listing group info for other hotel classes as a SUBDIVISION node, which will // be used as a parent node for children nodes of the next level. ListingGroupInfo otherHotelsSubdivisionListingGroupInfo = CreateListingGroupInfo (ListingGroupType.Subdivision, rootResourceName, otherHotelsListingDimensionInfo); // Create an ad group criterion for other hotel classes. AdGroupCriterion otherHotelsAdGroupCriterion = CreateAdGroupCriterion(customerId, adGroupId, otherHotelsSubdivisionListingGroupInfo, percentCpcBidMicroAmount); // Create an operation and add it to the list of operations. operations.Add(new AdGroupCriterionOperation { Create = otherHotelsAdGroupCriterion }); // Decrement the temp ID for the next ad group criterion. nextTempId--; return(otherHotelsAdGroupCriterion.ResourceName); }