Esempio n. 1
0
        /// <summary>
        /// Creates a Shopping dynamic remarketing campaign object (not including ad group level and
        /// below). This creates a Display campaign with the merchant center feed attached.
        /// Merchant Center is used for the product information in combination with a user list
        /// which contains hits with <code>ecomm_prodid</code> specified. See
        /// <a href="https://developers.google.com/adwords-remarketing-tag/parameters#retail">
        /// the guide</a> for more detail.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="merchantId">The ID of the Merchant Center account.</param>
        /// <param name="budgetId">The ID of the budget to use for the campaign.</param>
        /// <returns>The campaign that was created.</returns>
        private static Campaign CreateCampaign(AdWordsUser user, long merchantId, long budgetId)
        {
            using (CampaignService campaignService =
                       (CampaignService)user.GetService(AdWordsService.v201802.CampaignService)) {
                Campaign campaign = new Campaign {
                    name = "Shopping campaign #" + ExampleUtilities.GetRandomString(),
                    // Dynamic remarketing campaigns are only available on the Google Display Network.
                    advertisingChannelType = AdvertisingChannelType.DISPLAY,
                    status = CampaignStatus.PAUSED
                };

                Budget budget = new Budget {
                    budgetId = budgetId
                };
                campaign.budget = budget;

                // This example uses a Manual CPC bidding strategy, but you should select the strategy
                // that best aligns with your sales goals. More details here:
                //   https://support.google.com/adwords/answer/2472725
                BiddingStrategyConfiguration biddingStrategyConfiguration =
                    new BiddingStrategyConfiguration {
                    biddingStrategyType = BiddingStrategyType.MANUAL_CPC
                };
                campaign.biddingStrategyConfiguration = biddingStrategyConfiguration;

                ShoppingSetting setting = new ShoppingSetting {
                    // Campaigns with numerically higher priorities take precedence over those with lower
                    // priorities.
                    campaignPriority = 0,

                    // Set the Merchant Center account ID from which to source products.
                    merchantId = merchantId,

                    // Display Network campaigns do not support partition by country. The only supported
                    // value is "ZZ". This signals that products from all countries are available in the
                    // campaign. The actual products which serve are based on the products tagged in the
                    // user list entry.
                    salesCountry = "ZZ",

                    // Optional: Enable local inventory ads (items for sale in physical stores.)
                    enableLocal = true,

                    // Optional: Declare whether purchases are only made on the merchant store, or
                    // completed on Google.
                    purchasePlatform = ShoppingPurchasePlatform.MERCHANT
                };

                campaign.settings = new Setting[] { setting };

                CampaignOperation op = new CampaignOperation {
                    operand   = campaign,
                    @operator = Operator.ADD
                };

                CampaignReturnValue result = campaignService.mutate(new CampaignOperation[] { op });
                return(result.value[0]);
            }
        }
        /// <summary>
        /// Creates the Shopping campaign.
        /// </summary>
        /// <param name="user">The AdWords user for which the campaign is created.</param>
        /// <param name="budgetId">The budget ID.</param>
        /// <param name="merchantId">The Merchant Center ID.</param>
        /// <returns>The newly created Shopping campaign.</returns>
        private static Campaign CreateCampaign(AdWordsUser user, long budgetId, long merchantId)
        {
            using (CampaignService campaignService = (CampaignService)user.GetService(
                       AdWordsService.v201806.CampaignService)) {
                // Create the campaign.
                Campaign campaign = new Campaign {
                    name = "Shopping campaign #" + ExampleUtilities.GetRandomString(),

                    // The advertisingChannelType is what makes this a Shopping campaign.
                    advertisingChannelType = AdvertisingChannelType.SHOPPING,

                    // 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,

                    // Set shared budget (required).
                    budget = new Budget {
                        budgetId = budgetId
                    }
                };

                // Set bidding strategy (required).
                BiddingStrategyConfiguration biddingStrategyConfiguration =
                    new BiddingStrategyConfiguration {
                    // Note: Showcase ads require that the campaign has a ManualCpc
                    // BiddingStrategyConfiguration.
                    biddingStrategyType = BiddingStrategyType.MANUAL_CPC
                };

                campaign.biddingStrategyConfiguration = biddingStrategyConfiguration;

                // All Shopping campaigns need a ShoppingSetting.
                ShoppingSetting shoppingSetting = new ShoppingSetting {
                    salesCountry     = "US",
                    campaignPriority = 0,
                    merchantId       = merchantId,

                    // Set to "true" to enable Local Inventory Ads in your campaign.
                    enableLocal = true
                };
                campaign.settings = new Setting[] { shoppingSetting };

                // Create operation.
                CampaignOperation campaignOperation = new CampaignOperation {
                    operand   = campaign,
                    @operator = Operator.ADD
                };

                // Make the mutate request.
                CampaignReturnValue retval = campaignService.mutate(
                    new CampaignOperation[] { campaignOperation });
                return(retval.value[0]);
            }
        }
        /// <summary>
        /// Creates the shopping campaign.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="budgetId">The budget id.</param>
        /// <param name="merchantId">The Merchant Center id.</param>
        /// <returns>The Shopping campaign.</returns>
        private static Campaign CreateCampaign(AdWordsUser user, long budgetId, long merchantId)
        {
            CampaignService campaignService = (CampaignService)user.GetService(
                AdWordsService.v201710.CampaignService);

            // Create campaign.
            Campaign campaign = new Campaign();

            campaign.name = "Shopping campaign #" + ExampleUtilities.GetRandomString();

            // The advertisingChannelType is what makes this a Shopping campaign.
            campaign.advertisingChannelType = AdvertisingChannelType.SHOPPING;

            // 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.
            campaign.status = CampaignStatus.PAUSED;

            // Set shared budget (required).
            campaign.budget          = new Budget();
            campaign.budget.budgetId = budgetId;

            // Set bidding strategy (required).
            BiddingStrategyConfiguration biddingStrategyConfiguration =
                new BiddingStrategyConfiguration();

            biddingStrategyConfiguration.biddingStrategyType = BiddingStrategyType.MANUAL_CPC;

            campaign.biddingStrategyConfiguration = biddingStrategyConfiguration;

            // All Shopping campaigns need a ShoppingSetting.
            ShoppingSetting shoppingSetting = new ShoppingSetting();

            shoppingSetting.salesCountry     = "US";
            shoppingSetting.campaignPriority = 0;
            shoppingSetting.merchantId       = merchantId;

            // Set to "true" to enable Local Inventory Ads in your campaign.
            shoppingSetting.enableLocal = true;
            campaign.settings           = new Setting[] { shoppingSetting };

            // Create operation.
            CampaignOperation campaignOperation = new CampaignOperation();

            campaignOperation.operand   = campaign;
            campaignOperation.@operator = Operator.ADD;

            // Make the mutate request.
            CampaignReturnValue retval = campaignService.mutate(
                new CampaignOperation[] { campaignOperation });

            campaignService.Close();
            return(retval.value[0]);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a test campaign for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="biddingStrategy">The bidding strategy to be used.</param>
        /// <returns>The campaign id.</returns>
        public long CreateCampaign(AdWordsUser user, AdvertisingChannelType channelType,
                                   BiddingStrategyType strategyType)
        {
            CampaignService campaignService =
                (CampaignService)user.GetService(AdWordsService.v201406.CampaignService);

            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();

            biddingConfig.biddingStrategyType = strategyType;

            CampaignOperation campaignOperation = new CampaignOperation();

            campaignOperation.@operator    = Operator.ADD;
            campaignOperation.operand      = new Campaign();
            campaignOperation.operand.name =
                string.Format("Campaign {0}", DateTime.Now.ToString("yyyy-M-d H:m:s.ffffff"));
            campaignOperation.operand.advertisingChannelType = channelType;
            campaignOperation.operand.status = CampaignStatus.PAUSED;
            campaignOperation.operand.biddingStrategyConfiguration = biddingConfig;
            campaignOperation.operand.budget                    = new Budget();
            campaignOperation.operand.budget.budgetId           = CreateBudget(user);
            campaignOperation.operand.budget.period             = BudgetBudgetPeriod.DAILY;
            campaignOperation.operand.budget.amount             = new Money();
            campaignOperation.operand.budget.amount.microAmount = 100000000;
            campaignOperation.operand.budget.deliveryMethod     = BudgetBudgetDeliveryMethod.STANDARD;

            List <Setting>      settings     = new List <Setting>();
            KeywordMatchSetting matchSetting = new KeywordMatchSetting();

            matchSetting.optIn = true;
            settings.Add(matchSetting);

            if (channelType == AdvertisingChannelType.SHOPPING)
            {
                // All Shopping campaigns need a ShoppingSetting.
                ShoppingSetting shoppingSetting = new ShoppingSetting();
                shoppingSetting.salesCountry     = "US";
                shoppingSetting.campaignPriority = 0;
                shoppingSetting.merchantId       = (user.Config as AdWordsAppConfig).MerchantCenterId;

                settings.Add(shoppingSetting);
            }
            campaignOperation.operand.settings = settings.ToArray();

            CampaignReturnValue retVal =
                campaignService.mutate(new CampaignOperation[] { campaignOperation });

            return(retVal.value[0].id);
        }
        /// <summary>
        /// Creates the shopping campaign.
        /// </summary>
        /// <param name="budgetId">The budget id.</param>
        /// <param name="merchantId">The Merchant Center id.</param>
        /// <param name="campaignService">The CampaignService instance.</param>
        /// <returns>The Shopping campaign.</returns>
        private static Campaign CreateCampaign(long budgetId, long merchantId,
                                               CampaignService campaignService)
        {
            // Create campaign.
            Campaign campaign = new Campaign();

            campaign.name = "Shopping campaign #" + ExampleUtilities.GetRandomString();
            // The advertisingChannelType is what makes this a Shopping campaign.
            campaign.advertisingChannelType = AdvertisingChannelType.SHOPPING;

            // Set shared budget (required).
            campaign.budget          = new Budget();
            campaign.budget.budgetId = budgetId;

            // Set bidding strategy (required).
            BiddingStrategyConfiguration biddingStrategyConfiguration =
                new BiddingStrategyConfiguration();

            biddingStrategyConfiguration.biddingStrategyType = BiddingStrategyType.MANUAL_CPC;

            campaign.biddingStrategyConfiguration = biddingStrategyConfiguration;

            // Set keyword matching setting (required).
            KeywordMatchSetting keywordMatchSetting = new KeywordMatchSetting();

            keywordMatchSetting.optIn = false;

            // All Shopping campaigns need a ShoppingSetting.
            ShoppingSetting shoppingSetting = new ShoppingSetting();

            shoppingSetting.salesCountry     = "US";
            shoppingSetting.campaignPriority = 0;
            shoppingSetting.merchantId       = merchantId;
            campaign.settings = new Setting[] { keywordMatchSetting, shoppingSetting };

            // Create operation.
            CampaignOperation campaignOperation = new CampaignOperation();

            campaignOperation.operand   = campaign;
            campaignOperation.@operator = Operator.ADD;

            // Make the mutate request.
            CampaignReturnValue retval = campaignService.mutate(
                new CampaignOperation[] { campaignOperation });

            return(retval.value[0]);
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a test campaign for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="channelType">The advertising channel type for this
        /// campaign.</param>
        /// <param name="strategyType">The bidding strategy to be used for
        /// this campaign.</param>
        /// <param name="isMobile">True, if this campaign is mobile-only, false
        /// otherwise.</param>
        /// <returns>The campaign id.</returns>
        public long CreateCampaign(AdWordsUser user, AdvertisingChannelType channelType,
                                   BiddingStrategyType strategyType, bool isMobile)
        {
            CampaignService campaignService =
                (CampaignService)user.GetService(AdWordsService.v201607.CampaignService);

            Campaign campaign = new Campaign()
            {
                name = string.Format("Campaign {0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")),
                advertisingChannelType = channelType,
                status = CampaignStatus.PAUSED,
                biddingStrategyConfiguration = new BiddingStrategyConfiguration()
                {
                    biddingStrategyType = strategyType
                },
                budget = new Budget()
                {
                    budgetId = CreateBudget(user),
                    amount   = new Money()
                    {
                        microAmount = 100000000,
                    },
                    deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD
                }
            };

            if (isMobile)
            {
                switch (campaign.advertisingChannelType)
                {
                case AdvertisingChannelType.SEARCH:
                    campaign.advertisingChannelSubType = AdvertisingChannelSubType.SEARCH_MOBILE_APP;
                    break;

                case AdvertisingChannelType.DISPLAY:
                    campaign.advertisingChannelSubType = AdvertisingChannelSubType.DISPLAY_MOBILE_APP;
                    break;
                }
            }

            List <Setting> settings = new List <Setting>();

            if (channelType == AdvertisingChannelType.SHOPPING)
            {
                // All Shopping campaigns need a ShoppingSetting.
                ShoppingSetting shoppingSetting = new ShoppingSetting()
                {
                    salesCountry     = "US",
                    campaignPriority = 0,
                    merchantId       = (user.Config as AdWordsAppConfig).MerchantCenterId
                };
                settings.Add(shoppingSetting);
            }
            campaign.settings = settings.ToArray();

            CampaignOperation campaignOperation = new CampaignOperation()
            {
                @operator = Operator.ADD,
                operand   = campaign
            };

            CampaignReturnValue retVal =
                campaignService.mutate(new CampaignOperation[] { campaignOperation });

            return(retVal.value[0].id);
        }
        /// <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);
        }
        /// <summary>
        /// Creates a test campaign for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="channelType">The advertising channel type for this
        /// campaign.</param>
        /// <param name="strategyType">The bidding strategy to be used for
        /// this campaign.</param>
        /// <param name="isMobile">True, if this campaign is mobile-only, false
        /// otherwise.</param>
        /// <param name="isDsa">True, if this campaign is for DSA, false
        /// otherwise.</param>
        /// <param name="isGmail">True, if this campaign is for GMail Ads, false
        /// otherwise.</param>
        /// <returns>The campaign id.</returns>
        private long CreateCampaign(AdWordsUser user, AdvertisingChannelType channelType,
                                    BiddingStrategyType strategyType, bool isMobile, bool isDsa, bool isGmail)
        {
            CampaignService campaignService =
                (CampaignService)user.GetService(AdWordsService.v201802.CampaignService);

            Campaign campaign = new Campaign()
            {
                name = string.Format("Campaign {0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")),
                advertisingChannelType = channelType,

                // Set the test campaign to PAUSED when creating it to prevent the ads from serving.
                status = CampaignStatus.PAUSED,

                biddingStrategyConfiguration = new BiddingStrategyConfiguration()
                {
                    biddingStrategyType = strategyType
                },
                budget = new Budget()
                {
                    budgetId = CreateBudget(user),
                    amount   = new Money()
                    {
                        microAmount = 100000000,
                    },
                    deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD
                }
            };

            // Campaign setups that cannot be inferred just from AdvertisingChannelType uses flags.
            List <Setting> settings = new List <Setting>();

            // The following flags are all mutually exclusive for the purpose of testing.
            if (isMobile)
            {
                switch (campaign.advertisingChannelType)
                {
                case AdvertisingChannelType.SEARCH:
                    campaign.advertisingChannelSubType = AdvertisingChannelSubType.SEARCH_MOBILE_APP;
                    break;

                case AdvertisingChannelType.DISPLAY:
                    campaign.advertisingChannelSubType = AdvertisingChannelSubType.DISPLAY_MOBILE_APP;
                    break;
                }
            }
            else if (isDsa)
            {
                // Required: Set the campaign's Dynamic Search Ads settings.
                DynamicSearchAdsSetting dynamicSearchAdsSetting = new DynamicSearchAdsSetting();

                // Required: Set the domain name and language.
                dynamicSearchAdsSetting.domainName   = "example.com";
                dynamicSearchAdsSetting.languageCode = "en";
                settings.Add(dynamicSearchAdsSetting);
            }
            else if (isGmail)
            {
                campaign.advertisingChannelSubType = AdvertisingChannelSubType.DISPLAY_GMAIL_AD;
            }
            else if (channelType == AdvertisingChannelType.SHOPPING)
            {
                // All Shopping campaigns need a ShoppingSetting.
                ShoppingSetting shoppingSetting = new ShoppingSetting()
                {
                    salesCountry     = "US",
                    campaignPriority = 0,
                    merchantId       = (user.Config as AdWordsAppConfig).MerchantCenterId
                };
                settings.Add(shoppingSetting);
            }

            campaign.settings = settings.ToArray();

            CampaignOperation campaignOperation = new CampaignOperation()
            {
                @operator = Operator.ADD,
                operand   = campaign
            };

            CampaignReturnValue retVal =
                campaignService.mutate(new CampaignOperation[] { campaignOperation });

            return(retVal.value[0].id);
        }
Esempio n. 9
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);
        }
    /// <summary>
    /// Creates the shopping campaign.
    /// </summary>
    /// <param name="budgetId">The budget id.</param>
    /// <param name="merchantId">The Merchant Center id.</param>
    /// <param name="campaignService">The CampaignService instance.</param>
    /// <returns>The Shopping campaign.</returns>
    private static Campaign CreateCampaign(long budgetId, long merchantId,
        CampaignService campaignService) {
      // Create campaign.
      Campaign campaign = new Campaign();
      campaign.name = "Shopping campaign #" + ExampleUtilities.GetRandomString();
      // The advertisingChannelType is what makes this a Shopping campaign.
      campaign.advertisingChannelType = AdvertisingChannelType.SHOPPING;

      // Set shared budget (required).
      campaign.budget = new Budget();
      campaign.budget.budgetId = budgetId;

      // Set bidding strategy (required).
      BiddingStrategyConfiguration biddingStrategyConfiguration =
          new BiddingStrategyConfiguration();
      biddingStrategyConfiguration.biddingStrategyType = BiddingStrategyType.MANUAL_CPC;

      campaign.biddingStrategyConfiguration = biddingStrategyConfiguration;

      // All Shopping campaigns need a ShoppingSetting.
      ShoppingSetting shoppingSetting = new ShoppingSetting();
      shoppingSetting.salesCountry = "US";
      shoppingSetting.campaignPriority = 0;
      shoppingSetting.merchantId = merchantId;

      // Set to "true" to enable Local Inventory Ads in your campaign.
      shoppingSetting.enableLocal = true;
      campaign.settings = new Setting[] { shoppingSetting };

      // Create operation.
      CampaignOperation campaignOperation = new CampaignOperation();
      campaignOperation.operand = campaign;
      campaignOperation.@operator = Operator.ADD;

      // Make the mutate request.
      CampaignReturnValue retval = campaignService.mutate(
          new CampaignOperation[] { campaignOperation });

      return retval.value[0];
    }
Esempio n. 11
0
        /// <summary>
        /// Creates a test campaign for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="channelType">The advertising channel type for this
        /// campaign.</param>
        /// <param param name="strategyType">The bidding strategy to be used for
        /// this campaign.</param>
        /// <param name="isMobile">True, if this campaign is mobile-only, false
        /// otherwise.</param>
        /// <returns>The campaign id.</returns>
        public long CreateCampaign(AdWordsUser user, AdvertisingChannelType channelType,
        BiddingStrategyType strategyType, bool isMobile)
        {
            CampaignService campaignService =
              (CampaignService) user.GetService(AdWordsService.v201601.CampaignService);

              Campaign campaign = new Campaign() {
            name = string.Format("Campaign {0}", DateTime.Now.ToString("yyyy-M-d H:m:s.ffffff")),
            advertisingChannelType = channelType,
            status = CampaignStatus.PAUSED,
            biddingStrategyConfiguration = new BiddingStrategyConfiguration() {
              biddingStrategyType = strategyType
            },
            budget = new Budget() {
              budgetId = CreateBudget(user),
              period = BudgetBudgetPeriod.DAILY,
              amount = new Money() {
            microAmount = 100000000,
              },
              deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD
            }
              };

              if (isMobile) {
            switch (campaign.advertisingChannelType) {
              case AdvertisingChannelType.SEARCH:
            campaign.advertisingChannelSubType = AdvertisingChannelSubType.SEARCH_MOBILE_APP;
            break;

              case AdvertisingChannelType.DISPLAY:
            campaign.advertisingChannelSubType = AdvertisingChannelSubType.DISPLAY_MOBILE_APP;
            break;
            }
              }

              List<Setting> settings = new List<Setting>();

              if (channelType == AdvertisingChannelType.SHOPPING) {
            // All Shopping campaigns need a ShoppingSetting.
            ShoppingSetting shoppingSetting = new ShoppingSetting() {
              salesCountry = "US",
              campaignPriority = 0,
              merchantId = (user.Config as AdWordsAppConfig).MerchantCenterId
            };
            settings.Add(shoppingSetting);
              }
              campaign.settings = settings.ToArray();

              CampaignOperation campaignOperation = new CampaignOperation() {
            @operator = Operator.ADD,
            operand = campaign
              };

              CampaignReturnValue retVal =
              campaignService.mutate(new CampaignOperation[] { campaignOperation });
              return retVal.value[0].id;
        }