/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="adGroupId1">ID of the first ad group to which ad customizers are added. /// </param> /// <param name="adGroupId2">ID of the second ad group to which ad customizers are added. /// </param> public void Run(GoogleAdsClient client, long customerId, long adGroupId1, long adGroupId2) { // Get the AdGroupBidModifierService. AdGroupBidModifierServiceClient adGroupBidModifierService = client.GetService(Services.V3.AdGroupBidModifierService); string feedName = "Ad Customizer example feed " + ExampleUtilities.GetRandomString(); // Create a feed to be used as the ad customizer. string adCustomizerFeedResourceName = CreateAdCustomizerFeed(client, customerId, feedName); // Retrieve the attributes for the newly created feed. Dictionary <string, FeedAttribute> adCustomizerFeedAttributes = GetFeedAttributes(client, customerId, adCustomizerFeedResourceName); // Map the feed to the ad customizer placeholder type to mark it as an ad customizer. CreateAdCustomizerMapping(client, customerId, adCustomizerFeedResourceName, adCustomizerFeedAttributes); // Create the feed items that will fill the placeholders in the ads customized by the feed. List <string> feedItemResourceNames = CreateFeedItems(client, customerId, adCustomizerFeedResourceName, adCustomizerFeedAttributes); // Create a feed item targeting to associate the feed items with specific ad groups to // prevent them from being used in other ways. CreateFeedItemTargets(client, customerId, new[] { adGroupId1, adGroupId2 }, feedItemResourceNames); // Create ads with the customizations provided by the feed items. CreateAdsWithCustomizations(client, customerId, new[] { adGroupId1, adGroupId2 }, feedName); }
/// <summary>Snippet for GetAdGroupBidModifier</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetAdGroupBidModifier() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER]/adGroupBidModifiers/[AD_GROUP_BID_MODIFIER]"; // Make the request AdGroupBidModifier response = adGroupBidModifierServiceClient.GetAdGroupBidModifier(resourceName); }
/// <summary>Snippet for GetAdGroupBidModifier</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetAdGroupBidModifierResourceNames() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) AdGroupBidModifierName resourceName = AdGroupBidModifierName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"); // Make the request AdGroupBidModifier response = adGroupBidModifierServiceClient.GetAdGroupBidModifier(resourceName); }
/// <summary>Snippet for GetAdGroupBidModifierAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task GetAdGroupBidModifierAsync() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER_ID]/adGroupBidModifiers/[AD_GROUP_ID]~[CRITERION_ID]"; // Make the request AdGroupBidModifier response = await adGroupBidModifierServiceClient.GetAdGroupBidModifierAsync(resourceName); }
/// <summary>Snippet for GetAdGroupBidModifierAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task GetAdGroupBidModifierResourceNamesAsync() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) AdGroupBidModifierName resourceName = AdGroupBidModifierName.FromCustomerAdGroupBidModifier("[CUSTOMER]", "[AD_GROUP_BID_MODIFIER]"); // Make the request AdGroupBidModifier response = await adGroupBidModifierServiceClient.GetAdGroupBidModifierAsync(resourceName); }
/// <summary>Snippet for GetAdGroupBidModifier</summary> public void GetAdGroupBidModifierResourceNames() { // Snippet: GetAdGroupBidModifier(AdGroupBidModifierName, CallSettings) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) AdGroupBidModifierName resourceName = AdGroupBidModifierName.FromCustomerAdGroupBidModifier("[CUSTOMER]", "[AD_GROUP_BID_MODIFIER]"); // Make the request AdGroupBidModifier response = adGroupBidModifierServiceClient.GetAdGroupBidModifier(resourceName); // End snippet }
/// <summary>Snippet for GetAdGroupBidModifier</summary> public void GetAdGroupBidModifier() { // Snippet: GetAdGroupBidModifier(string, CallSettings) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER_ID]/adGroupBidModifiers/[AD_GROUP_ID]~[CRITERION_ID]"; // Make the request AdGroupBidModifier response = adGroupBidModifierServiceClient.GetAdGroupBidModifier(resourceName); // End snippet }
/// <summary>Snippet for GetAdGroupBidModifier</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetAdGroupBidModifierRequestObject() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) GetAdGroupBidModifierRequest request = new GetAdGroupBidModifierRequest { ResourceNameAsAdGroupBidModifierName = AdGroupBidModifierName.FromCustomerAdGroupBidModifier("[CUSTOMER]", "[AD_GROUP_BID_MODIFIER]"), }; // Make the request AdGroupBidModifier response = adGroupBidModifierServiceClient.GetAdGroupBidModifier(request); }
/// <summary>Snippet for GetAdGroupBidModifierAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task GetAdGroupBidModifierRequestObjectAsync() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) GetAdGroupBidModifierRequest request = new GetAdGroupBidModifierRequest { ResourceNameAsAdGroupBidModifierName = AdGroupBidModifierName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"), }; // Make the request AdGroupBidModifier response = await adGroupBidModifierServiceClient.GetAdGroupBidModifierAsync(request); }
/// <summary>Snippet for MutateAdGroupBidModifiers</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateAdGroupBidModifiers() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) string customerId = ""; IEnumerable <AdGroupBidModifierOperation> operations = new AdGroupBidModifierOperation[] { new AdGroupBidModifierOperation(), }; // Make the request MutateAdGroupBidModifiersResponse response = adGroupBidModifierServiceClient.MutateAdGroupBidModifiers(customerId, operations); }
/// <summary>Snippet for GetAdGroupBidModifierAsync</summary> public async Task GetAdGroupBidModifierResourceNamesAsync() { // Snippet: GetAdGroupBidModifierAsync(AdGroupBidModifierName, CallSettings) // Additional: GetAdGroupBidModifierAsync(AdGroupBidModifierName, CancellationToken) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) AdGroupBidModifierName resourceName = AdGroupBidModifierName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"); // Make the request AdGroupBidModifier response = await adGroupBidModifierServiceClient.GetAdGroupBidModifierAsync(resourceName); // End snippet }
/// <summary>Snippet for GetAdGroupBidModifierAsync</summary> public async Task GetAdGroupBidModifierAsync() { // Snippet: GetAdGroupBidModifierAsync(string, CallSettings) // Additional: GetAdGroupBidModifierAsync(string, CancellationToken) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER_ID]/adGroupBidModifiers/[AD_GROUP_ID]~[CRITERION_ID]"; // Make the request AdGroupBidModifier response = await adGroupBidModifierServiceClient.GetAdGroupBidModifierAsync(resourceName); // End snippet }
/// <summary>Snippet for GetAdGroupBidModifier</summary> public void GetAdGroupBidModifierRequestObject() { // Snippet: GetAdGroupBidModifier(GetAdGroupBidModifierRequest, CallSettings) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) GetAdGroupBidModifierRequest request = new GetAdGroupBidModifierRequest { ResourceNameAsAdGroupBidModifierName = AdGroupBidModifierName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"), }; // Make the request AdGroupBidModifier response = adGroupBidModifierServiceClient.GetAdGroupBidModifier(request); // End snippet }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="adGroupId">ID of the ad group where the bid modifier will be added. /// </param> /// <param name="bidModifierValue">The value of the bid modifier to add.</param> public void Run(GoogleAdsClient client, long customerId, long adGroupId, double bidModifierValue) { // Get the AdGroupBidModifierService. AdGroupBidModifierServiceClient adGroupBidModifierService = client.GetService(Services.V4.AdGroupBidModifierService); // Creates an ad group bid modifier for mobile devices with the specified ad group // ID and bid modifier value. AdGroupBidModifier adGroupBidModifier = new AdGroupBidModifier() { AdGroup = ResourceNames.AdGroup(customerId, adGroupId), BidModifier = bidModifierValue, Device = new DeviceInfo() { Type = Device.Mobile } }; // Creates an ad group bid modifier operation for creating an ad group bid modifier. AdGroupBidModifierOperation adGroupBidModifierOperation = new AdGroupBidModifierOperation() { Create = adGroupBidModifier }; // Send the operation in a mutate request. try { MutateAdGroupBidModifiersResponse response = adGroupBidModifierService.MutateAdGroupBidModifiers(customerId.ToString(), new AdGroupBidModifierOperation[] { adGroupBidModifierOperation }); Console.WriteLine("Added {0} ad group bid modifiers:", response.Results.Count); foreach (MutateAdGroupBidModifierResult result in response.Results) { Console.WriteLine($"\t{result.ResourceName}"); } } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary>Snippet for GetAdGroupBidModifierAsync</summary> public async Task GetAdGroupBidModifierRequestObjectAsync() { // Snippet: GetAdGroupBidModifierAsync(GetAdGroupBidModifierRequest, CallSettings) // Additional: GetAdGroupBidModifierAsync(GetAdGroupBidModifierRequest, CancellationToken) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) GetAdGroupBidModifierRequest request = new GetAdGroupBidModifierRequest { ResourceNameAsAdGroupBidModifierName = AdGroupBidModifierName.FromCustomerAdGroupBidModifier("[CUSTOMER]", "[AD_GROUP_BID_MODIFIER]"), }; // Make the request AdGroupBidModifier response = await adGroupBidModifierServiceClient.GetAdGroupBidModifierAsync(request); // End snippet }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="adGroupIds">ID of the ad groups to which ad customizers are added.</param> public void Run(GoogleAdsClient client, long customerId, long[] adGroupIds) { // Get the AdGroupBidModifierService. AdGroupBidModifierServiceClient adGroupBidModifierService = client.GetService(Services.V10.AdGroupBidModifierService); string feedName = "Ad_Customizer_example_feed_" + ExampleUtilities.GetShortRandomString(); try { // Create a feed to be used as the ad customizer. string adCustomizerFeedResourceName = CreateAdCustomizerFeed(client, customerId, feedName); // Retrieve the attributes for the newly created feed. Dictionary <string, FeedAttribute> adCustomizerFeedAttributes = GetFeedAttributes(client, customerId, adCustomizerFeedResourceName); // Map the feed to the ad customizer placeholder type to mark it as an // ad customizer. CreateAdCustomizerMapping(client, customerId, adCustomizerFeedResourceName, adCustomizerFeedAttributes); // Create the feed items that will fill the placeholders in the ads customized by // the feed. List <string> feedItemResourceNames = CreateFeedItems(client, customerId, adCustomizerFeedResourceName, adCustomizerFeedAttributes); // Create a feed item targeting to associate the feed items with specific // ad groups to prevent them from being used in other ways. CreateFeedItemTargets(client, customerId, adGroupIds, feedItemResourceNames); // Create ads with the customizations provided by the feed items. CreateAdsWithCustomizations(client, customerId, adGroupIds, feedName); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary>Snippet for MutateAdGroupBidModifiers</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateAdGroupBidModifiersRequestObject() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) MutateAdGroupBidModifiersRequest request = new MutateAdGroupBidModifiersRequest { CustomerId = "", Operations = { new AdGroupBidModifierOperation(), }, PartialFailure = false, ValidateOnly = false, }; // Make the request MutateAdGroupBidModifiersResponse response = adGroupBidModifierServiceClient.MutateAdGroupBidModifiers(request); }
/// <summary>Snippet for MutateAdGroupBidModifiersAsync</summary> public async Task MutateAdGroupBidModifiersAsync() { // Snippet: MutateAdGroupBidModifiersAsync(string, IEnumerable<AdGroupBidModifierOperation>, CallSettings) // Additional: MutateAdGroupBidModifiersAsync(string, IEnumerable<AdGroupBidModifierOperation>, CancellationToken) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) string customerId = ""; IEnumerable <AdGroupBidModifierOperation> operations = new AdGroupBidModifierOperation[] { new AdGroupBidModifierOperation(), }; // Make the request MutateAdGroupBidModifiersResponse response = await adGroupBidModifierServiceClient.MutateAdGroupBidModifiersAsync(customerId, operations); // End snippet }
/// <summary>Snippet for MutateAdGroupBidModifiersAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task MutateAdGroupBidModifiersRequestObjectAsync() { // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) MutateAdGroupBidModifiersRequest request = new MutateAdGroupBidModifiersRequest { CustomerId = "", Operations = { new AdGroupBidModifierOperation(), }, PartialFailure = false, ValidateOnly = false, ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified, }; // Make the request MutateAdGroupBidModifiersResponse response = await adGroupBidModifierServiceClient.MutateAdGroupBidModifiersAsync(request); }
/// <summary>Snippet for MutateAdGroupBidModifiers</summary> public void MutateAdGroupBidModifiersRequestObject() { // Snippet: MutateAdGroupBidModifiers(MutateAdGroupBidModifiersRequest, CallSettings) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = AdGroupBidModifierServiceClient.Create(); // Initialize request argument(s) MutateAdGroupBidModifiersRequest request = new MutateAdGroupBidModifiersRequest { CustomerId = "", Operations = { new AdGroupBidModifierOperation(), }, PartialFailure = false, ValidateOnly = false, ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified, }; // Make the request MutateAdGroupBidModifiersResponse response = adGroupBidModifierServiceClient.MutateAdGroupBidModifiers(request); // End snippet }
/// <summary>Snippet for MutateAdGroupBidModifiersAsync</summary> public async Task MutateAdGroupBidModifiersRequestObjectAsync() { // Snippet: MutateAdGroupBidModifiersAsync(MutateAdGroupBidModifiersRequest, CallSettings) // Additional: MutateAdGroupBidModifiersAsync(MutateAdGroupBidModifiersRequest, CancellationToken) // Create client AdGroupBidModifierServiceClient adGroupBidModifierServiceClient = await AdGroupBidModifierServiceClient.CreateAsync(); // Initialize request argument(s) MutateAdGroupBidModifiersRequest request = new MutateAdGroupBidModifiersRequest { CustomerId = "", Operations = { new AdGroupBidModifierOperation(), }, PartialFailure = false, ValidateOnly = false, }; // Make the request MutateAdGroupBidModifiersResponse response = await adGroupBidModifierServiceClient.MutateAdGroupBidModifiersAsync(request); // End snippet }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="adGroupId">The ad group to which bid modifiers are set.</param> public void Run(GoogleAdsClient client, long customerId, long adGroupId) { // Get the AdGroupBidModifierService. AdGroupBidModifierServiceClient service = client.GetService( Services.V2.AdGroupBidModifierService); // Constructs the ad group resource name to use for each bid modifier. string adGroupResourceName = ResourceNames.AdGroup(customerId, adGroupId); // 1) Create an ad group bid modifier based on the hotel check-in day. AdGroupBidModifier checkInDayAdGroupBidModifier = new AdGroupBidModifier() { // Sets the resource name to the ad group resource name joined with the criterion // ID whose value corresponds to the desired check-in day. AdGroup = adGroupResourceName, HotelCheckInDay = new HotelCheckInDayInfo() { DayOfWeek = DayOfWeek.Monday }, // Set the bid modifier value to 150%. BidModifier = 1.5, }; // Creates an ad group bid modifier operation. var checkInDayAdGroupBidModifierOperation = new AdGroupBidModifierOperation() { Create = checkInDayAdGroupBidModifier }; // 2) Create an ad group bid modifier based on the hotel length of stay. AdGroupBidModifier lengthOfStayAdGroupBidModifier = new AdGroupBidModifier() { // Set the ad group. AdGroup = ResourceNames.AdGroup(customerId, adGroupId), // Set the hotel length of stay info. HotelLengthOfStay = new HotelLengthOfStayInfo() { MinNights = 3, MaxNights = 7 }, // Set the bid modifier value to 170%. BidModifier = 1.7 }; // Create an ad group bid modifier operation. var lengthOfStayAdGroupBidModifierOperation = new AdGroupBidModifierOperation() { Create = lengthOfStayAdGroupBidModifier }; try { // Issue a mutate request to add an ad group bid modifiers. MutateAdGroupBidModifiersResponse response = service.MutateAdGroupBidModifiers( customerId.ToString(), new AdGroupBidModifierOperation[] { checkInDayAdGroupBidModifierOperation, lengthOfStayAdGroupBidModifierOperation } ); // Display the resource names of the added ad group bid modifiers. Console.WriteLine($"Added {response.Results.Count} hotel ad group bid modifiers:"); foreach (MutateAdGroupBidModifierResult result in response.Results) { Console.WriteLine($"- {result.ResourceName}"); } } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); } }