コード例 #1
0
        /// <summary>
        /// Adds the campaign targeting criteria to a campaign.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="campaignId">The campaign id.</param>
        /// <returns>The campaign criteria id.</returns>
        public long AddCampaignTargetingCriteria(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201406.CampaignCriterionService);

            // Create language criteria.
            // See http://code.google.com/apis/adwords/docs/appendix/languagecodes.html
            // for a detailed list of language codes.
            Language language1 = new Language();

            language1.id = 1002; // French
            CampaignCriterion languageCriterion1 = new CampaignCriterion();

            languageCriterion1.campaignId = campaignId;
            languageCriterion1.criterion  = language1;

            CampaignCriterion[] criteria = new CampaignCriterion[] { languageCriterion1 };

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

            foreach (CampaignCriterion criterion in criteria)
            {
                CampaignCriterionOperation operation = new CampaignCriterionOperation();
                operation.@operator = Operator.ADD;
                operation.operand   = criterion;
                operations.Add(operation);
            }

            CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray());

            return(retVal.value[0].criterion.id);
        }
コード例 #2
0
    /// <summary>
    /// Sets the campaign's targeting criteria.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="campaign">The campaign for which targeting criteria is
    /// created.</param>
    private void SetCampaignTargetingCriteria(AdWordsUser user, Campaign campaign) {
      using (CampaignCriterionService campaignCriterionService =
          (CampaignCriterionService) user.GetService(
              AdWordsService.v201802.CampaignCriterionService)) {

        // Create locations. The IDs can be found in the documentation or
        // retrieved with the LocationCriterionService.
        Location california = new Location() {
          id = 21137L
        };

        Location mexico = new Location() {
          id = 2484L
        };

        // Create languages. The IDs can be found in the documentation or
        // retrieved with the ConstantDataService.
        Language english = new Language() {
          id = 1000L
        };

        Language spanish = new Language() {
          id = 1003L
        };

        List<Criterion> criteria = new List<Criterion>() {
        california, mexico, english, spanish };

        // Create operations to add each of the criteria above.
        List<CampaignCriterionOperation> operations = new List<CampaignCriterionOperation>();
        foreach (Criterion criterion in criteria) {
          CampaignCriterionOperation operation = new CampaignCriterionOperation() {
            operand = new CampaignCriterion() {
              campaignId = campaign.id,
              criterion = criterion
            },
            @operator = Operator.ADD
          };

          operations.Add(operation);
        }

        // Set the campaign targets.
        CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(
            operations.ToArray());

        if (retVal != null && retVal.value != null) {
          // Display the added campaign targets.
          foreach (CampaignCriterion criterion in retVal.value) {
            Console.WriteLine("Campaign criteria of type '{0}' and id '{1}' was added.",
                              criterion.criterion.CriterionType, criterion.criterion.id);
          }
        }
      }
    }
コード例 #3
0
        public UpdateGeoTargetsResponse UpdateCampaignGeoTargets(string campaignId, UpdateGeoTargetsRequest updateGeoTargetsRequest)
        {
            UpdateGeoTargetsResponse updateResponse = new UpdateGeoTargetsResponse()
            {
                Success = true
            };

            Operator action = Operator.ADD;

            if (updateGeoTargetsRequest.UpdateMode == UpdateMode.Remove)
            {
                action = Operator.REMOVE;
            }

            List <KeyValuePair <string, string> > pairs = ExtractCityStatePairsFromRequets(updateGeoTargetsRequest);

            CampaignCriterionService campaignCriterionService = (CampaignCriterionService)_adwordsUser.GetService(AdWordsService.v201708.CampaignCriterionService);

            List <GeoTarget> targets = _locationNameHelper.GetTargetIdsByLocationNames(pairs);

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

            foreach (GeoTarget target in targets)
            {
                Location location = new Location()
                {
                    id = Convert.ToInt64(target.Id)
                };
                CampaignCriterionOperation operation         = new CampaignCriterionOperation();
                CampaignCriterion          campaignCriterion = new CampaignCriterion();
                campaignCriterion.campaignId            = Convert.ToInt64(campaignId);
                campaignCriterion.criterion             = location;
                campaignCriterion.CampaignCriterionType = "Location";
                operation.operand   = campaignCriterion;
                operation.@operator = action;
                operations.Add(operation);
            }

            try
            {
                CampaignCriterionReturnValue result = campaignCriterionService.mutate(operations.ToArray());
            }
            catch (Exception ex)
            {
                var exception = ex.Message;
                updateResponse.Success = false;
            }

            return(updateResponse);
        }
コード例 #4
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the campaign whose bid should be modified.
        /// </param>
        /// <param name="bidModifier">The bid modifier.</param>
        public void Run(AdWordsUser user, long campaignId, double bidModifier)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201409.CampaignCriterionService);

            // Create mobile platform. The ID can be found in the documentation.
            // https://developers.google.com/adwords/api/docs/appendix/platforms
            Platform mobile = new Platform();

            mobile.id = 30001;

            // Create criterion with modified bid.
            CampaignCriterion criterion = new CampaignCriterion();

            criterion.campaignId  = campaignId;
            criterion.criterion   = mobile;
            criterion.bidModifier = bidModifier;

            // Create SET operation.
            CampaignCriterionOperation operation = new CampaignCriterionOperation();

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

            try {
                // Update campaign criteria.
                CampaignCriterionReturnValue result = campaignCriterionService.mutate(
                    new CampaignCriterionOperation[] { operation });

                // Display campaign criteria.
                if (result.value != null)
                {
                    foreach (CampaignCriterion newCriterion in result.value)
                    {
                        Console.WriteLine("Campaign criterion with campaign id '{0}', criterion id '{1}', " +
                                          "and type '{2}' was modified with bid {3:F2}.", newCriterion.campaignId,
                                          newCriterion.criterion.id, newCriterion.criterion.type, newCriterion.bidModifier);
                    }
                }
                else
                {
                    Console.WriteLine("No campaign criteria were modified.");
                }
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to set bid modifier for campaign.", ex);
            }
        }
コード例 #5
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign for which shopping channel
        /// is set.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201406.CampaignCriterionService);

            // ProductSalesChannel is a fixed id criterion, with the possible values
            // defined here.
            // ONLINE: 200
            // LOCAL: 201
            ProductSalesChannel productSalesChannel = new ProductSalesChannel();

            productSalesChannel.id = 200;

            CampaignCriterion campaignCriterion = new CampaignCriterion();

            campaignCriterion.campaignId = campaignId;
            campaignCriterion.criterion  = productSalesChannel;

            // Create operation.
            CampaignCriterionOperation operation = new CampaignCriterionOperation();

            operation.operand   = campaignCriterion;
            operation.@operator = Operator.ADD;

            try {
                // Make the mutate request.
                CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(
                    new CampaignCriterionOperation[] { operation });

                if (retVal != null && retVal.value != null)
                {
                    // Display campaign targets.
                    foreach (CampaignCriterion criterion in retVal.value)
                    {
                        Console.WriteLine("Campaign criteria of type '{0}' was set to campaign with" +
                                          " id = '{1}'.", criterion.criterion.CriterionType, criterion.campaignId);
                    }
                }
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to set shopping product channel.", ex);
            }
        }
コード例 #6
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which targeting criteria
        /// are added.</param>
        /// <param name="feedId">ID of a feed that has been configured for location
        /// targeting, meaning it has an ENABLED FeedMapping with criterionType of
        /// 77. Feeds linked to a GMB account automatically have this FeedMapping.
        /// If you don't have such a feed, set this value to null.</param>
        public void Run(AdWordsUser user, long campaignId, long?feedId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201506.CampaignCriterionService);

            // Create language criteria.
            // See http://code.google.com/apis/adwords/docs/appendix/languagecodes.html
            // for a detailed list of language codes.
            Language language1 = new Language();

            language1.id = 1002; // French
            CampaignCriterion languageCriterion1 = new CampaignCriterion();

            languageCriterion1.campaignId = campaignId;
            languageCriterion1.criterion  = language1;

            Language language2 = new Language();

            language2.id = 1005; // Japanese
            CampaignCriterion languageCriterion2 = new CampaignCriterion();

            languageCriterion2.campaignId = campaignId;
            languageCriterion2.criterion  = language2;

            // Target Tier 3 income group near Miami, Florida.
            LocationGroups incomeLocationGroups = new LocationGroups();

            IncomeOperand incomeOperand = new IncomeOperand();

            // Tiers are numbered 1-10, and represent 10% segments of earners.
            // For example, TIER_1 is the top 10%, TIER_2 is the 80-90%, etc.
            // Tiers 6 through 10 are grouped into TIER_6_TO_10.
            incomeOperand.tier = IncomeTier.TIER_3;

            GeoTargetOperand geoTargetOperand1 = new GeoTargetOperand();

            geoTargetOperand1.locations = new long[] { 1015116 }; // Miami, FL.

            incomeLocationGroups.matchingFunction            = new Function();
            incomeLocationGroups.matchingFunction.lhsOperand =
                new FunctionArgumentOperand[] { incomeOperand };
            incomeLocationGroups.matchingFunction.@operator  = FunctionOperator.AND;
            incomeLocationGroups.matchingFunction.rhsOperand =
                new FunctionArgumentOperand[] { geoTargetOperand1 };

            CampaignCriterion locationGroupCriterion1 = new CampaignCriterion();

            locationGroupCriterion1.campaignId = campaignId;
            locationGroupCriterion1.criterion  = incomeLocationGroups;

            // Target places of interest near Downtown Miami, Florida.
            LocationGroups interestLocationGroups = new LocationGroups();

            PlacesOfInterestOperand placesOfInterestOperand = new PlacesOfInterestOperand();

            placesOfInterestOperand.category = PlacesOfInterestOperandCategory.DOWNTOWN;

            GeoTargetOperand geoTargetOperand2 = new GeoTargetOperand();

            geoTargetOperand2.locations = new long[] { 1015116 }; // Miami, FL.

            interestLocationGroups.matchingFunction            = new Function();
            interestLocationGroups.matchingFunction.lhsOperand =
                new FunctionArgumentOperand[] { placesOfInterestOperand };
            interestLocationGroups.matchingFunction.@operator  = FunctionOperator.AND;
            interestLocationGroups.matchingFunction.rhsOperand =
                new FunctionArgumentOperand[] { geoTargetOperand2 };

            CampaignCriterion locationGroupCriterion2 = new CampaignCriterion();

            locationGroupCriterion2.campaignId = campaignId;
            locationGroupCriterion2.criterion  = interestLocationGroups;

            CampaignCriterion locationGroupCriterion3 = new CampaignCriterion();

            if (feedId.HasValue)
            {
                // Distance targeting. Area of 10 miles around targets above.
                ConstantOperand radius = new ConstantOperand();
                radius.type        = ConstantOperandConstantType.DOUBLE;
                radius.unit        = ConstantOperandUnit.MILES;
                radius.doubleValue = 10.0;
                LocationExtensionOperand distance = new LocationExtensionOperand();
                distance.radius = radius;

                LocationGroups radiusLocationGroups = new LocationGroups();
                radiusLocationGroups.matchingFunction            = new Function();
                radiusLocationGroups.matchingFunction.@operator  = FunctionOperator.IDENTITY;
                radiusLocationGroups.matchingFunction.lhsOperand =
                    new FunctionArgumentOperand[] { distance };

                // FeedID should be the ID of a feed that has been configured for location
                // targeting, meaning it has an ENABLED FeedMapping with criterionType of
                // 77. Feeds linked to a GMB account automatically have this FeedMapping.
                radiusLocationGroups.feedId = feedId.Value;

                locationGroupCriterion3.campaignId = campaignId;
                locationGroupCriterion3.criterion  = radiusLocationGroups;
            }

            // Create location criteria.
            // See http://code.google.com/apis/adwords/docs/appendix/countrycodes.html
            // for a detailed list of country codes.
            Location location1 = new Location();

            location1.id = 2840; // USA
            CampaignCriterion locationCriterion1 = new CampaignCriterion();

            locationCriterion1.campaignId = campaignId;
            locationCriterion1.criterion  = location1;

            Location location2 = new Location();

            location2.id = 2392; // Japan
            CampaignCriterion locationCriterion2 = new CampaignCriterion();

            locationCriterion2.campaignId = campaignId;
            locationCriterion2.criterion  = location2;

            // Add a negative campaign keyword.
            NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();

            negativeCriterion.campaignId = campaignId;

            Keyword keyword = new Keyword();

            keyword.matchType = KeywordMatchType.BROAD;
            keyword.text      = "jupiter cruise";

            negativeCriterion.criterion = keyword;

            List <CampaignCriterion> criteria = new List <CampaignCriterion>(
                new CampaignCriterion[] { languageCriterion1,
                                          languageCriterion2, locationCriterion1, locationCriterion2, negativeCriterion,
                                          locationGroupCriterion1, locationGroupCriterion2 });

            if (feedId.HasValue)
            {
                criteria.Add(locationGroupCriterion3);
            }

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

            foreach (CampaignCriterion criterion in criteria)
            {
                CampaignCriterionOperation operation = new CampaignCriterionOperation();
                operation.@operator = Operator.ADD;
                operation.operand   = criterion;
                operations.Add(operation);
            }

            try {
                // Set the campaign targets.
                CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray());

                if (retVal != null && retVal.value != null)
                {
                    // Display campaign targets.
                    foreach (CampaignCriterion criterion in retVal.value)
                    {
                        Console.WriteLine("Campaign criteria of type '{0}' was set to campaign with" +
                                          " id = '{1}'.", criterion.criterion.CriterionType, criterion.campaignId);
                    }
                }
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to set Campaign criteria.", ex);
            }
        }
コード例 #7
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign id to add product scope.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201609.CampaignCriterionService);

            ProductScope productScope = new ProductScope();
            // This set of dimensions is for demonstration purposes only. It would be
            // extremely unlikely that you want to include so many dimensions in your
            // product scope.
            ProductBrand nexusBrand = new ProductBrand();

            nexusBrand.value = "Nexus";

            ProductCanonicalCondition newProducts = new ProductCanonicalCondition();

            newProducts.condition = ProductCanonicalConditionCondition.NEW;

            ProductCustomAttribute customAttribute = new ProductCustomAttribute();

            customAttribute.type  = ProductDimensionType.CUSTOM_ATTRIBUTE_0;
            customAttribute.value = "my attribute value";

            ProductOfferId bookOffer = new ProductOfferId();

            bookOffer.value = "book1";

            ProductType mediaProducts = new ProductType();

            mediaProducts.type  = ProductDimensionType.PRODUCT_TYPE_L1;
            mediaProducts.value = "Media";

            ProductType bookProducts = new ProductType();

            bookProducts.type  = ProductDimensionType.PRODUCT_TYPE_L2;
            bookProducts.value = "Books";

            // The value for the bidding category is a fixed ID for the
            // 'Luggage & Bags' category. You can retrieve IDs for categories from
            // the ConstantDataService. See the 'GetProductCategoryTaxonomy' example
            // for more details.
            ProductBiddingCategory luggageBiddingCategory = new ProductBiddingCategory();

            luggageBiddingCategory.type  = ProductDimensionType.BIDDING_CATEGORY_L1;
            luggageBiddingCategory.value = -5914235892932915235;

            productScope.dimensions = new ProductDimension[] { nexusBrand, newProducts, bookOffer,
                                                               mediaProducts, luggageBiddingCategory };

            CampaignCriterion campaignCriterion = new CampaignCriterion();

            campaignCriterion.campaignId = campaignId;
            campaignCriterion.criterion  = productScope;

            // Create operation.
            CampaignCriterionOperation operation = new CampaignCriterionOperation();

            operation.operand   = campaignCriterion;
            operation.@operator = Operator.ADD;

            try {
                // Make the mutate request.
                CampaignCriterionReturnValue result = campaignCriterionService.mutate(
                    new CampaignCriterionOperation[] { operation });

                Console.WriteLine("Created a ProductScope criterion with ID '{0}'",
                                  result.value[0].criterion.id);
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to set shopping product scope.", e);
            }
        }
コード例 #8
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which targeting criteria
        /// are added.</param>
        /// <param name="feedId">ID of a feed that has been configured for location
        /// targeting, meaning it has an ENABLED FeedMapping with criterionType of
        /// 77. Feeds linked to a GMB account automatically have this FeedMapping.
        /// If you don't have such a feed, set this value to null.</param>
        public void Run(AdWordsUser user, long campaignId, long?feedId)
        {
            using (CampaignCriterionService campaignCriterionService =
                       (CampaignCriterionService)user.GetService(AdWordsService.v201802
                                                                 .CampaignCriterionService))
            {
                // Create locations. The IDs can be found in the documentation or
                // retrieved with the LocationCriterionService.
                Location california = new Location()
                {
                    id = 21137L
                };

                Location mexico = new Location()
                {
                    id = 2484L
                };

                // Create languages. The IDs can be found in the documentation or
                // retrieved with the ConstantDataService.
                Language english = new Language()
                {
                    id = 1000L
                };

                Language spanish = new Language()
                {
                    id = 1003L
                };

                List <Criterion> criteria = new List <Criterion>()
                {
                    california,
                    mexico,
                    english,
                    spanish
                };

                // Distance targeting. Area of 10 miles around the locations in the location feed.
                if (feedId != null)
                {
                    LocationGroups radiusLocationGroup = new LocationGroups()
                    {
                        feedId           = feedId.Value,
                        matchingFunction = new Function()
                        {
                            @operator  = FunctionOperator.IDENTITY,
                            lhsOperand = new FunctionArgumentOperand[]
                            {
                                new LocationExtensionOperand()
                                {
                                    radius = new ConstantOperand()
                                    {
                                        type        = ConstantOperandConstantType.DOUBLE,
                                        unit        = ConstantOperandUnit.MILES,
                                        doubleValue = 10
                                    }
                                }
                            }
                        }
                    };

                    criteria.Add(radiusLocationGroup);
                }

                // Create operations to add each of the criteria above.
                List <CampaignCriterionOperation>
                operations = new List <CampaignCriterionOperation>();
                foreach (Criterion criterion in criteria)
                {
                    CampaignCriterionOperation operation = new CampaignCriterionOperation()
                    {
                        operand = new CampaignCriterion()
                        {
                            campaignId = campaignId,
                            criterion  = criterion
                        },
                        @operator = Operator.ADD
                    };

                    operations.Add(operation);
                }

                // Add a negative campaign criterion.

                CampaignCriterion negativeCriterion = new NegativeCampaignCriterion()
                {
                    campaignId = campaignId,
                    criterion  = new Keyword()
                    {
                        text      = "jupiter cruise",
                        matchType = KeywordMatchType.BROAD
                    }
                };

                CampaignCriterionOperation negativeCriterionOperation =
                    new CampaignCriterionOperation()
                {
                    operand   = negativeCriterion,
                    @operator = Operator.ADD
                };

                operations.Add(negativeCriterionOperation);

                try
                {
                    // Set the campaign targets.
                    CampaignCriterionReturnValue retVal =
                        campaignCriterionService.mutate(operations.ToArray());

                    if (retVal != null && retVal.value != null)
                    {
                        // Display campaign targets.
                        foreach (CampaignCriterion criterion in retVal.value)
                        {
                            Console.WriteLine(
                                "Campaign criteria of type '{0}' was set to campaign with" +
                                " id = '{1}'.", criterion.criterion.CriterionType,
                                criterion.campaignId);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to set Campaign criteria.", e);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which targeting criteria
        /// are added.</param>
        /// <param name="feedId">ID of a feed that has been configured for location
        /// targeting, meaning it has an ENABLED FeedMapping with criterionType of
        /// 77. Feeds linked to a GMB account automatically have this FeedMapping.
        /// If you don't have such a feed, set this value to null.</param>
        public void Run(AdWordsUser user, long campaignId, long?feedId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201605.CampaignCriterionService);

            // Create locations. The IDs can be found in the documentation or
            // retrieved with the LocationCriterionService.
            Location california = new Location()
            {
                id = 21137L
            };

            Location mexico = new Location()
            {
                id = 2484L
            };

            // Create languages. The IDs can be found in the documentation or
            // retrieved with the ConstantDataService.
            Language english = new Language()
            {
                id = 1000L
            };

            Language spanish = new Language()
            {
                id = 1003L
            };

            // Location groups criteria. These represent targeting by household income
            // or places of interest. The IDs can be found in the documentation or
            // retrieved with the LocationCriterionService.
            LocationGroups locationGroupTier3    = new LocationGroups();
            Function       tier3MatchingFunction = new Function();

            tier3MatchingFunction.lhsOperand = new FunctionArgumentOperand[] {
                // Tiers are numbered 1-10, and represent 10% segments of earners.
                // For example, TIER_1 is the top 10%, TIER_2 is the 80-90%, etc.
                // Tiers 6 through 10 are grouped into TIER_6_TO_10.
                new IncomeOperand()
                {
                    tier = IncomeTier.TIER_3
                }
            };
            tier3MatchingFunction.@operator  = FunctionOperator.AND;
            tier3MatchingFunction.rhsOperand = new FunctionArgumentOperand[] {
                new GeoTargetOperand()
                {
                    locations = new long[] { 1015116L } // Miami, FL
                }
            };

            locationGroupTier3.matchingFunction = tier3MatchingFunction;

            LocationGroups locationGroupDowntown = new LocationGroups()
            {
                matchingFunction = new Function()
                {
                    lhsOperand = new FunctionArgumentOperand[] {
                        new PlacesOfInterestOperand()
                        {
                            category = PlacesOfInterestOperandCategory.DOWNTOWN
                        }
                    },
                    @operator  = FunctionOperator.AND,
                    rhsOperand = new FunctionArgumentOperand[] {
                        new GeoTargetOperand()
                        {
                            locations = new long[] { 1015116L } // Miami, FL
                        }
                    }
                }
            };

            List <Criterion> criteria = new List <Criterion>()
            {
                california, mexico, english, spanish, locationGroupTier3
            };

            // Distance targeting. Area of 10 miles around the locations in the location feed.
            if (feedId != null)
            {
                LocationGroups radiusLocationGroup = new LocationGroups()
                {
                    feedId           = feedId.Value,
                    matchingFunction = new Function()
                    {
                        @operator  = FunctionOperator.IDENTITY,
                        lhsOperand = new FunctionArgumentOperand[] {
                            new LocationExtensionOperand()
                            {
                                radius = new ConstantOperand()
                                {
                                    type        = ConstantOperandConstantType.DOUBLE,
                                    unit        = ConstantOperandUnit.MILES,
                                    doubleValue = 10
                                }
                            }
                        }
                    }
                };

                criteria.Add(radiusLocationGroup);
            }

            // Create operations to add each of the criteria above.
            List <CampaignCriterionOperation> operations = new List <CampaignCriterionOperation>();

            foreach (Criterion criterion in criteria)
            {
                CampaignCriterionOperation operation = new CampaignCriterionOperation()
                {
                    operand = new CampaignCriterion()
                    {
                        campaignId = campaignId,
                        criterion  = criterion
                    },
                    @operator = Operator.ADD
                };

                operations.Add(operation);
            }

            // Add a negative campaign criterion.

            CampaignCriterion negativeCriterion = new NegativeCampaignCriterion()
            {
                campaignId = campaignId,
                criterion  = new Keyword()
                {
                    text      = "jupiter cruise",
                    matchType = KeywordMatchType.BROAD
                }
            };

            CampaignCriterionOperation negativeCriterionOperation = new CampaignCriterionOperation()
            {
                operand   = negativeCriterion,
                @operator = Operator.ADD
            };

            operations.Add(negativeCriterionOperation);

            try {
                // Set the campaign targets.
                CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray());

                if (retVal != null && retVal.value != null)
                {
                    // Display campaign targets.
                    foreach (CampaignCriterion criterion in retVal.value)
                    {
                        Console.WriteLine("Campaign criteria of type '{0}' was set to campaign with" +
                                          " id = '{1}'.", criterion.criterion.CriterionType, criterion.campaignId);
                    }
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to set Campaign criteria.", e);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which targeting criteria
        /// are added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201502.CampaignCriterionService);

            // Create language criteria.
            // See http://code.google.com/apis/adwords/docs/appendix/languagecodes.html
            // for a detailed list of language codes.
            Language language1 = new Language();

            language1.id = 1002; // French
            CampaignCriterion languageCriterion1 = new CampaignCriterion();

            languageCriterion1.campaignId = campaignId;
            languageCriterion1.criterion  = language1;

            Language language2 = new Language();

            language2.id = 1005; // Japanese
            CampaignCriterion languageCriterion2 = new CampaignCriterion();

            languageCriterion2.campaignId = campaignId;
            languageCriterion2.criterion  = language2;

            // Create location criteria.
            // See http://code.google.com/apis/adwords/docs/appendix/countrycodes.html
            // for a detailed list of country codes.
            Location location1 = new Location();

            location1.id = 2840; // USA
            CampaignCriterion locationCriterion1 = new CampaignCriterion();

            locationCriterion1.campaignId = campaignId;
            locationCriterion1.criterion  = location1;

            Location location2 = new Location();

            location2.id = 2392; // Japan
            CampaignCriterion locationCriterion2 = new CampaignCriterion();

            locationCriterion2.campaignId = campaignId;
            locationCriterion2.criterion  = location2;

            // Add a negative campaign placement.
            NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();

            negativeCriterion.campaignId = campaignId;

            Placement placement = new Placement();

            placement.url = "http://mars.google.com";

            negativeCriterion.criterion = placement;

            CampaignCriterion[] criteria = new CampaignCriterion[] { languageCriterion1,
                                                                     languageCriterion2, locationCriterion1, locationCriterion2, negativeCriterion };

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

            foreach (CampaignCriterion criterion in criteria)
            {
                CampaignCriterionOperation operation = new CampaignCriterionOperation();
                operation.@operator = Operator.ADD;
                operation.operand   = criterion;
                operations.Add(operation);
            }

            try {
                // Set the campaign targets.
                CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray());

                if (retVal != null && retVal.value != null)
                {
                    // Display campaign targets.
                    foreach (CampaignCriterion criterion in retVal.value)
                    {
                        Console.WriteLine("Campaign criteria of type '{0}' was set to campaign with" +
                                          " id = '{1}'.", criterion.criterion.CriterionType, criterion.campaignId);
                    }
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to set Campaign criteria.", e);
            }
        }
コード例 #11
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which targeting criteria
        /// are added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201402.CampaignCriterionService);

            // Create language criteria.
            // See http://code.google.com/apis/adwords/docs/appendix/languagecodes.html
            // for a detailed list of language codes.
            Language language1 = new Language();

            language1.id = 1002; // French
            CampaignCriterion languageCriterion1 = new CampaignCriterion();

            languageCriterion1.campaignId = campaignId;
            languageCriterion1.criterion  = language1;

            Language language2 = new Language();

            language2.id = 1005; // Japanese
            CampaignCriterion languageCriterion2 = new CampaignCriterion();

            languageCriterion2.campaignId = campaignId;
            languageCriterion2.criterion  = language2;

            // Target Tier 3 income group near Miami, Florida.
            LocationGroups incomeLocationGroups = new LocationGroups();

            IncomeOperand incomeOperand = new IncomeOperand();

            // Tiers are numbered 1-10, and represent 10% segments of earners.
            // For example, TIER_1 is the top 10%, TIER_2 is the 80-90%, etc.
            // Tiers 6 through 10 are grouped into TIER_6_TO_10.
            incomeOperand.tier = IncomeTier.TIER_3;

            GeoTargetOperand geoTargetOperand1 = new GeoTargetOperand();

            geoTargetOperand1.locations = new long[] { 1015116 }; // Miami, FL.

            incomeLocationGroups.matchingFunction            = new Function();
            incomeLocationGroups.matchingFunction.lhsOperand =
                new FunctionArgumentOperand[] { incomeOperand };
            incomeLocationGroups.matchingFunction.@operator  = FunctionOperator.AND;
            incomeLocationGroups.matchingFunction.rhsOperand =
                new FunctionArgumentOperand[] { geoTargetOperand1 };

            CampaignCriterion locationGroupCriterion1 = new CampaignCriterion();

            locationGroupCriterion1.campaignId = campaignId;
            locationGroupCriterion1.criterion  = incomeLocationGroups;

            // Target places of interest near Downtown Miami, Florida.
            LocationGroups interestLocationGroups = new LocationGroups();

            PlacesOfInterestOperand placesOfInterestOperand = new PlacesOfInterestOperand();

            placesOfInterestOperand.category = PlacesOfInterestOperandCategory.DOWNTOWN;

            GeoTargetOperand geoTargetOperand2 = new GeoTargetOperand();

            geoTargetOperand2.locations = new long[] { 1015116 }; // Miami, FL.

            interestLocationGroups.matchingFunction            = new Function();
            interestLocationGroups.matchingFunction.lhsOperand =
                new FunctionArgumentOperand[] { placesOfInterestOperand };
            interestLocationGroups.matchingFunction.@operator  = FunctionOperator.AND;
            interestLocationGroups.matchingFunction.rhsOperand =
                new FunctionArgumentOperand[] { geoTargetOperand2 };

            CampaignCriterion locationGroupCriterion2 = new CampaignCriterion();

            locationGroupCriterion2.campaignId = campaignId;
            locationGroupCriterion2.criterion  = interestLocationGroups;

            // Create location criteria.
            // See http://code.google.com/apis/adwords/docs/appendix/countrycodes.html
            // for a detailed list of country codes.
            Location location1 = new Location();

            location1.id = 2840; // USA
            CampaignCriterion locationCriterion1 = new CampaignCriterion();

            locationCriterion1.campaignId = campaignId;
            locationCriterion1.criterion  = location1;

            Location location2 = new Location();

            location2.id = 2392; // Japan
            CampaignCriterion locationCriterion2 = new CampaignCriterion();

            locationCriterion2.campaignId = campaignId;
            locationCriterion2.criterion  = location2;

            // Add a negative campaign keyword.
            NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();

            negativeCriterion.campaignId = campaignId;

            Keyword keyword = new Keyword();

            keyword.matchType = KeywordMatchType.BROAD;
            keyword.text      = "jupiter cruise";

            negativeCriterion.criterion = keyword;

            CampaignCriterion[] criteria = new CampaignCriterion[] { languageCriterion1,
                                                                     languageCriterion2, locationCriterion1, locationCriterion2, negativeCriterion,
                                                                     locationGroupCriterion1, locationGroupCriterion2 };

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

            foreach (CampaignCriterion criterion in criteria)
            {
                CampaignCriterionOperation operation = new CampaignCriterionOperation();
                operation.@operator = Operator.ADD;
                operation.operand   = criterion;
                operations.Add(operation);
            }

            try {
                // Set the campaign targets.
                CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(operations.ToArray());

                if (retVal != null && retVal.value != null)
                {
                    // Display campaign targets.
                    foreach (CampaignCriterion criterion in retVal.value)
                    {
                        Console.WriteLine("Campaign criteria of type '{0}' was set to campaign with" +
                                          " id = '{1}'.", criterion.criterion.CriterionType, criterion.campaignId);
                    }
                }
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to set Campaign criteria.", ex);
            }
        }