/// <summary>Snippet for AddBatchJobOperationsAsync</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 AddBatchJobOperations2ResourceNamesAsync()
        {
            // Create client
            BatchJobServiceClient batchJobServiceClient = await BatchJobServiceClient.CreateAsync();

            // Initialize request argument(s)
            BatchJobName resourceName = BatchJobName.FromCustomerBatchJob("[CUSTOMER_ID]", "[BATCH_JOB_ID]");
            IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
            {
                new MutateOperation(),
            };
            // Make the request
            AddBatchJobOperationsResponse response = await batchJobServiceClient.AddBatchJobOperationsAsync(resourceName, mutateOperations);
        }
        /// <summary>Snippet for MutateAsync</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 MutateAsync()
        {
            // Create client
            GoogleAdsServiceClient googleAdsServiceClient = await GoogleAdsServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
            {
                new MutateOperation(),
            };
            // Make the request
            MutateGoogleAdsResponse response = await googleAdsServiceClient.MutateAsync(customerId, mutateOperations);
        }
        /// <summary>Snippet for AddBatchJobOperationsAsync</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 AddBatchJobOperations2Async()
        {
            // Create client
            BatchJobServiceClient batchJobServiceClient = await BatchJobServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/batchJobs/[BATCH_JOB]";
            IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
            {
                new MutateOperation(),
            };
            // Make the request
            AddBatchJobOperationsResponse response = await batchJobServiceClient.AddBatchJobOperationsAsync(resourceName, mutateOperations);
        }
Пример #4
0
 /// <summary>Snippet for AddBatchJobOperations</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void AddBatchJobOperations1ResourceNames()
 {
     // Create client
     BatchJobServiceClient batchJobServiceClient = BatchJobServiceClient.Create();
     // Initialize request argument(s)
     BatchJobName resourceName  = BatchJobName.FromCustomerBatchJob("[CUSTOMER_ID]", "[BATCH_JOB_ID]");
     string       sequenceToken = "";
     IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
     {
         new MutateOperation(),
     };
     // Make the request
     AddBatchJobOperationsResponse response = batchJobServiceClient.AddBatchJobOperations(resourceName, sequenceToken, mutateOperations);
 }
 /// <summary>Snippet for AddBatchJobOperations</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void AddBatchJobOperations1()
 {
     // Create client
     BatchJobServiceClient batchJobServiceClient = BatchJobServiceClient.Create();
     // Initialize request argument(s)
     string resourceName  = "customers/[CUSTOMER]/batchJobs/[BATCH_JOB]";
     string sequenceToken = "";
     IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
     {
         new MutateOperation(),
     };
     // Make the request
     AddBatchJobOperationsResponse response = batchJobServiceClient.AddBatchJobOperations(resourceName, sequenceToken, mutateOperations);
 }
 /// <summary>Snippet for AddBatchJobOperations</summary>
 public void AddBatchJobOperations2()
 {
     // Snippet: AddBatchJobOperations(string, IEnumerable<MutateOperation>, CallSettings)
     // Create client
     BatchJobServiceClient batchJobServiceClient = BatchJobServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/batchJobs/[BATCH_JOB]";
     IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
     {
         new MutateOperation(),
     };
     // Make the request
     AddBatchJobOperationsResponse response = batchJobServiceClient.AddBatchJobOperations(resourceName, mutateOperations);
     // End snippet
 }
 /// <summary>Snippet for AddBatchJobOperations</summary>
 public void AddBatchJobOperations2ResourceNames()
 {
     // Snippet: AddBatchJobOperations(BatchJobName, IEnumerable<MutateOperation>, CallSettings)
     // Create client
     BatchJobServiceClient batchJobServiceClient = BatchJobServiceClient.Create();
     // Initialize request argument(s)
     BatchJobName resourceName = BatchJobName.FromCustomerBatchJob("[CUSTOMER]", "[BATCH_JOB]");
     IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
     {
         new MutateOperation(),
     };
     // Make the request
     AddBatchJobOperationsResponse response = batchJobServiceClient.AddBatchJobOperations(resourceName, mutateOperations);
     // End snippet
 }
Пример #8
0
 /// <summary>Snippet for Mutate</summary>
 public void Mutate()
 {
     // Snippet: Mutate(string, IEnumerable<MutateOperation>, CallSettings)
     // Create client
     GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
     {
         new MutateOperation(),
     };
     // Make the request
     MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(customerId, mutateOperations);
     // End snippet
 }
Пример #9
0
        /// <summary>Snippet for AddBatchJobOperationsAsync</summary>
        public async Task AddBatchJobOperations2Async()
        {
            // Snippet: AddBatchJobOperationsAsync(string, IEnumerable<MutateOperation>, CallSettings)
            // Additional: AddBatchJobOperationsAsync(string, IEnumerable<MutateOperation>, CancellationToken)
            // Create client
            BatchJobServiceClient batchJobServiceClient = await BatchJobServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/batchJobs/[BATCH_JOB_ID]";
            IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
            {
                new MutateOperation(),
            };
            // Make the request
            AddBatchJobOperationsResponse response = await batchJobServiceClient.AddBatchJobOperationsAsync(resourceName, mutateOperations);

            // End snippet
        }
        /// <summary>Snippet for AddBatchJobOperationsAsync</summary>
        public async Task AddBatchJobOperations2ResourceNamesAsync()
        {
            // Snippet: AddBatchJobOperationsAsync(BatchJobName, IEnumerable<MutateOperation>, CallSettings)
            // Additional: AddBatchJobOperationsAsync(BatchJobName, IEnumerable<MutateOperation>, CancellationToken)
            // Create client
            BatchJobServiceClient batchJobServiceClient = await BatchJobServiceClient.CreateAsync();

            // Initialize request argument(s)
            BatchJobName resourceName = BatchJobName.FromCustomerBatchJob("[CUSTOMER]", "[BATCH_JOB]");
            IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
            {
                new MutateOperation(),
            };
            // Make the request
            AddBatchJobOperationsResponse response = await batchJobServiceClient.AddBatchJobOperationsAsync(resourceName, mutateOperations);

            // End snippet
        }
Пример #11
0
        /// <summary>Snippet for MutateAsync</summary>
        public async Task MutateAsync()
        {
            // Snippet: MutateAsync(string, IEnumerable<MutateOperation>, CallSettings)
            // Additional: MutateAsync(string, IEnumerable<MutateOperation>, CancellationToken)
            // Create client
            GoogleAdsServiceClient googleAdsServiceClient = await GoogleAdsServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <MutateOperation> mutateOperations = new MutateOperation[]
            {
                new MutateOperation(),
            };
            // Make the request
            MutateGoogleAdsResponse response = await googleAdsServiceClient.MutateAsync(customerId, mutateOperations);

            // End snippet
        }
Пример #12
0
        /// <summary>
        /// Creates the budget for the campaign.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <returns>The resource name of the newly created campaign budget.</returns>
        internal static string CreateBudget(GoogleAdsClient client)
        {
            CampaignBudget budget = new CampaignBudget()
            {
                Name           = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(),
                DeliveryMethod = BudgetDeliveryMethod.Standard,
                AmountMicros   = 500000
            };

            MutateOperation mutateOperation = new MutateOperation()
            {
                CampaignBudgetOperation = new CampaignBudgetOperation()
                {
                    Create = budget,
                },
            };

            return(ExecuteOperations(client, new[] { mutateOperation }).First()
                   .CampaignBudgetResult.ResourceName);
        }
Пример #13
0
        /// <summary>
        /// Creates an ad group ad.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="adGroupResourceName">Resource name of the ad group in which the ad
        /// is created.</param>
        /// <param name="ad">The ad to create.</param>
        /// <returns>The resource name of the newly created ad group ad.</returns>
        internal static string CreateAdGroupAd(GoogleAdsClient client, Ad ad,
                                               string adGroupResourceName)
        {
            AdGroupAd adGroupAd = new AdGroupAd
            {
                AdGroup = adGroupResourceName,
                Status  = AdGroupAdStatus.Paused,
                Ad      = ad
            };

            MutateOperation mutateOperation = new MutateOperation()
            {
                AdGroupAdOperation = new AdGroupAdOperation()
                {
                    Create = adGroupAd
                }
            };

            return(ExecuteOperations(client, new[] { mutateOperation }).First()
                   .AdGroupAdResult.ResourceName);
        }
Пример #14
0
        /// <summary>
        /// Creates the ad group.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="campaignResourceName">Resource name of the campaign in which ad group
        /// is created.</param>
        /// <returns>The resource name of the newly created ad group.</returns>
        internal static string CreateAdGroup(GoogleAdsClient client, string campaignResourceName)
        {
            AdGroup adGroup = new AdGroup()
            {
                Name         = $"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}",
                Status       = AdGroupStatusEnum.Types.AdGroupStatus.Enabled,
                Campaign     = campaignResourceName,
                CpcBidMicros = 10000000
            };

            MutateOperation mutateOperation = new MutateOperation()
            {
                AdGroupOperation = new AdGroupOperation()
                {
                    Create = adGroup
                }
            };

            return(ExecuteOperations(client, new[] { mutateOperation }).First()
                   .AdGroupResult.ResourceName);
        }
        // [END add_performance_max_product_listing_group_tree_7]

        /// <summary>
        /// Prints the details of a MutateGoogleAdsResponse. Parses the "response" oneof field name
        /// and uses it to extract the new entity's name and resource name.
        /// </summary>
        /// <param name="request">A MutateGoogleAdsRequest instance.</param>
        /// <param name="response">A MutateGoogleAdsResponse instance.</param>
        private void PrintResponseDetails(MutateGoogleAdsRequest request, MutateGoogleAdsResponse response)
        {
            // Parse the Mutate response to print details about the entities that were created
            // in the request.
            for (int i = 0; i < response.MutateOperationResponses.Count; i++)
            {
                MutateOperation         operationRequest  = request.MutateOperations[i];
                MutateOperationResponse operationResponse = response.MutateOperationResponses[i];

                if (operationResponse.ResponseCase != MutateOperationResponse.ResponseOneofCase.AssetGroupListingGroupFilterResult)
                {
                    string entityName = operationResponse.ResponseCase.ToString();
                    // Trim the substring "Result" from the end of the entity name.
                    entityName = entityName.Remove(entityName.Length - 6);

                    Console.WriteLine($"Unsupported entity type: {entityName}");
                }

                string resourceName = operationResponse.AssetGroupListingGroupFilterResult.ResourceName;
                AssetGroupListingGroupFilterOperation assetOperation = operationRequest.AssetGroupListingGroupFilterOperation;

                switch (assetOperation.OperationCase)
                {
                case AssetGroupListingGroupFilterOperation.OperationOneofCase.Create:
                    Console.WriteLine(
                        $"Created a(n) AssetGroupListingGroupFilter with resource name: '{resourceName}'.");
                    break;

                case AssetGroupListingGroupFilterOperation.OperationOneofCase.Remove:
                    Console.WriteLine(
                        $"Removed a(n) AssetGroupListingGroupFilter with resource name: '{resourceName}'.");
                    break;

                default:
                    Console.WriteLine($"Unsupported operation type: {assetOperation.OperationCase.ToString()}");
                    continue;
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Creates a keyword.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="adGroupResourceName">The resource name of the ad group to which keyword
        /// is added.</param>
        /// <returns>The resource name of the newly created keyword.</returns>
        internal static string CreateKeyword(GoogleAdsClient client, string adGroupResourceName)
        {
            AdGroupCriterion criterion = new AdGroupCriterion()
            {
                AdGroup = adGroupResourceName,
                Status  = AdGroupCriterionStatus.Enabled,
                Keyword = new KeywordInfo()
                {
                    Text      = $"mars cruise #{DateTime.Now.Ticks}",
                    MatchType = KeywordMatchType.Exact
                }
            };
            MutateOperation mutateOperation = new MutateOperation()
            {
                AdGroupCriterionOperation = new AdGroupCriterionOperation()
                {
                    Create = criterion
                }
            };

            return(ExecuteOperations(client, new[] { mutateOperation }).First()
                   .AdGroupCriterionResult.ResourceName);
        }
Пример #17
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID.</param>
        /// <param name="keywordText">A keyword string used for generating keyword themes.</param>
        /// <param name="freeFormKeywordText">A keyword used to create a free-form keyword theme.
        /// </param>
        /// <param name="businessLocationId">The ID of a Business Profile location.</param>
        /// <param name="businessName">The name of a Business Profile business.</param>
        public void Run(GoogleAdsClient client, long customerId, string keywordText,
                        string freeFormKeywordText, ulong?businessLocationId, string businessName)
        {
            GoogleAdsServiceClient googleAdsServiceClient =
                client.GetService(Services.V10.GoogleAdsService);

            try
            {
                // [START add_smart_campaign_12]
                // Gets the SmartCampaignSuggestionInfo object which acts as the basis for many
                // of the entities necessary to create a Smart campaign. It will be reused a number
                // of times to retrieve suggestions for keyword themes, budget amount, ad
                //creatives, and campaign criteria.
                SmartCampaignSuggestionInfo suggestionInfo =
                    GetSmartCampaignSuggestionInfo(client, businessLocationId, businessName);

                // Generates a list of keyword themes using the SuggestKeywordThemes method on the
                // SmartCampaignSuggestService. It is strongly recommended that you use this
                // strategy for generating keyword themes.
                List <KeywordThemeConstant> keywordThemeConstants =
                    GetKeywordThemeSuggestions(client, customerId, suggestionInfo);

                // Optionally retrieves auto-complete suggestions for the given keyword text and
                // adds them to the list of keyWordThemeConstants.
                if (keywordText != null)
                {
                    keywordThemeConstants.AddRange(GetKeywordTextAutoCompletions(
                                                       client, keywordText));
                }

                // Converts the KeywordThemeConstants to KeywordThemeInfos.
                List <KeywordThemeInfo> keywordThemeInfos = keywordThemeConstants.Select(
                    constant =>
                    new KeywordThemeInfo {
                    KeywordThemeConstant = constant.ResourceName
                })
                                                            .ToList();

                // Optionally includes any freeform keywords verbatim.
                if (freeFormKeywordText != null)
                {
                    keywordThemeInfos.Add(new KeywordThemeInfo()
                    {
                        FreeFormKeywordTheme = freeFormKeywordText
                    });
                }

                // Includes the keyword suggestions in the overall SuggestionInfo object.
                // [START add_smart_campaign_13]
                suggestionInfo.KeywordThemes.Add(keywordThemeInfos);
                // [END add_smart_campaign_13]
                // [END add_smart_campaign_12]

                SmartCampaignAdInfo adSuggestions = GetAdSuggestions(client, customerId,
                                                                     suggestionInfo);

                long suggestedBudgetAmount = GetBudgetSuggestion(client, customerId,
                                                                 suggestionInfo);

                // [START add_smart_campaign_7]
                // The below methods create and return MutateOperations that we later provide to
                // the GoogleAdsService.Mutate method in order to create the entities in a single
                // request. Since the entities for a Smart campaign are closely tied to one-another
                // it's considered a best practice to create them in a single Mutate request; the
                // entities will either all complete successfully or fail entirely, leaving no
                // orphaned entities. See:
                // https://developers.google.com/google-ads/api/docs/mutating/overview
                MutateOperation campaignBudgetOperation =
                    CreateCampaignBudgetOperation(customerId, suggestedBudgetAmount);
                MutateOperation smartCampaignOperation =
                    CreateSmartCampaignOperation(customerId);
                MutateOperation smartCampaignSettingOperation =
                    CreateSmartCampaignSettingOperation(customerId, businessLocationId,
                                                        businessName);
                IEnumerable <MutateOperation> campaignCriterionOperations =
                    CreateCampaignCriterionOperations(customerId, keywordThemeInfos,
                                                      suggestionInfo);
                MutateOperation adGroupOperation   = CreateAdGroupOperation(customerId);
                MutateOperation adGroupAdOperation = CreateAdGroupAdOperation(customerId,
                                                                              adSuggestions);

                // Send the operations in a single mutate request.
                MutateGoogleAdsRequest mutateGoogleAdsRequest = new MutateGoogleAdsRequest
                {
                    CustomerId = customerId.ToString()
                };
                // It's important to create these entities in this order because they depend on
                // each other, for example the SmartCampaignSetting and ad group depend on the
                // campaign, and the ad group ad depends on the ad group.
                mutateGoogleAdsRequest.MutateOperations.Add(campaignBudgetOperation);
                mutateGoogleAdsRequest.MutateOperations.Add(smartCampaignOperation);
                mutateGoogleAdsRequest.MutateOperations.Add(smartCampaignSettingOperation);
                mutateGoogleAdsRequest.MutateOperations.Add(campaignCriterionOperations);
                mutateGoogleAdsRequest.MutateOperations.Add(adGroupOperation);
                mutateGoogleAdsRequest.MutateOperations.Add(adGroupAdOperation);

                MutateGoogleAdsResponse response =
                    googleAdsServiceClient.Mutate(mutateGoogleAdsRequest);

                PrintResponseDetails(response);
                // [END add_smart_campaign_7]
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Пример #18
0
        // [START add_performance_max_campaign_1]
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID.</param>
        /// <param name="audienceId">The optional audience ID.</param>
        public void Run(GoogleAdsClient client, long customerId, long?audienceId)
        {
            try
            {
                // [START add_performance_max_campaign_1]
                GoogleAdsServiceClient googleAdsServiceClient =
                    client.GetService(Services.V10.GoogleAdsService);

                // Performance Max campaigns require that repeated assets such as headlines and
                // descriptions be created before the campaign.
                //
                // For the list of required assets for a Performance Max campaign, see
                // https://developers.google.com/google-ads/api/docs/performance-max/assets
                //
                // Create the headlines.
                List <string> headlineAssetResourceNames = CreateMultipleTextAssets(
                    client,
                    customerId,
                    new[] {
                    "Travel",
                    "Travel Reviews",
                    "Book travel"
                }
                    );

                // Create the descriptions.
                List <string> descriptionAssetResourceNames = CreateMultipleTextAssets(
                    client,
                    customerId,
                    new[] {
                    "Take to the air!",
                    "Fly to the sky!"
                }
                    );

                string tempResourceNameCampaignBudget = ResourceNames.CampaignBudget(
                    customerId,
                    TEMPORARY_ID_BUDGET
                    );

                // The below methods create and return MutateOperations that we later provide to
                // the GoogleAdsService.Mutate method in order to create the entities in a single
                // request. Since the entities for a Performance Max campaign are closely tied to
                // one-another, it is considered a best practice to create them in a single Mutate
                // request so they all complete successfully or fail entirely, leaving no
                // orphaned entities.
                //
                // See: https://developers.google.com/google-ads/api/docs/mutating/overview
                MutateOperation campaignBudgetOperation = CreateCampaignBudgetOperation(
                    tempResourceNameCampaignBudget
                    );

                string tempResourceNameCampaign = ResourceNames.Campaign(
                    customerId,
                    TEMPORARY_ID_CAMPAIGN
                    );

                MutateOperation performanceMaxCampaignOperation =
                    CreatePerformanceMaxCampaignOperation(
                        tempResourceNameCampaign,
                        tempResourceNameCampaignBudget
                        );

                List <MutateOperation> campaignCriterionOperations =
                    CreateCampaignCriterionOperations(tempResourceNameCampaign);

                List <MutateOperation> assetGroupOperations =
                    CreateAssetGroupOperations(
                        tempResourceNameCampaign,
                        ResourceNames.AssetGroup(customerId, TEMPORARY_ID_ASSET_GROUP),
                        headlineAssetResourceNames,
                        descriptionAssetResourceNames,
                        new AssetGroupAssetTemporaryResourceNameGenerator(
                            customerId,
                            TEMPORARY_ID_ASSET_GROUP
                            ),
                        client.Config
                        );

                List <MutateOperation> assetGroupSignalOperations =
                    CreateAssetGroupSignalOperations(
                        customerId,
                        ResourceNames.AssetGroup(customerId, TEMPORARY_ID_ASSET_GROUP),
                        audienceId
                        );

                MutateGoogleAdsRequest request = new MutateGoogleAdsRequest
                {
                    CustomerId = customerId.ToString()
                };

                // It's important to create these entities in this order because they depend on
                // each other.
                //
                // Additionally, we take several lists of operations and flatten them into one
                // large list.
                request.MutateOperations.Add(campaignBudgetOperation);
                request.MutateOperations.Add(performanceMaxCampaignOperation);
                request.MutateOperations.AddRange(campaignCriterionOperations);
                request.MutateOperations.AddRange(assetGroupOperations);
                request.MutateOperations.AddRange(assetGroupSignalOperations);

                MutateGoogleAdsResponse response = googleAdsServiceClient.Mutate(request);

                PrintResponseDetails(response);
                // [END add_performance_max_campaign_1]
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Пример #19
0
        // [END add_performance_max_campaign_2]

        // [START add_performance_max_campaign_3]
        /// Creates a MutateOperation that creates a new Performance Max campaign.
        /// <param name="campaignResourceName">The campaign resource name.</param>
        /// <param name="campaignBudgetResourceName">The campaign budget resource name.</param>
        /// <returns>A MutateOperations that will create this new campaign.</returns>
        private MutateOperation CreatePerformanceMaxCampaignOperation(
            string campaignResourceName,
            string campaignBudgetResourceName)
        {
            MutateOperation operation = new MutateOperation()
            {
                CampaignOperation = new CampaignOperation()
                {
                    Create = new Campaign()
                    {
                        Name = "Performance Max campaign #" + ExampleUtilities.GetRandomString(),

                        // Set the campaign status as PAUSED. The campaign is the only entity in
                        // the mutate request that should have its status set.
                        Status = CampaignStatus.Paused,

                        // All Performance Max campaigns have an AdvertisingChannelType of
                        // PerformanceMax. The AdvertisingChannelSubType should not be set.
                        AdvertisingChannelType = AdvertisingChannelType.PerformanceMax,

                        // Bidding strategy must be set directly on the campaign. Setting a
                        // portfolio bidding strategy by resource name is not supported. Max
                        // Conversion and Maximize Conversion Value are the only strategies
                        // supported for Performance Max campaigns. BiddingStrategyTYpe is
                        // read-only and cannot be set by the API. An optional ROAS (Return on
                        // Advertising Spend) can be set to enable the MaximizeConversionValue
                        // bidding strategy. The ROAS value must be specified as a ratio in the API.
                        // It is calculated by dividing "total value" by "total spend".
                        //
                        // For more information on Maximize Conversion Value, see the support
                        // article:
                        // http://support.google.com/google-ads/answer/7684216.
                        //
                        // A target_roas of 3.5 corresponds to a 350% return on ad spend.
                        MaximizeConversionValue = new MaximizeConversionValue()
                        {
                            TargetRoas = 3.5
                        },

                        // Set the Final URL expansion opt out. This flag is specific to
                        // Performance Max campaigns. If opted out (True), only the final URLs in
                        // the asset group or URLs specified in the advertiser's Google Merchant
                        // Center or business data feeds are targeted.
                        // If opted in (False), the entire domain will be targeted. For best
                        // results, set this value to false to opt in and allow URL expansions. You
                        // can optionally add exclusions to limit traffic to parts of your website.
                        UrlExpansionOptOut = false,

                        // Use the temporary resource name created earlier
                        ResourceName = campaignResourceName,

                        // Set the budget using the given budget resource name.
                        CampaignBudget = campaignBudgetResourceName,

                        // Optional fields
                        StartDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd"),
                        EndDate   = DateTime.Now.AddDays(365).ToString("yyyyMMdd")
                    }
                }
            };

            return(operation);
        }
Пример #20
0
        // [END add_performance_max_campaign_3]

        // [START add_performance_max_campaign_4]
        /// <summary>
        /// Creates a list of MutateOperations that create new campaign criteria.
        /// </summary>
        /// <param name="campaignResourceName">The campaign resource name.</param>
        /// <returns>A list of MutateOperations that create new campaign criteria.</returns>
        private List <MutateOperation> CreateCampaignCriterionOperations(
            string campaignResourceName)
        {
            List <MutateOperation> operations = new List <MutateOperation>();

            // Set the LOCATION campaign criteria.
            // Target all of New York City except Brooklyn.
            // Location IDs are listed here:
            // https://developers.google.com/google-ads/api/reference/data/geotargets
            // and they can also be retrieved using the GeoTargetConstantService as shown
            // here: https://developers.google.com/google-ads/api/docs/targeting/location-targeting
            //
            // We will add one positive location target for New York City (ID=1023191)
            // and one negative location target for Brooklyn (ID=1022762).
            // First, add the positive (negative = False) for New York City.
            MutateOperation operation1 = new MutateOperation()
            {
                CampaignCriterionOperation = new CampaignCriterionOperation()
                {
                    Create = new CampaignCriterion()
                    {
                        Campaign = campaignResourceName,
                        Location = new LocationInfo()
                        {
                            GeoTargetConstant = ResourceNames.GeoTargetConstant(1023191)
                        },

                        Negative = false
                    }
                }
            };

            operations.Add(operation1);

            // Next add the negative target for Brooklyn.
            MutateOperation operation2 = new MutateOperation()
            {
                CampaignCriterionOperation = new CampaignCriterionOperation()
                {
                    Create = new CampaignCriterion()
                    {
                        Campaign = campaignResourceName,
                        Location = new LocationInfo()
                        {
                            GeoTargetConstant = ResourceNames.GeoTargetConstant(1022762)
                        },

                        Negative = true
                    }
                }
            };

            operations.Add(operation2);

            // Set the LANGUAGE campaign criterion.
            MutateOperation operation3 = new MutateOperation()
            {
                CampaignCriterionOperation = new CampaignCriterionOperation()
                {
                    Create = new CampaignCriterion()
                    {
                        Campaign = campaignResourceName,

                        // Set the language.
                        // For a list of all language codes, see:
                        // https://developers.google.com/google-ads/api/reference/data/codes-formats#expandable-7
                        Language = new LanguageInfo()
                        {
                            LanguageConstant = ResourceNames.LanguageConstant(1000) // English
                        },
                    }
                }
            };

            operations.Add(operation3);

            return(operations);
        }