Пример #1
0
        /// <summary>
        /// Creates the feed mapping for DSA page feeds.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="feedDetails">The feed details.</param>
        private static void CreateFeedMapping(AdWordsUser user, DSAFeedDetails feedDetails)
        {
            using (FeedMappingService feedMappingService =
                       (FeedMappingService)user.GetService(AdWordsService.v201802.FeedMappingService)) {
                // Map the FeedAttributeIds to the fieldId constants.
                AttributeFieldMapping urlFieldMapping = new AttributeFieldMapping();
                urlFieldMapping.feedAttributeId = feedDetails.urlAttributeId;
                urlFieldMapping.fieldId         = DSA_PAGE_URLS_FIELD_ID;

                AttributeFieldMapping labelFieldMapping = new AttributeFieldMapping();
                labelFieldMapping.feedAttributeId = feedDetails.labelAttributeId;
                labelFieldMapping.fieldId         = DSA_LABEL_FIELD_ID;

                // Create the FieldMapping and operation.
                FeedMapping feedMapping = new FeedMapping();
                feedMapping.criterionType          = DSA_PAGE_FEED_CRITERION_TYPE;
                feedMapping.feedId                 = feedDetails.feedId;
                feedMapping.attributeFieldMappings = new AttributeFieldMapping[] {
                    urlFieldMapping, labelFieldMapping
                };

                FeedMappingOperation operation = new FeedMappingOperation();
                operation.operand   = feedMapping;
                operation.@operator = Operator.ADD;

                try {
                    // Add the field mapping.
                    feedMappingService.mutate(new FeedMappingOperation[] { operation });
                    return;
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create feed mapping.", e);
                }
            }
        }
        private static void createSitelinksFeedMapping(AdWordsUser user,
                                                       SitelinksDataHolder sitelinksData)
        {
            using (FeedMappingService feedMappingService =
                       (FeedMappingService)user.GetService(AdWordsService.v201806.FeedMappingService)) {
                // Map the FeedAttributeIds to the fieldId constants.
                AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping()
                {
                    feedAttributeId = sitelinksData.LinkTextFeedAttributeId,
                    fieldId         = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT
                };

                AttributeFieldMapping linkFinalUrlFieldMapping = new AttributeFieldMapping()
                {
                    feedAttributeId = sitelinksData.LinkFinalUrlFeedAttributeId,
                    fieldId         = PLACEHOLDER_FIELD_SITELINK_FINAL_URL
                };

                AttributeFieldMapping line2FieldMapping = new AttributeFieldMapping()
                {
                    feedAttributeId = sitelinksData.Line2FeedAttributeId,
                    fieldId         = PLACEHOLDER_FIELD_LINE_2_TEXT
                };

                AttributeFieldMapping line3FieldMapping = new AttributeFieldMapping()
                {
                    feedAttributeId = sitelinksData.Line3FeedAttributeId,
                    fieldId         = PLACEHOLDER_FIELD_LINE_3_TEXT
                };

                // Create the FieldMapping and operation.
                FeedMappingOperation operation = new FeedMappingOperation()
                {
                    operand = new FeedMapping()
                    {
                        placeholderType        = PLACEHOLDER_SITELINKS,
                        feedId                 = sitelinksData.FeedId,
                        attributeFieldMappings = new AttributeFieldMapping[] {
                            linkTextFieldMapping, linkFinalUrlFieldMapping, line2FieldMapping, line3FieldMapping
                        }
                    },
                    @operator = Operator.ADD
                };

                // Save the field mapping.
                FeedMappingReturnValue result =
                    feedMappingService.mutate(new FeedMappingOperation[] { operation });

                foreach (FeedMapping savedFeedMapping in result.value)
                {
                    Console.WriteLine(
                        "Feed mapping with ID {0} and placeholderType {1} was saved for feed with ID {2}.",
                        savedFeedMapping.feedMappingId, savedFeedMapping.placeholderType,
                        savedFeedMapping.feedId);
                }
            }
        }
Пример #3
0
 /// <summary>Snippet for MutateFeedMappings</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateFeedMappings()
 {
     // Create client
     FeedMappingServiceClient feedMappingServiceClient = FeedMappingServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <FeedMappingOperation> operations = new FeedMappingOperation[]
     {
         new FeedMappingOperation(),
     };
     // Make the request
     MutateFeedMappingsResponse response = feedMappingServiceClient.MutateFeedMappings(customerId, operations);
 }
Пример #4
0
        /// <summary>
        /// Creates a feed mapping, which tells Google Ads how to interpret this data to display
        /// additional sitelink information on ads.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="feed">The feed for which the operation will be created.</param>
        private void CreateFeedMapping(GoogleAdsClient client, long customerId, Feed feed)
        {
            FeedMappingServiceClient feedMappingServiceClient =
                client.GetService(Services.V4.FeedMappingService);

            FeedMapping feedMapping = new FeedMapping
            {
                PlaceholderType = PlaceholderTypeEnum.Types.PlaceholderType.Sitelink,
                Feed            = feed.ResourceName,
            };

            foreach (FeedAttribute feedAttribute in feed.Attributes)
            {
                AttributeFieldMapping attributeFieldMapping = new AttributeFieldMapping()
                {
                    FeedAttributeId = feedAttribute.Id
                };

                switch (feedAttribute.Name)
                {
                case "Link Text":
                    attributeFieldMapping.SitelinkField = SitelinkPlaceholderField.Text;
                    break;

                case "Link Final URL":
                    attributeFieldMapping.SitelinkField = SitelinkPlaceholderField.FinalUrls;
                    break;

                case "Line 1":
                    attributeFieldMapping.SitelinkField = SitelinkPlaceholderField.Line1;
                    break;

                case "Line 2":
                    attributeFieldMapping.SitelinkField = SitelinkPlaceholderField.Line2;
                    break;
                }

                feedMapping.AttributeFieldMappings.Add(attributeFieldMapping);
            }

            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            MutateFeedMappingsResponse response = feedMappingServiceClient.MutateFeedMappings
                                                      (customerId.ToString(), new[] { operation });

            Console.WriteLine($"Created feed mapping '{response.Results.First().ResourceName}'");
        }
        /// <summary>
        /// Creates a feed mapping for a given feed.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="feedResourceName">The feed resource for which feed mapping is created.
        /// </param>
        /// <param name="feedAttributes">The feed attributes.</param>
        private void CreateFeedMapping(GoogleAdsClient client, long customerId,
                                       string feedResourceName,
                                       Dictionary <DsaPageFeedCriterionField, FeedAttribute> feedAttributes
                                       )
        {
            // Get the FeedMappingService.
            FeedMappingServiceClient feedMappingService = client.GetService(
                Services.V3.FeedMappingService);

            FeedMapping feedMapping = new FeedMapping()
            {
                CriterionType = FeedMappingCriterionType.DsaPageFeed,
                Feed          = feedResourceName,

                // Map the FeedAttributeId to the fieldId constants.
                AttributeFieldMappings =
                {
                    new AttributeFieldMapping()
                    {
                        FeedAttributeId  = feedAttributes[DsaPageFeedCriterionField.PageUrl].Id,
                        DsaPageFeedField = DsaPageFeedCriterionField.PageUrl
                    },

                    new AttributeFieldMapping()
                    {
                        FeedAttributeId  = feedAttributes[DsaPageFeedCriterionField.Label].Id,
                        DsaPageFeedField = DsaPageFeedCriterionField.Label
                    }
                }
            };

            // Create the operation.
            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            // Add the FeedMapping.
            MutateFeedMappingsResponse response =
                feedMappingService.MutateFeedMappings(customerId.ToString(), new[] { operation });

            // Display the results.
            foreach (MutateFeedMappingResult result in response.Results)
            {
                Console.WriteLine($"Created feed mapping with resource name" +
                                  $" '{result.ResourceName}'");
            }
        }
Пример #6
0
        /// <summary>
        /// Creates a feed mapping and sets the feed as an ad customizer feed.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="feedResourceName">The resource name of the feed.</param>
        /// <param name="feedAttributes">The attributes of the feed.</param>
        private void CreateAdCustomizerMapping(GoogleAdsClient client, long customerId,
                                               string feedResourceName, Dictionary <string, FeedAttribute> feedAttributes)
        {
            // Get the FeedMappingService.
            FeedMappingServiceClient feedMappingService =
                client.GetService(Services.V4.FeedMappingService);

            // Map the feed attributes to ad customizer placeholder fields.
            // For a full list of ad customizer placeholder fields, see
            // https://developers.google.com/google-ads/api/reference/rpc/latest/AdCustomizerPlaceholderFieldEnum.AdCustomizerPlaceholderField
            AttributeFieldMapping nameFieldMapping = new AttributeFieldMapping()
            {
                FeedAttributeId   = feedAttributes["Name"].Id,
                AdCustomizerField = AdCustomizerPlaceholderField.String
            };

            AttributeFieldMapping priceFieldMapping = new AttributeFieldMapping()
            {
                FeedAttributeId   = feedAttributes["Price"].Id,
                AdCustomizerField = AdCustomizerPlaceholderField.Price
            };

            AttributeFieldMapping dateFieldMapping = new AttributeFieldMapping()
            {
                FeedAttributeId   = feedAttributes["Date"].Id,
                AdCustomizerField = AdCustomizerPlaceholderField.Date
            };

            FeedMapping feedMapping = new FeedMapping()
            {
                Feed                   = feedResourceName,
                PlaceholderType        = PlaceholderType.AdCustomizer,
                AttributeFieldMappings = { nameFieldMapping, priceFieldMapping, dateFieldMapping }
            };

            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            MutateFeedMappingsResponse response =
                feedMappingService.MutateFeedMappings(customerId.ToString(), new[] { operation });

            Console.WriteLine($"Added feed mapping with resource name" +
                              $" '{response.Results[0].ResourceName}'.");
        }
Пример #7
0
        /// <summary>Snippet for MutateFeedMappingsAsync</summary>
        public async Task MutateFeedMappingsAsync()
        {
            // Snippet: MutateFeedMappingsAsync(string, IEnumerable<FeedMappingOperation>, CallSettings)
            // Additional: MutateFeedMappingsAsync(string, IEnumerable<FeedMappingOperation>, CancellationToken)
            // Create client
            FeedMappingServiceClient feedMappingServiceClient = await FeedMappingServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <FeedMappingOperation> operations = new FeedMappingOperation[]
            {
                new FeedMappingOperation(),
            };
            // Make the request
            MutateFeedMappingsResponse response = await feedMappingServiceClient.MutateFeedMappingsAsync(customerId, operations);

            // End snippet
        }
        /// <summary>
        /// Creates a new FeedMapping that indicates how the data holder's feed
        /// should be interpreted in the context of ad customizers.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="dataHolder">The data holder that contains metadata about
        /// the customizer Feed.</param>
        private static void CreateFeedMapping(AdWordsUser user, CustomizersDataHolder dataHolder)
        {
            // Get the FeedMappingService.
            FeedMappingService feedMappingService = (FeedMappingService)user.GetService(
                AdWordsService.v201406.FeedMappingService);

            FeedMapping feedMapping = new FeedMapping();

            feedMapping.feedId          = dataHolder.FeedId;
            feedMapping.placeholderType = PLACEHOLDER_AD_CUSTOMIZER;

            List <AttributeFieldMapping> attributeFieldMappings = new List <AttributeFieldMapping>();
            AttributeFieldMapping        attributeFieldMapping;

            attributeFieldMapping = new AttributeFieldMapping();
            attributeFieldMapping.feedAttributeId = dataHolder.NameFeedAttributeId;
            attributeFieldMapping.fieldId         = PLACEHOLDER_FIELD_STRING;
            attributeFieldMappings.Add(attributeFieldMapping);

            attributeFieldMapping = new AttributeFieldMapping();
            attributeFieldMapping.feedAttributeId = dataHolder.PriceFeedAttributeId;
            attributeFieldMapping.fieldId         = PLACEHOLDER_FIELD_PRICE;
            attributeFieldMappings.Add(attributeFieldMapping);

            attributeFieldMapping = new AttributeFieldMapping();
            attributeFieldMapping.feedAttributeId = dataHolder.DateFeedAttributeId;
            attributeFieldMapping.fieldId         = PLACEHOLDER_FIELD_DATE;
            attributeFieldMappings.Add(attributeFieldMapping);

            feedMapping.attributeFieldMappings = attributeFieldMappings.ToArray();

            FeedMappingOperation feedMappingOperation = new FeedMappingOperation();

            feedMappingOperation.operand   = feedMapping;
            feedMappingOperation.@operator = Operator.ADD;

            FeedMapping addedFeedMapping =
                feedMappingService.mutate(new FeedMappingOperation[] { feedMappingOperation }).value[0];

            Console.WriteLine("Feed mapping with ID {0} and placeholder type {1} was added for " +
                              "feed with ID {2}.",
                              addedFeedMapping.feedMappingId, addedFeedMapping.placeholderType,
                              addedFeedMapping.feedId);
        }
Пример #9
0
        private static void createSiteLinksFeedMapping(
            AdWordsUser user, SiteLinksDataHolder siteLinksData)
        {
            // Get the FeedItemService.
            FeedMappingService feedMappingService =
                (FeedMappingService)user.GetService(AdWordsService.v201406.FeedMappingService);

            // Map the FeedAttributeIds to the fieldId constants.
            AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping();

            linkTextFieldMapping.feedAttributeId = siteLinksData.LinkTextFeedAttributeId;
            linkTextFieldMapping.fieldId         = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT;
            AttributeFieldMapping linkUrlFieldMapping = new AttributeFieldMapping();

            linkUrlFieldMapping.feedAttributeId = siteLinksData.LinkUrlFeedAttributeId;
            linkUrlFieldMapping.fieldId         = PLACEHOLDER_FIELD_SITELINK_URL;

            // Create the FieldMapping and operation.
            FeedMapping feedMapping = new FeedMapping();

            feedMapping.placeholderType        = PLACEHOLDER_SITELINKS;
            feedMapping.feedId                 = siteLinksData.SiteLinksFeedId;
            feedMapping.attributeFieldMappings =
                new AttributeFieldMapping[] { linkTextFieldMapping, linkUrlFieldMapping };
            FeedMappingOperation operation = new FeedMappingOperation();

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

            // Save the field mapping.
            FeedMappingReturnValue result =
                feedMappingService.mutate(new FeedMappingOperation[] { operation });

            foreach (FeedMapping savedFeedMapping in result.value)
            {
                Console.WriteLine(
                    "Feed mapping with ID {0} and placeholderType {1} was saved for feed with ID {2}.",
                    savedFeedMapping.feedMappingId, savedFeedMapping.placeholderType,
                    savedFeedMapping.feedId);
            }
        }
Пример #10
0
        /// <summary>
        /// Creates a feed mapping for a given feed.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the real estate feed is
        /// added.</param>
        /// <param name="feedAttributes">The feed attributes.</param>
        /// <param name="feedResourceName">The resource name of the feed.</param>
        private void CreateFeedMapping(GoogleAdsClient client, long customerId,
                                       Dictionary <RealEstatePlaceholderField, FeedAttribute> feedAttributes,
                                       string feedResourceName)
        {
            // Get the FeedMappingServiceClient.
            FeedMappingServiceClient feedMappingService = client.GetService(
                Services.V3.FeedMappingService);

            // Maps the FeedAttributeIds to the placeholder values. The FeedAttributeId is the
            // ID of the FeedAttribute created in the CreatedFeed method. This can be thought of
            // as the generic ID of the column of the new feed. The placeholder value specifies
            // the type of column this is in the context of a real estate feed (e.g.
            // a LISTING_ID or LISTING_NAME). The FeedMapping associates the feed column by ID to
            // this type and controls how the feed attributes are presented in dynamic content.
            // See https://developers.google.com/google-ads/api/reference/rpc/Google.Ads.GoogleAds.V3.enums#Google.Ads.GoogleAds.V3.enums.RealEstatePlaceholderFieldEnum.RealEstatePlaceholderField
            // for the full list of placeholder values.

            AttributeFieldMapping listingIdMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.ListingId].Id,
                RealEstateField = RealEstatePlaceholderField.ListingId
            };

            AttributeFieldMapping listingNameMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.ListingName].Id,
                RealEstateField = RealEstatePlaceholderField.ListingName
            };

            AttributeFieldMapping finalUrlsMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.FinalUrls].Id,
                RealEstateField = RealEstatePlaceholderField.FinalUrls
            };

            AttributeFieldMapping imageUrlMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.ImageUrl].Id,
                RealEstateField = RealEstatePlaceholderField.ImageUrl
            };

            AttributeFieldMapping contextualKeywordsMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.ContextualKeywords].Id,
                RealEstateField = RealEstatePlaceholderField.ContextualKeywords
            };

            // Creates the feed mapping.
            FeedMapping feedMapping = new FeedMapping()
            {
                PlaceholderType        = PlaceholderType.DynamicRealEstate,
                Feed                   = feedResourceName,
                AttributeFieldMappings =
                {
                    listingIdMapping,
                    listingNameMapping,
                    finalUrlsMapping,
                    imageUrlMapping,
                    contextualKeywordsMapping
                }
            };

            // Creates the operation.
            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            // Adds the FeedMapping.
            MutateFeedMappingsResponse response = feedMappingService.MutateFeedMappings(
                customerId.ToString(), new[] { operation });

            // Displays the results.
            foreach (MutateFeedMappingResult result in response.Results)
            {
                Console.WriteLine($"Created feed mapping with resource name" +
                                  $" '{result.ResourceName}'.");
            }
        }
        /// <summary>
        /// Creates a feed mapping for a given feed.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the flights feed is
        /// added.</param>
        /// <param name="feedAttributes">The feed attributes.</param>
        /// <param name="feedResourceName">The resource name of the feed.</param>
        private void CreateFeedMapping(GoogleAdsClient client, long customerId,
                                       Dictionary <FlightPlaceholderField, FeedAttribute> feedAttributes,
                                       string feedResourceName)
        {
            // Get the FeedMappingServiceClient.
            FeedMappingServiceClient feedMappingService = client.GetService(
                Services.V5.FeedMappingService);

            // Maps the FeedAttributeIds to the fieldId constants.
            AttributeFieldMapping flightDescriptionMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.FlightDescription].Id,
                FlightField     = FlightPlaceholderField.FlightDescription
            };

            AttributeFieldMapping destinationIdMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.DestinationId].Id,
                FlightField     = FlightPlaceholderField.DestinationId
            };

            AttributeFieldMapping flightPriceMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.FlightPrice].Id,
                FlightField     = FlightPlaceholderField.FlightPrice
            };

            AttributeFieldMapping flightSalePriceMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.FlightSalePrice].Id,
                FlightField     = FlightPlaceholderField.FlightSalePrice
            };

            AttributeFieldMapping finalUrlsMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.FinalUrls].Id,
                FlightField     = FlightPlaceholderField.FinalUrls
            };

            // Creates the feed mapping.
            FeedMapping feedMapping = new FeedMapping()
            {
                PlaceholderType        = PlaceholderType.DynamicFlight,
                Feed                   = feedResourceName,
                AttributeFieldMappings =
                {
                    flightDescriptionMapping,
                    destinationIdMapping,
                    flightPriceMapping,
                    flightSalePriceMapping,
                    finalUrlsMapping
                }
            };

            // Creates the operation.
            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            // Adds the FeedMapping.
            MutateFeedMappingsResponse response = feedMappingService.MutateFeedMappings(
                customerId.ToString(), new[] { operation });

            // Displays the results.
            foreach (MutateFeedMappingResult result in response.Results)
            {
                Console.WriteLine($"Created feed mapping with resource name" +
                                  $" '{result.ResourceName}'.");
            }
        }
    private static void createSitelinksFeedMapping(
        AdWordsUser user, SitelinksDataHolder sitelinksData) {
      // Get the FeedItemService.
      FeedMappingService feedMappingService =
        (FeedMappingService) user.GetService(AdWordsService.v201509.FeedMappingService);

      // Map the FeedAttributeIds to the fieldId constants.
      AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping();
      linkTextFieldMapping.feedAttributeId = sitelinksData.LinkTextFeedAttributeId;
      linkTextFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT;
      AttributeFieldMapping linkFinalUrlFieldMapping = new AttributeFieldMapping();
      linkFinalUrlFieldMapping.feedAttributeId = sitelinksData.LinkFinalUrlFeedAttributeId;
      linkFinalUrlFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_FINAL_URL;

      // Create the FieldMapping and operation.
      FeedMapping feedMapping = new FeedMapping();
      feedMapping.placeholderType = PLACEHOLDER_SITELINKS;
      feedMapping.feedId = sitelinksData.FeedId;
      feedMapping.attributeFieldMappings =
          new AttributeFieldMapping[] {linkTextFieldMapping, linkFinalUrlFieldMapping};
      FeedMappingOperation operation = new FeedMappingOperation();
      operation.operand = feedMapping;
      operation.@operator = Operator.ADD;

      // Save the field mapping.
      FeedMappingReturnValue result =
          feedMappingService.mutate(new FeedMappingOperation[] {operation});
      foreach (FeedMapping savedFeedMapping in result.value) {
        Console.WriteLine(
            "Feed mapping with ID {0} and placeholderType {1} was saved for feed with ID {2}.",
            savedFeedMapping.feedMappingId, savedFeedMapping.placeholderType,
            savedFeedMapping.feedId);
      }
    }