/// <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.V5.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}'");
        }
        private static void createSitelinksFeedMapping(AdWordsUser user,
                                                       SitelinksDataHolder sitelinksData)
        {
            using (FeedMappingService feedMappingService =
                       (FeedMappingService)user.GetService(AdWordsService.v201705.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;

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

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

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

                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);
                }
            }
        }
Exemplo n.º 3
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}'.");
        }
        /// <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);
        }
Exemplo n.º 5
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.v201806.FeedMappingService)) {
                // Map the FeedAttributeIds to the fieldId constants.
                AttributeFieldMapping urlFieldMapping = new AttributeFieldMapping {
                    feedAttributeId = feedDetails.urlAttributeId,
                    fieldId         = DSA_PAGE_URLS_FIELD_ID
                };

                AttributeFieldMapping labelFieldMapping = new AttributeFieldMapping {
                    feedAttributeId = feedDetails.labelAttributeId,
                    fieldId         = DSA_LABEL_FIELD_ID
                };

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

                FeedMappingOperation operation = new FeedMappingOperation {
                    operand   = feedMapping,
                    @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);
                }
            }
        }
Exemplo n.º 6
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);
      }
    }