/// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The Google Ads user.</param>
        public void Run(AdWordsUser user)
        {
            aw::Budget   budget   = CreateBudget(user);
            aw::Campaign campaign = CreateCampaign(user, budget.budgetId);
            aw::AdGroup  adGroup  = CreateAdGroup(user, campaign.id);

            aw::AdGroupAd[]        adGroupAds      = CreateTextAds(user, adGroup.id);
            aw::AdGroupCriterion[] adGroupCriteria = CreateKeywords(user, adGroup.id,
                                                                    KEYWORDS_TO_ADD);
        }
예제 #2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The Google Ads user.</param>
        /// <param name="client">The Google Ads client.</param>
        public void Run(AdWordsUser user, GoogleAdsClient client)
        {
            // Note: The IDs returned for various entities by both APIs are the same, and can
            // be used interchangeably.
            long customerId = long.Parse((user.Config as AdWordsAppConfig).ClientCustomerId);

            gagvr::CampaignBudget budget = CreateBudget(client,
                                                        long.Parse((user.Config as AdWordsAppConfig).ClientCustomerId));
            aw::Campaign campaign = CreateCampaign(user, budget.Id);
            aw::AdGroup  adGroup  = CreateAdGroup(user, campaign.id);

            aw::AdGroupAd[]        adGroupAds      = CreateTextAds(user, adGroup.id);
            aw::AdGroupCriterion[] adGroupCriteria = CreateKeywords(user, adGroup.id,
                                                                    KEYWORDS_TO_ADD);
        }
        /// <summary>
        /// Creates the campaign.
        /// </summary>
        /// <param name="user">The Google Ads user.</param>
        /// <param name="budgetId">The budget ID.</param>
        /// <returns>The newly created campaign instance.</returns>
        public aw::Campaign CreateCampaign(AdWordsUser user, long budgetId)
        {
            // Get the CampaignService.
            using (aw::CampaignService campaignService =
                       (aw::CampaignService)user.GetService(AdWordsService.v201809.CampaignService))
            {
                // Create the campaign.
                aw::Campaign campaign = new aw::Campaign
                {
                    name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(),
                    advertisingChannelType = aw::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 = aw::CampaignStatus.PAUSED
                };

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

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

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

                // 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.
                aw::CampaignOperation operation = new aw::CampaignOperation
                {
                    @operator = aw::Operator.ADD,
                    operand   = campaign
                };

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

                // Retrieve the newly created campaign.
                aw::Campaign newCampaign = retVal.value[0];

                // Display the results.
                Console.WriteLine($"Campaign with ID={newCampaign.id} and name=" +
                                  $"'{newCampaign.name}' was created.");

                // return the newly created campaign.
                return(newCampaign);
            }
        }