/// <summary> /// Creates a new criterion containing a subdivision listing group node. /// </summary> /// <param name="customerId">The client customer ID.</param> /// <param name="adGroupId">The ID of the ad group.</param> /// <param name="adGroupCriterionId">The ID of the criterion. This value will used to /// construct the resource name. This can be a negative number if the criterion is yet to /// be created.</param> /// <param name="parentAdGroupCriterionResourceName">The resource name of the parent of /// this criterion.</param> /// <param name="listingDimensionInfo">The ListingDimensionInfo to be set for this listing /// group.</param> /// <returns>The ad group criterion object that contains the subdivision listing group /// node.</returns> private AdGroupCriterion CreateListingGroupSubdivision(long customerId, long adGroupId, long adGroupCriterionId, String parentAdGroupCriterionResourceName, ListingDimensionInfo listingDimensionInfo) { String adGroupCriterionResourceName = ResourceNames.AdGroupCriterion( customerId, adGroupId, adGroupCriterionId); AdGroupCriterion adGroupCriterion = new AdGroupCriterion() { // The resource name the criterion will be created with. This will define the // ID for the ad group criterion. ResourceName = adGroupCriterionResourceName, Status = AdGroupCriterionStatus.Enabled, ListingGroup = new ListingGroupInfo() { Type = ListingGroupType.Subdivision, // Set the ad group criterion resource name for the parent listing group. // This can include a criterion ID if the parent criterion is not yet created. // Use StringValue to convert from a String to a compatible argument type. ParentAdGroupCriterion = parentAdGroupCriterionResourceName, // Case values contain the listing dimension used for the node. CaseValue = listingDimensionInfo } }; return(adGroupCriterion); }
/// <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 a new criterion containing a biddable unit listing group node. /// </summary> /// <param name="customerId">The client customer ID.</param> /// <param name="adGroupId">The ID of the ad group.</param> /// <param name="parentAdGroupCriterionResourceName">The resource name of the parent of /// this criterion.</param> /// <param name="listingDimensionInfo">The ListingDimensionInfo to be set for this listing /// group.</param> /// <param name="cpcBidMicros">The CPC bid for items in this listing group. This value /// should be specified in micros.</param> /// <returns>The ad group criterion object that contains the biddable unit listing group /// node.</returns> private AdGroupCriterion CreateListingGroupUnitBiddable(long customerId, long adGroupId, String parentAdGroupCriterionResourceName, ListingDimensionInfo listingDimensionInfo, long cpcBidMicros) { String adGroupResourceName = ResourceNames.AdGroup(customerId, adGroupId); AdGroupCriterion adGroupCriterion = new AdGroupCriterion() { // The resource name the ad group the listing group node will be attached to unit. // Note: Listing group units do not require temporary IDs if ad group resource name // and parentAdGroupCriterionResourceName are specified. To use temporary IDs for // unit criteria, use ResourceName property. AdGroup = adGroupResourceName, Status = AdGroupCriterionStatus.Enabled, ListingGroup = new ListingGroupInfo() { // Set the type as a UNIT, which will allow the group to be biddable Type = ListingGroupType.Unit, // Set the ad group criterion resource name for the parent listing group. // This can include a criterion ID if the parent criterion is not yet created. // Use StringValue to convert from a String to a compatible argument type. ParentAdGroupCriterion = parentAdGroupCriterionResourceName, // Case values contain the listing dimension used for the node. CaseValue = listingDimensionInfo }, // Set the bid for this listing group unit. // This will be used as the CPC bid for items that are included in this // listing group CpcBidMicros = cpcBidMicros }; return(adGroupCriterion); }
/// <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 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); }