Feeds

Use FeedService to create a Feed, which describes the shape of the data to be uploaded. The feed is analogous to a database table, and it may contain multiple FeedAttributes, which act as its database columns. Each attribute has a name and a type.

Since we will be creating data for sitelinks in the example below, we need to specify:

  • Link text
  • Link final URLs
  • Line 1
  • Line 2

The final rendered sitelink allows 2 lines of description in addition to the link itself.

Make sure to specify a feed origin of USER to tell Google Ads that this feed will be populated by user data, not automatically by Google Ads itself.

It is important to retrieve the full feed after creation to fetch all the relevant attribute IDs, which will be required in order to populate data to the correct attributes when creating feed items in the next step.

Ruby

client = Google::Ads::GoogleAds::GoogleAdsClient.new

feed = client.resource.feed do |f|
  f.name = "example feed"
  f.origin = :USER

  # Specify the column name and data type. This is just raw data at this point,
  # and not yet linked to any particular purpose. The names are used to help us
  # remember what they are intended for later.
  f.attributes << client.resource.feed_attribute do |fa|
    fa.name = "Link Text"
    fa.type = :STRING
  end
  f.attributes << client.resource.feed_attribute do |fa|
    fa.name = "Link Final URL"
    fa.type = :URL_LIST
  end
  f.attributes << client.resource.feed_attribute do |fa|
    fa.name = "Line 1"
    fa.type = :STRING
  end
  f.attributes << client.resource.feed_attribute do |fa|
    fa.name = "Line 2"
    fa.type = :STRING
  end
end

operation = client.operation.create_resource.feed(feed)

feed_resource_name =
    client.service.feed.mutate_feeds(customer_id, [operation]).results.first.resource_name

# After we create the feed, we need to fetch it so we can determine the
# attribute IDs, which will be required when populating feed items.
feed = client.service.google_ads.search(
  customer_id,
  "select feed.attributes from feed where feed.resource_name = '#{feed_resource_name}'"
).first.feed

attribute_ids = feed.attributes.map {|attribute| attribute.id}