コード例 #1
0
        /// <summary>
        /// Updates the given TargetingSetting of an ad group.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID.</param>
        /// <param name="adGroupId">The ad group ID for which to update the audience targeting
        ///     restriction.</param>
        /// <param name="targetingSetting">The updated targeting setting.</param>
        // [START update_audience_target_restriction_2]
        private void UpdateTargetingSetting(GoogleAdsClient client, long customerId, long
                                            adGroupId, TargetingSetting targetingSetting)
        {
            // Get the AdGroupService client.
            AdGroupServiceClient adGroupServiceClient =
                client.GetService(Services.V10.AdGroupService);

            // Create an ad group object with the updated targeting setting.
            AdGroup adGroup = new AdGroup
            {
                ResourceName     = ResourceNames.AdGroup(customerId, adGroupId),
                TargetingSetting = targetingSetting
            };

            // Construct an operation that will update the ad group, using the FieldMasks utility
            // to derive the update mask. This mask tells the Google Ads API which attributes of the
            // ad group you want to change.
            AdGroupOperation operation = new AdGroupOperation
            {
                Update     = adGroup,
                UpdateMask = FieldMasks.AllSetFieldsOf(adGroup)
            };

            // Send the operation in a mutate request.
            MutateAdGroupsResponse response =
                adGroupServiceClient.MutateAdGroups(customerId.ToString(), new[] { operation });

            // Print the resource name of the updated object.
            Console.WriteLine("Updated targeting setting of ad group with resource name " +
                              $"'{response.Results.First().ResourceName}'; set the AUDIENCE target restriction " +
                              "to 'Observation'.");
        }
コード例 #2
0
 private void _removeRule(TargetingSetting obj)
 {
     if (obj != null)
     {
         Settings.Remove(obj);
     }
 }
コード例 #3
0
 private void _editRule(TargetingSetting obj)
 {
     AddButtonText    = "<";
     AddButtonTooltip = "Save";
     EditingRule      = true;
     CurrentSetting   = obj;
 }
コード例 #4
0
        private void _addRule(TargetingSetting obj)
        {
            if (Settings.All(s => !s.Equals(CurrentSetting)))
            {
                Settings.Add(CurrentSetting);
            }


            AddButtonText    = "ü";
            AddButtonTooltip = "Add";
            CurrentSetting   = new TargetingSetting();
        }
コード例 #5
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which ad groups are
        /// added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            using (AdGroupService adGroupService =
                       (AdGroupService)user.GetService(AdWordsService.v201710.AdGroupService)) {
                List <AdGroupOperation> operations = new List <AdGroupOperation>();

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

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

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

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

                    adGroup.biddingStrategyConfiguration = biddingConfig;

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

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

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

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

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

                    // Set the rotation mode.
                    AdGroupAdRotationMode rotationMode = new AdGroupAdRotationMode();
                    rotationMode.adRotationMode   = AdRotationMode.OPTIMIZE;
                    adGroup.adGroupAdRotationMode = rotationMode;

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

                    operations.Add(operation);
                }

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

                    // Display the results.
                    if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                    {
                        foreach (AdGroup newAdGroup in retVal.value)
                        {
                            Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.",
                                              newAdGroup.id, newAdGroup.name);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No ad groups were created.");
                    }
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create ad groups.", e);
                }
            }
        }
コード例 #6
0
        public static AdGroupReturnValue CreateAdGroup(AdWordsUser user, AdGroupLo adGroupLo)
        {
            using (AdGroupService adGroupService =
                       (AdGroupService)user.GetService(AdWordsService.v201710.AdGroupService))
            {
                List <AdGroupOperation> operations = new List <AdGroupOperation>();

                // Create the ad group.
                AdGroup adGroup = new AdGroup();
                adGroup.name       = adGroupLo.Name;
                adGroup.status     = AdGroupStatus.PAUSED;
                adGroup.campaignId = adGroupLo.CampaignId;

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

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

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

                adGroup.biddingStrategyConfiguration = biddingConfig;

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

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

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

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

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

                // Set the rotation mode.
                AdGroupAdRotationMode rotationMode = new AdGroupAdRotationMode();
                rotationMode.adRotationMode   = AdRotationMode.OPTIMIZE;
                adGroup.adGroupAdRotationMode = rotationMode;

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

                operations.Add(operation);


                AdGroupReturnValue returnDGroup;
                try
                {
                    // Create the ad group.
                    returnDGroup = adGroupService.mutate(operations.ToArray());
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to create ad group.", e);
                }
                return(returnDGroup);
            }
        }
コード例 #7
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which ad groups are
        /// added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the AdGroupService.
            AdGroupService adGroupService =
                (AdGroupService)user.GetService(AdWordsService.v201402.AdGroupService);

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

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

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

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

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

                adGroup.biddingStrategyConfiguration = biddingConfig;

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

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

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

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

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

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

                operations.Add(operation);
            }

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

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

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

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

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

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

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

            adGroup.biddingStrategyConfiguration = biddingConfig;

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

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

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

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

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

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

            operations.Add(operation);
              }

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

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              foreach (AdGroup newAdGroup in retVal.value) {
            Console.WriteLine("Ad group with id = '{0}' and name = '{1}' was created.",
                newAdGroup.id, newAdGroup.name);
              }
            } else {
              Console.WriteLine("No ad groups were created.");
            }
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to create ad groups.", e);
              }
        }
コード例 #9
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for the conversion action is
        ///     added.</param>
        /// <param name="adGroupId">The ad group ID for which to update the audience targeting
        ///     restriction.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId)
        {
            // Get the GoogleAdsService client.
            GoogleAdsServiceClient googleAdsServiceClient =
                client.GetService(Services.V10.GoogleAdsService);

            // Create a search request that retrieves the targeting settings from a given ad group.
            // [START update_audience_target_restriction]
            string query = $@"
                SELECT ad_group.id, ad_group.name, ad_group.targeting_setting.target_restrictions
                FROM ad_group
                WHERE ad_group.id = {adGroupId}";

            // [END update_audience_target_restriction]

            try
            {
                // Issue the search request.
                PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchResponse =
                    googleAdsServiceClient.Search(customerId.ToString(), query);

                // Create an empty TargetingSetting instance.
                TargetingSetting targetingSetting = new TargetingSetting();

                // Create a flag that specifies whether or not we should update the targeting
                // setting. We should only do this if we find an AUDIENCE target restriction with
                // bid_only set to false.
                bool shouldUpdateTargetingSetting = false;

                // Iterate over all rows in all pages and prints the requested field values for the
                // ad group in each row.
                foreach (GoogleAdsRow googleAdsRow in searchResponse)
                {
                    AdGroup adGroup = googleAdsRow.AdGroup;

                    Console.WriteLine($"Ad group with ID {adGroup.Id} and name '{adGroup.Name}' " +
                                      "was found with the following targeting restrictions:");

                    RepeatedField <TargetRestriction> targetRestrictions =
                        adGroup.TargetingSetting.TargetRestrictions;

                    // Loop through and print each of the target restrictions. Reconstruct the
                    // TargetingSetting object with the updated audience target restriction because
                    // Google will overwrite the entire targeting_setting field of the ad group when
                    // the field mask includes targeting_setting in an update operation.
                    // [START update_audience_target_restriction_1]
                    foreach (TargetRestriction targetRestriction in targetRestrictions)
                    {
                        TargetingDimension targetingDimension =
                            targetRestriction.TargetingDimension;
                        bool bidOnly = targetRestriction.BidOnly;

                        Console.WriteLine("\tTargeting restriction with targeting dimension " +
                                          $"'{targetingDimension}' and bid only set to '{bidOnly}'.");

                        // Add the target restriction to the TargetingSetting object as is if the
                        // targeting dimension has a value other than AUDIENCE because those should
                        // not change.
                        if (targetingDimension != TargetingDimension.Audience)
                        {
                            targetingSetting.TargetRestrictions.Add(targetRestriction);
                        }
                        else if (!bidOnly)
                        {
                            shouldUpdateTargetingSetting = true;

                            // Add an AUDIENCE target restriction with bid_only set to true to the
                            // targeting setting object. This has the effect of setting the AUDIENCE
                            // target restriction to "Observation". For more details about the
                            // targeting setting, visit
                            // https://support.google.com/google-ads/answer/7365594.
                            targetingSetting.TargetRestrictions.Add(new TargetRestriction
                            {
                                TargetingDimension = TargetingDimension.Audience,
                                BidOnly            = true
                            });
                        }
                    }
                    // [END update_audience_target_restriction_1]
                }

                // Only update the TargetSetting on the ad group if there is an AUDIENCE
                // TargetRestriction with bid_only set to false.
                if (shouldUpdateTargetingSetting)
                {
                    UpdateTargetingSetting(client, customerId, adGroupId, targetingSetting);
                }
                else
                {
                    Console.WriteLine("No target restrictions to update.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
コード例 #10
0
 private bool _canAddRule(TargetingSetting arg)
 {
     return(CurrentSetting.IsValid());
 }
コード例 #11
0
 private bool _canRemoveRule(TargetingSetting arg)
 {
     return(arg != null);
 }
コード例 #12
0
 private bool _canEditRule(TargetingSetting arg)
 {
     return(arg != null);
 }