Beispiel #1
0
        /// <summary>
        /// Creates the Shopping campaign.
        /// </summary>
        /// <param name="user">The AdWords user for which the campaign is created.</param>
        /// <param name="budgetId">The budget ID.</param>
        /// <param name="merchantId">The Merchant Center ID.</param>
        /// <returns>The newly created Shopping campaign.</returns>
        private static Campaign CreateCampaign(AdWordsUser user, long budgetId, long merchantId)
        {
            using (CampaignService campaignService =
                       (CampaignService)user.GetService(AdWordsService.v201802.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
                {
                    // Showcase ads require either ManualCpc or EnhancedCpc.
                    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]);
            }
        }
Beispiel #2
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.v201607.BudgetService);

            // Get the CampaignService.
            CampaignService campaignService =
                (CampaignService)user.GetService(AdWordsService.v201607.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);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a test campaign for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="channelType">The advertising channel type for this
        /// campaign.</param>
        /// <param name="strategyType">The bidding strategy to be used for
        /// this campaign.</param>
        /// <param name="isMobile">True, if this campaign is mobile-only, false
        /// otherwise.</param>
        /// <param name="isDsa">True, if this campaign is for DSA, false
        /// otherwise.</param>
        /// <returns>The campaign id.</returns>
        public long CreateCampaign(AdWordsUser user, AdvertisingChannelType channelType,
                                   BiddingStrategyType strategyType, bool isMobile, bool isDsa)
        {
            CampaignService campaignService =
                (CampaignService)user.GetService(AdWordsService.v201705.CampaignService);

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

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

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

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

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

            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>
        /// 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.v201506.BudgetService);

            // Get the CampaignService.
            CampaignService campaignService =
                (CampaignService)user.GetService(AdWordsService.v201506.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;

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

                // 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);
            }
        }
        /// <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.v201509.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);
        }
Beispiel #6
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.v201802.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.appVendor    = MobileApplicationVendor.VENDOR_GOOGLE_MARKET;
                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);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Updates the campaign DSA setting to add DSA pagefeeds.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The Campaign ID.</param>
        /// <param name="feedId">The page feed ID.</param>
        private static void UpdateCampaignDsaSetting(AdWordsUser user, long campaignId, long feedId)
        {
            using (CampaignService campaignService = (CampaignService)user.GetService(
                       AdWordsService.v201710.CampaignService)) {
                Selector selector = new Selector()
                {
                    fields     = new string[] { Campaign.Fields.Id, Campaign.Fields.Settings },
                    predicates = new Predicate[] {
                        Predicate.Equals(Campaign.Fields.Id, campaignId)
                    },
                    paging = Paging.Default
                };

                CampaignPage page = campaignService.get(selector);

                if (page == null || page.entries == null || page.entries.Length == 0)
                {
                    throw new System.ApplicationException(string.Format(
                                                              "Failed to retrieve campaign with ID = {0}.", campaignId));
                }
                Campaign campaign = page.entries[0];

                if (campaign.settings == null)
                {
                    throw new System.ApplicationException("This is not a DSA campaign.");
                }

                DynamicSearchAdsSetting dsaSetting = null;
                Setting[] campaignSettings         = campaign.settings;

                for (int i = 0; i < campaign.settings.Length; i++)
                {
                    Setting setting = campaignSettings[i];
                    if (setting is DynamicSearchAdsSetting)
                    {
                        dsaSetting = (DynamicSearchAdsSetting)setting;
                        break;
                    }
                }

                if (dsaSetting == null)
                {
                    throw new System.ApplicationException("This is not a DSA campaign.");
                }

                // Use a page feed to specify precisely which URLs to use with your
                // Dynamic Search Ads.
                dsaSetting.pageFeed = new PageFeed()
                {
                    feedIds = new long[] {
                        feedId
                    },
                };

                // Optional: Specify whether only the supplied URLs should be used with your
                // Dynamic Search Ads.
                dsaSetting.useSuppliedUrlsOnly = true;

                Campaign campaignToUpdate = new Campaign();
                campaignToUpdate.id       = campaignId;
                campaignToUpdate.settings = campaignSettings;

                CampaignOperation operation = new CampaignOperation();
                operation.operand   = campaignToUpdate;
                operation.@operator = Operator.SET;

                try {
                    CampaignReturnValue retval = campaignService.mutate(
                        new CampaignOperation[] { operation });
                    Campaign updatedCampaign = retval.value[0];
                    Console.WriteLine("DSA page feed for campaign ID '{0}' was updated with feed ID '{1}'.",
                                      updatedCampaign.id, feedId);
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to set page feed for campaign.", e);
                }
            }
        }
        public IHttpActionResult DeleteCampaign(int id)
        {
            CampaignReturnValue camp = Adwords.Campaigns.SetCampaignStatus(new AdWordsUser(), id, CampaignStatus.REMOVED);

            return(Ok(camp));
        }
        public IHttpActionResult CreateCampaign([FromBody] CampaignLo campaignDto)
        {
            CampaignReturnValue camp = Adwords.Campaigns.CreateCampaign(new AdWordsUser(), campaignDto);

            return(Ok(camp));
        }
Beispiel #10
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);
            }
        }
Beispiel #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.v201802.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);
                }
            }
        }
        /// <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.v201802.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);
                }
            }
        }