/// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="adGroupId">Id of the ad group that contains the keyword.
    /// </param>
    /// <param name="keywordId">Id of the keyword to be updated.</param>
    public void Run(AdWordsUser user, long adGroupId, long keywordId) {
      // Get the AdGroupCriterionService.
      AdGroupCriterionService adGroupCriterionService =
          (AdGroupCriterionService) user.GetService(AdWordsService.v201509.AdGroupCriterionService);

      // Since we are not updating any keyword-specific fields, it is enough to
      // create a criterion object.
      Criterion criterion = new Criterion();
      criterion.id = keywordId;

      // Create ad group criterion.
      BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
      biddableAdGroupCriterion.adGroupId = adGroupId;
      biddableAdGroupCriterion.criterion = criterion;

      // Create the bids.
      BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
      CpcBid cpcBid = new CpcBid();
      cpcBid.bid = new Money();
      cpcBid.bid.microAmount = 1000000;
      biddingConfig.bids = new Bids[] {cpcBid};

      biddableAdGroupCriterion.biddingStrategyConfiguration = biddingConfig;

      // Create the operation.
      AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
      operation.@operator = Operator.SET;
      operation.operand = biddableAdGroupCriterion;

      try {
        // Update the keyword.
        AdGroupCriterionReturnValue retVal =
            adGroupCriterionService.mutate(new AdGroupCriterionOperation[] {operation});

        // Display the results.
        if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
          AdGroupCriterion adGroupCriterion = retVal.value[0];
          long bidAmount = 0;
          foreach (Bids bids in (adGroupCriterion as BiddableAdGroupCriterion).
              biddingStrategyConfiguration.bids) {
            if (bids is CpcBid) {
              bidAmount = (bids as CpcBid).bid.microAmount;
              break;
            }
          }

          Console.WriteLine("Keyword with ad group id = '{0}', id = '{1}' was updated with " +
              "bid amount = '{2}' micros.", adGroupCriterion.adGroupId,
              adGroupCriterion.criterion.id, bidAmount);
        } else {
          Console.WriteLine("No keyword was updated.");
        }
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to update keyword.", e);
      }
    }
Esempio n. 2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group that contains the keyword.
        /// </param>
        /// <param name="keywordId">Id of the keyword to be updated.</param>
        public void Run(AdWordsUser user, long adGroupId, long keywordId)
        {
            using (AdGroupCriterionService adGroupCriterionService =
                (AdGroupCriterionService) user.GetService(AdWordsService.v201809
                    .AdGroupCriterionService))
            {
                // Since we are not updating any keyword-specific fields, it is enough to
                // create a criterion object.
                Criterion criterion = new Criterion
                {
                    id = keywordId
                };

                // Create ad group criterion.
                BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion
                {
                    adGroupId = adGroupId,
                    criterion = criterion
                };

                // Create the bids.
                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
                CpcBid cpcBid = new CpcBid
                {
                    bid = new Money
                    {
                        microAmount = 1000000
                    }
                };
                biddingConfig.bids = new Bids[]
                {
                    cpcBid
                };

                biddableAdGroupCriterion.biddingStrategyConfiguration = biddingConfig;

                // Create the operation.
                AdGroupCriterionOperation operation = new AdGroupCriterionOperation
                {
                    @operator = Operator.SET,
                    operand = biddableAdGroupCriterion
                };

                try
                {
                    // Update the keyword.
                    AdGroupCriterionReturnValue retVal = adGroupCriterionService.mutate(
                        new AdGroupCriterionOperation[]
                        {
                            operation
                        });

                    // Display the results.
                    if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                    {
                        AdGroupCriterion adGroupCriterion = retVal.value[0];
                        long bidAmount = 0;
                        foreach (Bids bids in (adGroupCriterion as BiddableAdGroupCriterion)
                            .biddingStrategyConfiguration.bids)
                        {
                            if (bids is CpcBid)
                            {
                                bidAmount = (bids as CpcBid).bid.microAmount;
                                break;
                            }
                        }

                        Console.WriteLine(
                            "Keyword with ad group id = '{0}', id = '{1}' was updated with " +
                            "bid amount = '{2}' micros.", adGroupCriterion.adGroupId,
                            adGroupCriterion.criterion.id, bidAmount);
                    }
                    else
                    {
                        Console.WriteLine("No keyword was updated.");
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to update keyword.", e);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which ad groups are
        /// added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the AdGroupService.
              AdGroupService adGroupService =
              (AdGroupService) user.GetService(AdWordsService.v201509.AdGroupService);

              List<AdGroupOperation> operations = new List<AdGroupOperation>();

              for (int i = 0; i < NUM_ITEMS; i++) {
            // Create the ad group.
            AdGroup adGroup = new AdGroup();
            adGroup.name = string.Format("Earth to Mars Cruises #{0}",
            ExampleUtilities.GetRandomString());
            adGroup.status = AdGroupStatus.ENABLED;
            adGroup.campaignId = campaignId;

            // Set the ad group bids.
            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();

            CpcBid cpcBid = new CpcBid();
            cpcBid.bid = new Money();
            cpcBid.bid.microAmount = 10000000;

            biddingConfig.bids = new Bids[] {cpcBid};

            adGroup.biddingStrategyConfiguration = biddingConfig;

            // Optional: Set targeting restrictions.
            // Depending on the criterionTypeGroup value, most TargetingSettingDetail
            // only affect Display campaigns. However, the USER_INTEREST_AND_LIST value
            // works for RLSA campaigns - Search campaigns targeting using a
            // remarketing list.
            TargetingSetting targetingSetting = new TargetingSetting();

            // Restricting to serve ads that match your ad group placements.
            // This is equivalent to choosing "Target and bid" in the UI.
            TargetingSettingDetail placementDetail = new TargetingSettingDetail();
            placementDetail.criterionTypeGroup = CriterionTypeGroup.PLACEMENT;
            placementDetail.targetAll = false;

            // Using your ad group verticals only for bidding. This is equivalent
            // to choosing "Bid only" in the UI.
            TargetingSettingDetail verticalDetail = new TargetingSettingDetail();
            verticalDetail.criterionTypeGroup = CriterionTypeGroup.VERTICAL;
            verticalDetail.targetAll = true;

            targetingSetting.details = new TargetingSettingDetail[] {placementDetail, verticalDetail};

            adGroup.settings = new Setting[] {targetingSetting};

            // Create the operation.
            AdGroupOperation operation = new AdGroupOperation();
            operation.@operator = Operator.ADD;
            operation.operand = adGroup;

            operations.Add(operation);
              }

              try {
            // Create the ad group.
            AdGroupReturnValue retVal = adGroupService.mutate(operations.ToArray());

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              foreach (AdGroup newAdGroup in retVal.value) {
            Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.",
                newAdGroup.id, newAdGroup.name);
              }
            } else {
              Console.WriteLine("No ad groups were created.");
            }
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to create ad groups.", e);
              }
        }
Esempio n. 4
0
        /// <summary>
        /// Set custom targeting for the page feed URLs based on a list of labels.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Ad group ID.</param>
        /// <param name="labelName">The label name.</param>
        /// <returns>The newly created webpage criterion.</returns>
        private static BiddableAdGroupCriterion AddDsaTargeting(AdWordsUser user, long adGroupId,
                                                                string labelName)
        {
            using (AdGroupCriterionService adGroupCriterionService =
                       (AdGroupCriterionService)user.GetService(
                           AdWordsService.v201806.AdGroupCriterionService)) {
                // Create a webpage criterion.
                Webpage webpage = new Webpage();

                WebpageParameter parameter = new WebpageParameter {
                    criterionName = "Test criterion"
                };
                webpage.parameter = parameter;

                // Add a condition for label=specified_label_name.
                WebpageCondition condition = new WebpageCondition {
                    operand  = WebpageConditionOperand.CUSTOM_LABEL,
                    argument = labelName
                };
                parameter.conditions = new WebpageCondition[] { condition };

                BiddableAdGroupCriterion criterion = new BiddableAdGroupCriterion {
                    adGroupId = adGroupId,
                    criterion = webpage
                };

                // Set a custom bid for this criterion.
                BiddingStrategyConfiguration biddingStrategyConfiguration =
                    new BiddingStrategyConfiguration {
                    bids = new Bids[] {
                        new CpcBid()
                        {
                            bid = new Money()
                            {
                                microAmount = 1500000
                            }
                        }
                    }
                };

                criterion.biddingStrategyConfiguration = biddingStrategyConfiguration;

                AdGroupCriterionOperation operation = new AdGroupCriterionOperation {
                    operand   = criterion,
                    @operator = Operator.ADD
                };

                try {
                    AdGroupCriterionReturnValue retval = adGroupCriterionService.mutate(
                        new AdGroupCriterionOperation[] { operation });
                    BiddableAdGroupCriterion newCriterion = (BiddableAdGroupCriterion)retval.value[0];

                    Console.WriteLine("Web page criterion with ID = {0} and status = {1} was created.",
                                      newCriterion.criterion.id, newCriterion.userStatus);
                    return(newCriterion);
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create webpage criterion for " +
                                                          "custom page feed label.", e);
                }
            }
        }
Esempio n. 5
0
        public static CampaignReturnValue CreateCampaign(AdWordsUser user, CampaignLo campaignDto)
        {
            using (CampaignService campaignService =
                       (CampaignService)user.GetService(AdWordsService.v201710.CampaignService))
            {
                CampaignReturnValue camp = new CampaignReturnValue();

                Budget budget = Budgets.CreateBudget(user, campaignDto);

                List <CampaignOperation> operations = new List <CampaignOperation>();


                // Create the campaign.
                Campaign campaign = new Campaign();
                campaign.name = campaignDto.Name;
                campaign.advertisingChannelType = AdvertisingChannelType.SEARCH;

                // 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.ENABLED;

                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
                biddingConfig.biddingStrategyType     = BiddingStrategyType.MANUAL_CPC;
                campaign.biddingStrategyConfiguration = biddingConfig;

                campaign.budget          = new Budget();
                campaign.budget.budgetId = budget.budgetId;

                // Set the campaign network options.
                campaign.networkSetting = new NetworkSetting();
                campaign.networkSetting.targetGoogleSearch         = true;
                campaign.networkSetting.targetSearchNetwork        = true;
                campaign.networkSetting.targetContentNetwork       = false;
                campaign.networkSetting.targetPartnerSearchNetwork = false;

                // Set the campaign settings for Advanced location options.
                GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting();
                geoSetting.positiveGeoTargetType = GeoTargetTypeSettingPositiveGeoTargetType.DONT_CARE;
                geoSetting.negativeGeoTargetType = GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE;

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

                // Optional: Set the start date.
                if (Debugger.IsAttached)
                {
                    campaignDto.StartDate = campaignDto.StartDate.AddHours(6);
                }
                campaign.startDate = campaignDto.StartDate.ToString("yyyyMMdd");

                // Optional: Set the end date.
                if (Debugger.IsAttached)
                {
                    campaignDto.EndDate = campaignDto.EndDate.AddHours(6);
                }
                campaign.endDate = campaignDto.EndDate.ToString("yyyyMMdd");

                // Optional: Set the frequency cap.
                FrequencyCap frequencyCap = new FrequencyCap();
                frequencyCap.impressions = 5;
                frequencyCap.level       = Level.ADGROUP;
                frequencyCap.timeUnit    = TimeUnit.DAY;
                campaign.frequencyCap    = frequencyCap;

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

                operations.Add(operation);

                try
                {
                    // Add the campaign.
                    camp = campaignService.mutate(operations.ToArray());
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to add campaigns.", e);
                }
                return(camp);
            }
        }
    /// <summary>
    /// Creates the campaign with a shared bidding strategy.
    /// </summary>
    /// <param name="campaignService">The campaign service.</param>
    /// <param name="name">The campaign name.</param>
    /// <param name="biddingStrategyId">The bidding strategy id.</param>
    /// <param name="sharedBudgetId">The shared budget id.</param>
    /// <returns>The campaign object.</returns>
    private Campaign CreateCampaignWithBiddingStrategy(CampaignService campaignService, string name,
        long biddingStrategyId, long sharedBudgetId) {
      // Create campaign.
      Campaign campaign = new Campaign();
      campaign.name = name;
      campaign.advertisingChannelType = AdvertisingChannelType.SEARCH;

      // Set the budget.
      campaign.budget = new Budget();
      campaign.budget.budgetId = sharedBudgetId;

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

      campaign.biddingStrategyConfiguration = biddingStrategyConfiguration;

      // Set network targeting (recommended).
      NetworkSetting networkSetting = new NetworkSetting();
      networkSetting.targetGoogleSearch = true;
      networkSetting.targetSearchNetwork = true;
      networkSetting.targetContentNetwork = true;
      campaign.networkSetting = networkSetting;

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

      return campaignService.mutate(new CampaignOperation[] {operation}).value[0];
    }
Esempio n. 7
0
        /// <summary>
        /// Adds a web page criterion to target Dynamic Search Ads.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">The ad group ID.</param>
        /// <returns>The newly created web page criterion.</returns>
        private static BiddableAdGroupCriterion AddWebPageCriteria(AdWordsUser user, long adGroupId)
        {
            using (AdGroupCriterionService adGroupCriterionService =
                       (AdGroupCriterionService)user.GetService(AdWordsService.v201809
                                                                .AdGroupCriterionService))
            {
                // Create a webpage criterion for special offers for mars cruise.
                WebpageParameter param = new WebpageParameter
                {
                    criterionName = "Special offers for mars"
                };

                WebpageCondition urlCondition = new WebpageCondition
                {
                    operand  = WebpageConditionOperand.URL,
                    argument = "/marscruise/special"
                };

                WebpageCondition titleCondition = new WebpageCondition
                {
                    operand  = WebpageConditionOperand.PAGE_TITLE,
                    argument = "Special Offer"
                };

                param.conditions = new WebpageCondition[]
                {
                    urlCondition,
                    titleCondition
                };

                Webpage webpage = new Webpage
                {
                    parameter = param
                };

                // Create biddable ad group criterion.
                BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion
                {
                    adGroupId  = adGroupId,
                    criterion  = webpage,
                    userStatus = UserStatus.PAUSED
                };

                // Optional: set a custom bid.
                BiddingStrategyConfiguration biddingStrategyConfiguration =
                    new BiddingStrategyConfiguration();
                CpcBid bid = new CpcBid()
                {
                    bid = new Money()
                    {
                        microAmount = 10000000L
                    }
                };
                biddingStrategyConfiguration.bids = new Bids[]
                {
                    bid
                };
                biddableAdGroupCriterion.biddingStrategyConfiguration =
                    biddingStrategyConfiguration;

                // Create the operation.
                AdGroupCriterionOperation operation = new AdGroupCriterionOperation
                {
                    @operator = Operator.ADD,
                    operand   = biddableAdGroupCriterion
                };

                try
                {
                    AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(
                        new AdGroupCriterionOperation[]
                    {
                        operation
                    });

                    BiddableAdGroupCriterion newCriterion =
                        (BiddableAdGroupCriterion)result.value[0];
                    Console.WriteLine(
                        "Webpage criterion with ID = '{0}' was added to ad group ID '{1}'.",
                        newCriterion.criterion.id, newCriterion.adGroupId);
                    return(newCriterion);
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to create webpage criterion.", e);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates the campaign.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="budget">The campaign budget.</param>
        /// <returns>The newly created campaign.</returns>
        private static Campaign CreateCampaign(AdWordsUser user, Budget budget)
        {
            using (CampaignService campaignService =
                       (CampaignService)user.GetService(AdWordsService.v201809.CampaignService))
            {
                // Create a Dynamic Search Ads campaign.
                Campaign campaign = new Campaign
                {
                    name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(),
                    advertisingChannelType = AdvertisingChannelType.SEARCH,

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

                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration
                {
                    biddingStrategyType = BiddingStrategyType.MANUAL_CPC
                };
                campaign.biddingStrategyConfiguration = biddingConfig;

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

                // Required: Set the campaign's Dynamic Search Ads settings.
                DynamicSearchAdsSetting dynamicSearchAdsSetting = new DynamicSearchAdsSetting
                {
                    // Required: Set the domain name and language.
                    domainName   = "example.com",
                    languageCode = "en"
                };

                // Set the campaign settings.
                campaign.settings = new Setting[]
                {
                    dynamicSearchAdsSetting
                };

                // Optional: Set the start date.
                campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd");

                // Optional: Set the end date.
                campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd");

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

                try
                {
                    // Add the campaign.
                    CampaignReturnValue retVal = campaignService.mutate(new CampaignOperation[]
                    {
                        operation
                    });

                    // Display the results.
                    Campaign newCampaign = retVal.value[0];
                    Console.WriteLine("Campaign with id = '{0}' and name = '{1}' was added.",
                                      newCampaign.id, newCampaign.name);
                    return(newCampaign);
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to add campaigns.", e);
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group to be updated.</param>
        /// <param name="bidMicroAmount">The CPC bid amount in micros.</param>
        public void Run(AdWordsUser user, long adGroupId, long?bidMicroAmount)
        {
            using (AdGroupService adGroupService =
                       (AdGroupService)user.GetService(AdWordsService.v201806.AdGroupService))
            {
                // Create an ad group with the specified ID.
                AdGroup adGroup = new AdGroup
                {
                    id = adGroupId,

                    // Pause the ad group.
                    status = AdGroupStatus.PAUSED
                };

                // Update the CPC bid if specified.
                if (bidMicroAmount != null)
                {
                    BiddingStrategyConfiguration biddingStrategyConfiguration =
                        new BiddingStrategyConfiguration();
                    Money cpcBidMoney = new Money
                    {
                        microAmount = bidMicroAmount.Value
                    };
                    CpcBid cpcBid = new CpcBid
                    {
                        bid = cpcBidMoney
                    };
                    biddingStrategyConfiguration.bids = new Bids[]
                    {
                        cpcBid
                    };
                    adGroup.biddingStrategyConfiguration = biddingStrategyConfiguration;
                }

                // Create the operation.
                AdGroupOperation operation = new AdGroupOperation
                {
                    @operator = Operator.SET,
                    operand   = adGroup
                };

                try
                {
                    // Update the ad group.
                    AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[]
                    {
                        operation
                    });

                    // Display the results.
                    if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                    {
                        AdGroup adGroupResult = retVal.value[0];
                        BiddingStrategyConfiguration bsConfig =
                            adGroupResult.biddingStrategyConfiguration;

                        // Find the CpcBid in the bidding strategy configuration's bids collection.
                        long cpcBidMicros = 0L;
                        if (bsConfig != null && bsConfig.bids != null)
                        {
                            foreach (Bids bid in bsConfig.bids)
                            {
                                if (bid is CpcBid)
                                {
                                    cpcBidMicros = ((CpcBid)bid).bid.microAmount;
                                    break;
                                }
                            }
                        }

                        Console.WriteLine(
                            "Ad group with ID {0} and name '{1}' updated to have status '{2}'" +
                            " and CPC bid {3}", adGroupResult.id, adGroupResult.name,
                            adGroupResult.status, cpcBidMicros);
                    }
                    else
                    {
                        Console.WriteLine("No ad groups were updated.");
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to update ad group.", e);
                }
            }
        }
        /// <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.v201809.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]);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            using (CampaignService campaignService =
                       (CampaignService)user.GetService(AdWordsService.v201710.CampaignService)) {
                // Create the campaign.
                Campaign campaign = new Campaign();
                campaign.name = "Interplanetary Cruise App #" + ExampleUtilities.GetRandomString();

                // 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 the advertising channel and subchannel types for universal app campaigns.
                campaign.advertisingChannelType    = AdvertisingChannelType.MULTI_CHANNEL;
                campaign.advertisingChannelSubType = AdvertisingChannelSubType.UNIVERSAL_APP_CAMPAIGN;

                // Set the campaign's bidding strategy. Universal app campaigns
                // only support TARGET_CPA bidding strategy.
                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
                biddingConfig.biddingStrategyType = BiddingStrategyType.TARGET_CPA;

                // Set the target CPA to $1 / app install.
                TargetCpaBiddingScheme biddingScheme = new TargetCpaBiddingScheme();
                biddingScheme.targetCpa             = new Money();
                biddingScheme.targetCpa.microAmount = 1000000;

                biddingConfig.biddingScheme           = biddingScheme;
                campaign.biddingStrategyConfiguration = biddingConfig;

                // Set the campaign's budget.
                campaign.budget          = new Budget();
                campaign.budget.budgetId = CreateBudget(user).budgetId;

                // Optional: Set the start date.
                campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd");

                // Optional: Set the end date.
                campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd");

                // Set the campaign's assets and ad text ideas. These values will be used to
                // generate ads.
                UniversalAppCampaignSetting universalAppSetting = new UniversalAppCampaignSetting();
                universalAppSetting.appId        = "com.labpixies.colordrips";
                universalAppSetting.description1 = "A cool puzzle game";
                universalAppSetting.description2 = "Remove connected blocks";
                universalAppSetting.description3 = "3 difficulty levels";
                universalAppSetting.description4 = "4 colorful fun skins";

                // Optional: You can set up to 20 image assets for your campaign.
                // See UploadImage.cs for an example on how to upload images.
                //
                // universalAppSetting.imageMediaIds = new long[] { INSERT_IMAGE_MEDIA_ID_HERE };

                // Optimize this campaign for getting new users for your app.
                universalAppSetting.universalAppBiddingStrategyGoalType =
                    UniversalAppBiddingStrategyGoalType.OPTIMIZE_FOR_INSTALL_CONVERSION_VOLUME;

                // Optional: If you select the OPTIMIZE_FOR_IN_APP_CONVERSION_VOLUME goal
                // type, then also specify your in-app conversion types so AdWords can
                // focus your campaign on people who are most likely to complete the
                // corresponding in-app actions.
                // Conversion type IDs can be retrieved using ConversionTrackerService.get.
                //
                // campaign.selectiveOptimization = new SelectiveOptimization();
                // campaign.selectiveOptimization.conversionTypeIds =
                //    new long[] { INSERT_CONVERSION_TYPE_ID_1_HERE, INSERT_CONVERSION_TYPE_ID_2_HERE };

                // Optional: Set the campaign settings for Advanced location options.
                GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting();
                geoSetting.positiveGeoTargetType =
                    GeoTargetTypeSettingPositiveGeoTargetType.LOCATION_OF_PRESENCE;
                geoSetting.negativeGeoTargetType =
                    GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE;

                campaign.settings = new Setting[] { universalAppSetting, geoSetting };

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

                try {
                    // Add the campaign.
                    CampaignReturnValue retVal = campaignService.mutate(
                        new CampaignOperation[] { operation });

                    // Display the results.
                    if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                    {
                        foreach (Campaign newCampaign in retVal.value)
                        {
                            Console.WriteLine("Universal app campaign with name = '{0}' and id = '{1}' " +
                                              "was added.", newCampaign.name, newCampaign.id);

                            // Optional: Set the campaign's location and language targeting. No other targeting
                            // criteria can be used for universal app campaigns.
                            SetCampaignTargetingCriteria(user, newCampaign);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No universal app campaigns were added.");
                    }
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to add universal app campaigns.", e);
                }
            }
        }
            /// <summary>
            /// Creates the unit.
            /// </summary>
            /// <param name="parent">The node that should be this node's parent.
            /// </param>
            /// <param name="value">The value being paritioned on.</param>
            /// <param name="bidAmount">The amount to bid for matching products,
            /// in micros.</param>
            /// <param name="isNegative">True, if this is negative criterion, false
            /// otherwise.</param>
            /// <returns>A new unit node.</returns>
            public ProductPartition CreateUnit(ProductPartition parent, ProductDimension value,
          long bidAmount, bool isNegative)
            {
                ProductPartition unit = new ProductPartition();
                unit.partitionType = ProductPartitionType.UNIT;

                // The root node has neither a parent nor a value.
                if (parent != null) {
                  unit.parentCriterionId = parent.id;
                  unit.caseValue = value;
                }

                AdGroupCriterion criterion;

                if (isNegative) {
                  criterion = new NegativeAdGroupCriterion();
                } else {
                  BiddingStrategyConfiguration biddingStrategyConfiguration =
                  new BiddingStrategyConfiguration();

                  CpcBid cpcBid = new CpcBid();
                  cpcBid.bid = new Money();
                  cpcBid.bid.microAmount = bidAmount;
                  biddingStrategyConfiguration.bids = new Bids[] { cpcBid };

                  criterion = new BiddableAdGroupCriterion();
                  (criterion as BiddableAdGroupCriterion).biddingStrategyConfiguration =
                  biddingStrategyConfiguration;
                }

                criterion.adGroupId = this.adGroupId;
                criterion.criterion = unit;

                this.CreateAddOperation(criterion);

                return unit;
            }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group that contains the placement.
        /// </param>
        /// <param name="placementId">Id of the placement to be updated.</param>
        public void Run(AdWordsUser user, long adGroupId, long placementId)
        {
            // Get the AdGroupCriterionService.
            AdGroupCriterionService adGroupCriterionService =
                (AdGroupCriterionService)user.GetService(AdWordsService.v201506.AdGroupCriterionService);

            // Since we are not updating any placement-specific fields, it is enough to
            // create a criterion object.
            Criterion criterion = new Criterion();

            criterion.CriterionType = "PLACEMENT";
            criterion.id            = placementId;

            // Create ad group criterion.
            BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();

            biddableAdGroupCriterion.adGroupId = adGroupId;
            biddableAdGroupCriterion.criterion = criterion;

            // Create the bids.
            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
            CpmBid cpmBid = new CpmBid();

            cpmBid.bid             = new Money();
            cpmBid.bid.microAmount = 1000000;
            biddingConfig.bids     = new Bids[] { cpmBid };

            biddableAdGroupCriterion.biddingStrategyConfiguration = biddingConfig;

            // Create the operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation();

            operation.@operator = Operator.SET;
            operation.operand   = biddableAdGroupCriterion;

            try {
                // Update the placement.
                AdGroupCriterionReturnValue retVal =
                    adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation });

                // Display the results.
                if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                {
                    AdGroupCriterion adGroupCriterion = retVal.value[0];
                    long             bidAmount        = 0;
                    foreach (Bids bids in (adGroupCriterion as BiddableAdGroupCriterion).
                             biddingStrategyConfiguration.bids)
                    {
                        if (bids is CpmBid)
                        {
                            bidAmount = (bids as CpmBid).bid.microAmount;
                            break;
                        }
                    }
                    Console.WriteLine("Placement with ad group id = '{0}', id = '{1}' was updated with " +
                                      "bid amount = '{2}' micros.", adGroupCriterion.adGroupId,
                                      adGroupCriterion.criterion.id, bidAmount);
                }
                else
                {
                    Console.WriteLine("No placement was updated.");
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to update placement.", e);
            }
        }
    /// <summary>
    /// Constructs a the bidding configuration object corresponding to the node.
    /// </summary>
    /// <returns>The bidding configuration node.</returns>
    /// <remarks>A <code>null</code> may be returned if a bid is not allowed
    /// on this node, or if the bid is not specified.</remarks>
    internal BiddingStrategyConfiguration GetBiddingConfig() {
      BiddingStrategyConfiguration biddingConfig = null;
      if (this.CpcBidSpecified && this.IsUnit) {
        biddingConfig = new BiddingStrategyConfiguration();

        Money bidMoney = new Money() {
          microAmount = this.CpcBid
        };

        CpcBid cpcBid = new CpcBid() {
          bid = bidMoney,
          cpcBidSource = BidSource.CRITERION
        };

        biddingConfig.bids = new Bids[] { cpcBid };
      }
      return biddingConfig;
    }
Esempio n. 15
0
        /// <summary>
        /// Creates a test adgroup for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign id for which the adgroup is created.</param>
        /// <param name="isCpmBid">True, if a ManualCPM bid is to be used.</param>
        /// <returns>The adgroup id.</returns>
        public long CreateAdGroup(AdWordsUser user, long campaignId, bool isCpmBid)
        {
            AdGroupService adGroupService =
              (AdGroupService) user.GetService(AdWordsService.v201601.AdGroupService);

              AdGroupOperation adGroupOperation = new AdGroupOperation();
              adGroupOperation.@operator = Operator.ADD;
              adGroupOperation.operand = new AdGroup();
              adGroupOperation.operand.campaignId = campaignId;
              adGroupOperation.operand.name =
              string.Format("AdGroup {0}", DateTime.Now.ToString("yyyy-M-d H:m:s.ffffff"));
              adGroupOperation.operand.status = AdGroupStatus.ENABLED;

              if (isCpmBid) {
            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
            CpmBid cpmBid = new CpmBid();
            cpmBid.bid = new Money();
            cpmBid.bid.microAmount = 10000000;
            biddingConfig.bids = new Bids[] { cpmBid };
            adGroupOperation.operand.biddingStrategyConfiguration = biddingConfig;
              } else {
            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
            CpcBid cpcBid = new CpcBid();
            cpcBid.bid = new Money();
            cpcBid.bid.microAmount = 10000000;
            biddingConfig.bids = new Bids[] { cpcBid };
            adGroupOperation.operand.biddingStrategyConfiguration = biddingConfig;
              }
              AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] { adGroupOperation });
              return retVal.value[0].id;
        }
Esempio n. 16
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            using (CampaignService campaignService =
                       (CampaignService)user.GetService(AdWordsService.v201806.CampaignService))
            {
                Budget budget = CreateBudget(user);

                List <CampaignOperation> operations = new List <CampaignOperation>();

                for (int i = 0; i < NUM_ITEMS; i++)
                {
                    // Create the campaign.
                    Campaign campaign = new Campaign
                    {
                        name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(),
                        advertisingChannelType = AdvertisingChannelType.SEARCH,

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

                    BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration
                    {
                        biddingStrategyType = BiddingStrategyType.MANUAL_CPC
                    };
                    campaign.biddingStrategyConfiguration = biddingConfig;

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

                    // Set the campaign network options.
                    campaign.networkSetting = new NetworkSetting
                    {
                        targetGoogleSearch         = true,
                        targetSearchNetwork        = true,
                        targetContentNetwork       = false,
                        targetPartnerSearchNetwork = false
                    };

                    // Set the campaign settings for Advanced location options.
                    GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting
                    {
                        positiveGeoTargetType = GeoTargetTypeSettingPositiveGeoTargetType.DONT_CARE,
                        negativeGeoTargetType = GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE
                    };

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

                    // Optional: Set the start date.
                    campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd");

                    // Optional: Set the end date.
                    campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd");

                    // Optional: Set the frequency cap.
                    FrequencyCap frequencyCap = new FrequencyCap
                    {
                        impressions = 5,
                        level       = Level.ADGROUP,
                        timeUnit    = TimeUnit.DAY
                    };
                    campaign.frequencyCap = frequencyCap;

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

                    operations.Add(operation);
                }

                try
                {
                    // Add the campaign.
                    CampaignReturnValue retVal = campaignService.mutate(operations.ToArray());

                    // Display the results.
                    if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                    {
                        foreach (Campaign newCampaign in retVal.value)
                        {
                            Console.WriteLine(
                                "Campaign with name = '{0}' and id = '{1}' was added.",
                                newCampaign.name, newCampaign.id);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No campaigns were added.");
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to add campaigns.", e);
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the BudgetService.
            BudgetService budgetService =
                (BudgetService)user.GetService(AdWordsService.v201705.BudgetService);

            // Get the CampaignService.
            CampaignService campaignService =
                (CampaignService)user.GetService(AdWordsService.v201705.CampaignService);

            // Create the campaign budget.
            Budget budget = new Budget();

            budget.name               = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString();
            budget.deliveryMethod     = BudgetBudgetDeliveryMethod.STANDARD;
            budget.amount             = new Money();
            budget.amount.microAmount = 500000;

            BudgetOperation budgetOperation = new BudgetOperation();

            budgetOperation.@operator = Operator.ADD;
            budgetOperation.operand   = budget;

            try {
                BudgetReturnValue budgetRetval = budgetService.mutate(
                    new BudgetOperation[] { budgetOperation });
                budget = budgetRetval.value[0];
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add shared budget.", e);
            }

            List <CampaignOperation> operations = new List <CampaignOperation>();

            for (int i = 0; i < NUM_ITEMS; i++)
            {
                // Create the campaign.
                Campaign campaign = new Campaign();
                campaign.name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString();
                campaign.advertisingChannelType = AdvertisingChannelType.SEARCH;

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

                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
                biddingConfig.biddingStrategyType     = BiddingStrategyType.MANUAL_CPC;
                campaign.biddingStrategyConfiguration = biddingConfig;

                campaign.budget          = new Budget();
                campaign.budget.budgetId = budget.budgetId;

                // Set the campaign network options.
                campaign.networkSetting = new NetworkSetting();
                campaign.networkSetting.targetGoogleSearch         = true;
                campaign.networkSetting.targetSearchNetwork        = true;
                campaign.networkSetting.targetContentNetwork       = false;
                campaign.networkSetting.targetPartnerSearchNetwork = false;

                // Set the campaign settings for Advanced location options.
                GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting();
                geoSetting.positiveGeoTargetType = GeoTargetTypeSettingPositiveGeoTargetType.DONT_CARE;
                geoSetting.negativeGeoTargetType = GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE;

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

                // Optional: Set the start date.
                campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd");

                // Optional: Set the end date.
                campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd");

                // Optional: Set the campaign ad serving optimization status.
                campaign.adServingOptimizationStatus = AdServingOptimizationStatus.ROTATE;

                // Optional: Set the frequency cap.
                FrequencyCap frequencyCap = new FrequencyCap();
                frequencyCap.impressions = 5;
                frequencyCap.level       = Level.ADGROUP;
                frequencyCap.timeUnit    = TimeUnit.DAY;
                campaign.frequencyCap    = frequencyCap;

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

                operations.Add(operation);
            }

            try {
                // Add the campaign.
                CampaignReturnValue retVal = campaignService.mutate(operations.ToArray());

                // Display the results.
                if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                {
                    foreach (Campaign newCampaign in retVal.value)
                    {
                        Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was added.",
                                          newCampaign.name, newCampaign.id);
                    }
                }
                else
                {
                    Console.WriteLine("No campaigns were added.");
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add campaigns.", e);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the CampaignService.
            BudgetService budgetService =
                (BudgetService)user.GetService(AdWordsService.v201406.BudgetService);

            // Get the CampaignService.
            CampaignService campaignService =
                (CampaignService)user.GetService(AdWordsService.v201406.CampaignService);

            // Create the campaign budget.
            Budget budget = new Budget();

            budget.name               = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString();
            budget.period             = BudgetBudgetPeriod.DAILY;
            budget.deliveryMethod     = BudgetBudgetDeliveryMethod.STANDARD;
            budget.amount             = new Money();
            budget.amount.microAmount = 500000;

            BudgetOperation budgetOperation = new BudgetOperation();

            budgetOperation.@operator = Operator.ADD;
            budgetOperation.operand   = budget;

            try {
                BudgetReturnValue budgetRetval = budgetService.mutate(new BudgetOperation[] { budgetOperation });
                budget = budgetRetval.value[0];
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to add shared budget.", ex);
            }

            List <CampaignOperation> operations = new List <CampaignOperation>();

            for (int i = 0; i < NUM_ITEMS; i++)
            {
                // Create the campaign.
                Campaign campaign = new Campaign();
                campaign.name   = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString();
                campaign.status = CampaignStatus.PAUSED;
                campaign.advertisingChannelType = AdvertisingChannelType.SEARCH;

                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
                biddingConfig.biddingStrategyType = BiddingStrategyType.MANUAL_CPM;

                // Optional: also provide matching bidding scheme.
                biddingConfig.biddingScheme = new ManualCpmBiddingScheme();

                campaign.biddingStrategyConfiguration = biddingConfig;

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

                // Set targetContentNetwork true. Other network targeting is not available
                // for Ad Exchange Buyers.
                campaign.networkSetting = new NetworkSetting();
                campaign.networkSetting.targetGoogleSearch         = false;
                campaign.networkSetting.targetSearchNetwork        = false;
                campaign.networkSetting.targetContentNetwork       = true;
                campaign.networkSetting.targetPartnerSearchNetwork = false;

                // Enable campaign for Real-time bidding.
                RealTimeBiddingSetting rtbSetting = new RealTimeBiddingSetting();
                rtbSetting.optIn = true;

                // Set the campaign settings for near-exact and near-phrase matches.
                KeywordMatchSetting keywordSetting = new KeywordMatchSetting();
                keywordSetting.optIn = false;

                campaign.settings = new Setting[] { rtbSetting, keywordSetting };

                // Optional: Set the start date.
                campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd");

                // Optional: Set the end date.
                campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd");

                // Optional: Set the campaign ad serving optimization status.
                campaign.adServingOptimizationStatus = AdServingOptimizationStatus.ROTATE;

                // Optional: Set the frequency cap.
                FrequencyCap frequencyCap = new FrequencyCap();
                frequencyCap.impressions = 5;
                frequencyCap.level       = Level.ADGROUP;
                frequencyCap.timeUnit    = TimeUnit.DAY;
                campaign.frequencyCap    = frequencyCap;

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

                operations.Add(operation);
            }

            try {
                // Add the campaign.
                CampaignReturnValue retVal = campaignService.mutate(operations.ToArray());

                // Display the results.
                if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                {
                    foreach (Campaign newCampaign in retVal.value)
                    {
                        Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was added.",
                                          newCampaign.name, newCampaign.id);
                    }
                }
                else
                {
                    Console.WriteLine("No campaigns were added.");
                }
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to add campaigns.", ex);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Creates an ad group.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign ID.</param>
        /// <returns>the newly created ad group.</returns>
        private static AdGroup CreateAdGroup(AdWordsUser user, long campaignId)
        {
            using (AdGroupService adGroupService =
                       (AdGroupService)user.GetService(AdWordsService.v201809.AdGroupService))
            {
                // Create the ad group.
                AdGroup adGroup = new AdGroup
                {
                    // Required: Set the ad group's type to Dynamic Search Ads.
                    adGroupType = AdGroupType.SEARCH_DYNAMIC_ADS,

                    name = string.Format("Earth to Mars Cruises #{0}",
                                         ExampleUtilities.GetRandomString()),
                    campaignId = campaignId,
                    status     = AdGroupStatus.PAUSED,

                    // Recommended: Set a tracking URL template for your ad group if you want to use
                    // URL tracking software.
                    trackingUrlTemplate = "http://tracker.example.com/traveltracker/{escapedlpurl}"
                };

                // Set the ad group bids.
                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();

                CpcBid cpcBid = new CpcBid
                {
                    bid = new Money
                    {
                        microAmount = 3000000
                    }
                };

                biddingConfig.bids = new Bids[]
                {
                    cpcBid
                };

                adGroup.biddingStrategyConfiguration = biddingConfig;

                // Create the operation.
                AdGroupOperation operation = new AdGroupOperation
                {
                    @operator = Operator.ADD,
                    operand   = adGroup
                };

                try
                {
                    // Create the ad group.
                    AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[]
                    {
                        operation
                    });

                    // Display the results.
                    AdGroup newAdGroup = retVal.value[0];
                    Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.",
                                      newAdGroup.id, newAdGroup.name);
                    return(newAdGroup);
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to create ad group.", e);
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which ad groups are
        /// added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the AdGroupService.
            AdGroupService adGroupService =
                (AdGroupService)user.GetService(AdWordsService.v201409.AdGroupService);

            List <AdGroupOperation> operations = new List <AdGroupOperation>();

            for (int i = 0; i < NUM_ITEMS; i++)
            {
                // Create the ad group.
                AdGroup adGroup = new AdGroup();
                adGroup.name = string.Format("Earth to Mars Cruises #{0}",
                                             ExampleUtilities.GetRandomString());
                adGroup.status     = AdGroupStatus.ENABLED;
                adGroup.campaignId = campaignId;

                // Set the ad group bids.
                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();

                CpmBid cpmBid = new CpmBid();
                cpmBid.bid             = new Money();
                cpmBid.bid.microAmount = 10000000;

                biddingConfig.bids = new Bids[] { cpmBid };

                adGroup.biddingStrategyConfiguration = biddingConfig;

                // Optional: Set targeting restrictions.
                // These settings only affect serving for the Display Network.
                TargetingSetting targetingSetting = new TargetingSetting();

                TargetingSettingDetail placementDetail = new TargetingSettingDetail();
                placementDetail.criterionTypeGroup = CriterionTypeGroup.PLACEMENT;
                placementDetail.targetAll          = true;

                TargetingSettingDetail verticalDetail = new TargetingSettingDetail();
                verticalDetail.criterionTypeGroup = CriterionTypeGroup.VERTICAL;
                verticalDetail.targetAll          = false;

                targetingSetting.details = new TargetingSettingDetail[] { placementDetail, verticalDetail };

                adGroup.settings = new Setting[] { targetingSetting };

                // Create the operation.
                AdGroupOperation operation = new AdGroupOperation();
                operation.@operator = Operator.ADD;
                operation.operand   = adGroup;

                operations.Add(operation);
            }

            try {
                // Create the ad group.
                AdGroupReturnValue retVal = adGroupService.mutate(operations.ToArray());

                // Display the results.
                if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                {
                    foreach (AdGroup newAdGroup in retVal.value)
                    {
                        Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.",
                                          newAdGroup.id, newAdGroup.name);
                    }
                }
                else
                {
                    Console.WriteLine("No ad groups were created.");
                }
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to create ad groups.", ex);
            }
        }
    /// <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. 22
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which ad groups are
        /// added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the AdGroupService.
            AdGroupService adGroupService =
                (AdGroupService)user.GetService(AdWordsService.v201605.AdGroupService);

            List <AdGroupOperation> operations = new List <AdGroupOperation>();

            for (int i = 0; i < NUM_ITEMS; i++)
            {
                // Create the ad group.
                AdGroup adGroup = new AdGroup();
                adGroup.name = string.Format("Earth to Mars Cruises #{0}",
                                             ExampleUtilities.GetRandomString());
                adGroup.status     = AdGroupStatus.ENABLED;
                adGroup.campaignId = campaignId;

                // Set the ad group bids.
                BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();

                CpcBid cpcBid = new CpcBid();
                cpcBid.bid             = new Money();
                cpcBid.bid.microAmount = 10000000;

                biddingConfig.bids = new Bids[] { cpcBid };

                adGroup.biddingStrategyConfiguration = biddingConfig;

                // Optional: Set targeting restrictions.
                // Depending on the criterionTypeGroup value, most TargetingSettingDetail
                // only affect Display campaigns. However, the USER_INTEREST_AND_LIST value
                // works for RLSA campaigns - Search campaigns targeting using a
                // remarketing list.
                TargetingSetting targetingSetting = new TargetingSetting();

                // Restricting to serve ads that match your ad group placements.
                // This is equivalent to choosing "Target and bid" in the UI.
                TargetingSettingDetail placementDetail = new TargetingSettingDetail();
                placementDetail.criterionTypeGroup = CriterionTypeGroup.PLACEMENT;
                placementDetail.targetAll          = false;

                // Using your ad group verticals only for bidding. This is equivalent
                // to choosing "Bid only" in the UI.
                TargetingSettingDetail verticalDetail = new TargetingSettingDetail();
                verticalDetail.criterionTypeGroup = CriterionTypeGroup.VERTICAL;
                verticalDetail.targetAll          = true;

                targetingSetting.details = new TargetingSettingDetail[] { placementDetail, verticalDetail };

                adGroup.settings = new Setting[] { targetingSetting };

                // Create the operation.
                AdGroupOperation operation = new AdGroupOperation();
                operation.@operator = Operator.ADD;
                operation.operand   = adGroup;

                operations.Add(operation);
            }

            try {
                // Create the ad group.
                AdGroupReturnValue retVal = adGroupService.mutate(operations.ToArray());

                // Display the results.
                if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                {
                    foreach (AdGroup newAdGroup in retVal.value)
                    {
                        Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.",
                                          newAdGroup.id, newAdGroup.name);
                    }
                }
                else
                {
                    Console.WriteLine("No ad groups were created.");
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to create ad groups.", e);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the BudgetService.
              BudgetService budgetService =
              (BudgetService) user.GetService(AdWordsService.v201601.BudgetService);

              // Get the CampaignService.
              CampaignService campaignService =
              (CampaignService) user.GetService(AdWordsService.v201601.CampaignService);

              // Create the campaign budget.
              Budget budget = new Budget();
              budget.name = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString();
              budget.period = BudgetBudgetPeriod.DAILY;
              budget.deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD;
              budget.amount = new Money();
              budget.amount.microAmount = 500000;

              BudgetOperation budgetOperation = new BudgetOperation();
              budgetOperation.@operator = Operator.ADD;
              budgetOperation.operand = budget;

              try {
            BudgetReturnValue budgetRetval = budgetService.mutate(
            new BudgetOperation[] { budgetOperation });
            budget = budgetRetval.value[0];
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to add shared budget.", e);
              }

              List<CampaignOperation> operations = new List<CampaignOperation>();

              for (int i = 0; i < NUM_ITEMS; i++) {
            // Create the campaign.
            Campaign campaign = new Campaign();
            campaign.name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString();
            campaign.status = CampaignStatus.PAUSED;
            campaign.advertisingChannelType = AdvertisingChannelType.SEARCH;

            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
            biddingConfig.biddingStrategyType = BiddingStrategyType.MANUAL_CPC;
            campaign.biddingStrategyConfiguration = biddingConfig;

            campaign.budget = new Budget();
            campaign.budget.budgetId = budget.budgetId;

            // Set the campaign network options.
            campaign.networkSetting = new NetworkSetting();
            campaign.networkSetting.targetGoogleSearch = true;
            campaign.networkSetting.targetSearchNetwork = true;
            campaign.networkSetting.targetContentNetwork = false;
            campaign.networkSetting.targetPartnerSearchNetwork = false;

            // Set the campaign settings for Advanced location options.
            GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting();
            geoSetting.positiveGeoTargetType = GeoTargetTypeSettingPositiveGeoTargetType.DONT_CARE;
            geoSetting.negativeGeoTargetType = GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE;

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

            // Optional: Set the start date.
            campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd");

            // Optional: Set the end date.
            campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd");

            // Optional: Set the campaign ad serving optimization status.
            campaign.adServingOptimizationStatus = AdServingOptimizationStatus.ROTATE;

            // Optional: Set the frequency cap.
            FrequencyCap frequencyCap = new FrequencyCap();
            frequencyCap.impressions = 5;
            frequencyCap.level = Level.ADGROUP;
            frequencyCap.timeUnit = TimeUnit.DAY;
            campaign.frequencyCap = frequencyCap;

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

            operations.Add(operation);
              }

              try {
            // Add the campaign.
            CampaignReturnValue retVal = campaignService.mutate(operations.ToArray());

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              foreach (Campaign newCampaign in retVal.value) {
            Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was added.",
                newCampaign.name, newCampaign.id);
              }
            } else {
              Console.WriteLine("No campaigns were added.");
            }
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to add campaigns.", e);
              }
        }
        /// <summary>
        /// Creates the criterion for product partition.
        /// </summary>
        /// <param name="partitionId">The product partition ID.</param>
        /// <param name="parentPartitionId">The proudct partition ID for parent node.</param>
        /// <param name="caseValue">The case value.</param>
        /// <param name="isUnit">True, if the node is UNIT node, false otherwise.</param>
        /// <param name="isExcluded">True, if the node is EXCLUDE node, false otherwise.</param>
        /// <param name="bid">The bid to be set on a node, if it is UNIT.</param>
        /// <returns>An ad group criterion node for the product partition.</returns>
        internal static AdGroupCriterion CreateCriterionForProductPartition(long partitionId,
        long parentPartitionId, ProductDimension caseValue, bool isUnit, bool isExcluded,
        long bid)
        {
            AdGroupCriterion adGroupCriterion;
              ProductPartition partition = new ProductPartition() {
            id = partitionId,
            parentCriterionId = parentPartitionId,
            caseValue = caseValue,
            partitionType = isUnit ? ProductPartitionType.UNIT : ProductPartitionType.SUBDIVISION
              };

              if (isExcluded) {
            NegativeAdGroupCriterion negative = new NegativeAdGroupCriterion();
            adGroupCriterion = negative;
              } else {
            BiddableAdGroupCriterion biddable = new BiddableAdGroupCriterion();
            biddable.userStatus = UserStatus.ENABLED;

            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
            if (isUnit && bid != 0) {
              CpcBid cpcBid = new CpcBid() {
            bid = new Money() {
              microAmount = bid
            },
            cpcBidSource = BidSource.CRITERION
              };
              biddingConfig.bids = new Bids[] { cpcBid };
            }
            biddable.biddingStrategyConfiguration = biddingConfig;
            adGroupCriterion = biddable;
              }
              adGroupCriterion.criterion = partition;
              return adGroupCriterion;
        }