コード例 #1
0
        /// <summary>
        ///  Creates a new standard shopping campaign in the specified client account.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="budgetResourceName">The resource name of the budget for the campaign.
        /// </param>
        /// <param name="merchantCenterAccountId">The Merchant Center account ID.</param>
        /// <returns>Resource name of the newly created campaign.</returns>
        /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more
        /// service errors.</exception>
        // [START add_shopping_product_ad_2]
        private string AddStandardShoppingCampaign(GoogleAdsClient client, long customerId,
                                                   string budgetResourceName, long merchantCenterAccountId)
        {
            // Get the CampaignService.
            CampaignServiceClient campaignService =
                client.GetService(Services.V10.CampaignService);

            // Configures the shopping settings.
            ShoppingSetting shoppingSetting = new ShoppingSetting()
            {
                // Sets the sales country of products to include in the campaign.
                SalesCountry = "US",

                // Sets the priority of the campaign. Higher numbers take priority over lower
                // numbers. For Shopping Product Ad campaigns, allowed values are between 0 and 2,
                // inclusive.
                CampaignPriority = 0,

                MerchantId = merchantCenterAccountId,

                // Enables local inventory ads for this campaign.
                EnableLocal = true
            };

            // Create the standard shopping campaign.
            Campaign campaign = new Campaign()
            {
                Name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(),

                // Configures settings related to shopping campaigns including advertising channel
                // type and shopping setting.
                AdvertisingChannelType = AdvertisingChannelType.Shopping,

                ShoppingSetting = shoppingSetting,

                // Recommendation: Set the campaign to PAUSED when creating it to prevent
                // the ads from immediately serving. Set to ENABLED once you've added
                // targeting and the ads are ready to serve
                Status = CampaignStatus.Paused,

                // Sets the bidding strategy to Manual CPC (with eCPC enabled)
                // Recommendation: Use one of the automated bidding strategies for Shopping
                // campaigns to help you optimize your advertising spend. More information can be
                // found here: https://support.google.com/google-ads/answer/6309029
                ManualCpc = new ManualCpc()
                {
                    EnhancedCpcEnabled = true
                },

                // Sets the budget.
                CampaignBudget = budgetResourceName
            };

            // Creates a campaign operation.
            CampaignOperation operation = new CampaignOperation()
            {
                Create = campaign
            };

            // Issues a mutate request to add the campaign.
            MutateCampaignsResponse response =
                campaignService.MutateCampaigns(customerId.ToString(),
                                                new CampaignOperation[] { operation });
            MutateCampaignResult result = response.Results[0];

            Console.WriteLine("Added a standard shopping campaign with resource name: '{0}'.",
                              result.ResourceName);
            return(result.ResourceName);
        }
コード例 #2
0
        /// <summary>
        ///  Creates a new shopping campaign for Smart Shopping ads in the specified client account.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="budgetResourceName">The resource name of the budget for the campaign.
        /// </param>
        /// <param name="merchantCenterAccountId">The Merchant Center account ID.</param>
        /// <returns>Resource name of the newly created campaign.</returns>
        /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more
        /// service errors.</exception>
        // [START AddShoppingSmartAd_3]
        private string AddSmartShoppingCampaign(GoogleAdsClient client, long customerId,
                                                string budgetResourceName, long merchantCenterAccountId)
        {
            // Get the CampaignService.
            CampaignServiceClient campaignService =
                client.GetService(Services.V6.CampaignService);

            // Configures the shopping settings.
            ShoppingSetting shoppingSetting = new ShoppingSetting()
            {
                // Sets the sales country of products to include in the campaign.
                SalesCountry = "US",
                MerchantId   = merchantCenterAccountId,
            };

            // [START AddShoppingSmartAd]
            // Create the standard shopping campaign.
            Campaign campaign = new Campaign()
            {
                Name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(),

                // Configures settings related to shopping campaigns including advertising channel
                // type, sub-type and shopping setting.
                AdvertisingChannelType    = AdvertisingChannelType.Shopping,
                AdvertisingChannelSubType = AdvertisingChannelSubType.ShoppingSmartAds,

                ShoppingSetting = shoppingSetting,

                // Recommendation: Set the campaign to PAUSED when creating it to prevent
                // the ads from immediately serving. Set to ENABLED once you've added
                // targeting and the ads are ready to serve
                Status = CampaignStatus.Paused,

                // Bidding strategy must be set directly on the campaign.
                // Setting a portfolio bidding strategy by resourceName is not supported.
                // Maximize conversion value is the only strategy supported for Smart Shopping
                // campaigns.
                // An optional ROAS (Return on Advertising Spend) can be set for
                // MaximizeConversionValue.
                // The ROAS value must be specified as a ratio in the API. It is calculated by
                // dividingW "total value" by "total spend".
                // For more information on maximize conversion value, see the support article:
                // http://support.google.com/google-ads/answer/7684216)
                MaximizeConversionValue = new MaximizeConversionValue()
                {
                    TargetRoas = 3.5
                },

                // Sets the budget.
                CampaignBudget = budgetResourceName
            };
            // [END AddShoppingSmartAd]

            // Creates a campaign operation.
            CampaignOperation operation = new CampaignOperation()
            {
                Create = campaign
            };

            // Issues a mutate request to add the campaign.
            MutateCampaignsResponse response =
                campaignService.MutateCampaigns(customerId.ToString(),
                                                new CampaignOperation[] { operation });
            MutateCampaignResult result = response.Results[0];

            Console.WriteLine("Added a Smart Shopping campaign with resource name: '{0}'.",
                              result.ResourceName);
            return(result.ResourceName);
        }