Exemplo n.º 1
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.v201506.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;
    }
    /// <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];
    }
Exemplo n.º 3
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.v201506.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>();

      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;
    }