Product Feeds for Google and Facebook

A data feed is a file made up of a list of products which use groupings of attributes that define each one of your products in a unique way. Attributes, such as 'condition' and 'availability', can have standardized values, or accepted "answers," or attributes can be open to fill with your own choice of value, such as 'id' or 'title'. Accurately describing your items using these attributes allows users to search and find your items more easily.

The examples below show how you can easily add a product feed to connect your LemonStand product catalog to some of the most popular ad and social media platforms.


Google Shopping Compatible Feed

The following is an example for a product feed that is compatible with the required Google Shopping format and can be connected via your Google Merchant Center account. Check out our in-depth article on how to connect this feed to Google Merchant Center so that you can set up Google Shopping campaigns here.

In the Store Design panel, create a new site template and set the "Content-Type" to "text/xml; charset=utf-8". The contents of your site template should simply be:

{{ page() }}

Now, create a new page template and set the Name and URL to "google-products.xml", and the Code to "googleproducts". Under settings, make sure the template is set to select the one created in the first step, and the action is set to "shop:products".  The Content of the page should be similar to the example code below, although knowledgeable developers may customize this. You should definitely update the text in the title and description to name and describe your business:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"> 
    <channel> 
        <title>Your store name here</title> 
        <link>{{ site_url('/') }}</link> 
        <description>Your store description here</description> 
    {% set displayVariantsCollection = 'display-variants'|collection %}
    {% set ids = [] %}
    
    {% for product in displayVariantsCollection.products %}
        {% set ids = ids|merge([product.id]) %}
    {% endfor %}
    {% for product in products %}
        {% if product.id in ids %}
            {% for variant in product.productVariants %}
                {{ partial('shop-google-product-list-xml', {'product': product, 'variant': variant}) }} 
            {% endfor %}
        {% else %}          
            {{ partial('shop-google-product-list-xml', {'product': product}) }}
        {% endif %}
    {% endfor %} 
    
    </channel> 
</rss>

In this page we also will push some products and any related variants to our feed. All the products in the collection 'display-variants' will have their variants displayed in the feed alongside the rest of the products.

Next, create a partial block with the Code set to "shop-google-product-list-xml" and include the code below in the Content section:

{% set variant = variant|default(null) %}
{% if variant %}
    {% set id = "Variant_#{variant.id}" %}
    {% set url = "https:#{site_url('/')}product/#{product.url_name}?" %}
    {% for key, value in variant.getOptionsArray %}
        {% set url = url ~ "options[#{key}]=#{value}&" %}
    {% endfor %}
    {% set image = 'https:' ~ product.images.first.thumbnail('auto','auto') %}
    {% set price = variant.base_price ? variant.base_price : product.price %}
    {% set sku = variant.sku %}
    {% set gtin = variant.barcode %}
    {% set weight = variant.weight %}
{% else %}
  {% set id = "Product_#{product.id}" %}
  {% set url = "https:#{site_url('/')}product/#{product.url_name}" %}
  {% set image = 'https:' ~ product.images.first.thumbnail('auto','auto') %}
  {% set price = product.price %}
  {% set sku = product.sku %}
  {% set gtin = product.barcode %}
  {% set weight = product.weight %}
{% endif %}
{% set item = variant ? variant : product %}
{% if not item.isOutOfStock() %}
    {% set availability = 'in stock' %}
{% elseif product.allow_preorder %}
    {% set availability = 'preorder' %}
{% else %}
    {% set availability = 'out of stock' %}
{% endif %}
    
<item> 
    <g:id>{{ id }}</g:id> 
    <g:title>{{ product.name }} </g:title>
    <g:description>{{ product.description|striptags }} </g:description>
    <g:link>{{ url }}</g:link>
    <g:image_link>{{ image }}</g:image_link>
    <g:price>{{ price }} USD</g:price>
    <g:condition>new</g:condition>
    <g:availability>{{ availability }}</g:availability>
    <g:brand>{{ product.manufacturer.name }} </g:brand>
    <g:mpn>{{ sku }} </g:mpn>
    <g:gtin>{{ gtin }} </g:gtin>
    <g:shipping_weight>{{ weight }} lbs</g:shipping_weight>
    
    
    
    {% if variant %}
        {% for opts in variant.product_options %}
            {% if opts.name == 'Color' %}
              {% set val = opts.pivot.value %}
              {% for key, value in opts.values %}
                {% if key == val %}
                   <g:color>{{ value }}</g:color>
                {% endif %}
              {% endfor %}
            {% endif %}
        {% endfor %}
    {% endif %}
</item>

The units for price and shipping weight may need to be adjusted to match the units you're using for your store. Also, depending on what your variants are you may need to customize the last part of the code in the partial. In the example it assumes the variant is Color. However, that might not be the case for your products. 

Note that this example doesn't include all of the possible fields you can send in a Google product feed, but it does include all required fields as well as some others that are often used. You can get more information about the Google product feed here.


Facebook and Instagram Compatible Feed

The following is an example for a product feed that is compatible with the required Facebook product catalog format and can be connected via your Facebook Catalog Manager account. To learn more about how you can connect this feed to a Facebook Shop account and from there create Instagram Shoppable Posts - check out our help article here.

In the Store Design panel, create a new site template and set the "Content-Type" to "text/xml; charset=utf-8". The contents of your site template should simply be:

{{ page() }}

Now, create a new page template and set the Name and URL to "fb-products.xml", and the Code to "fbproducts". Under settings, make sure the template is set to select the one created in the first step, and the action is set to "shop:products".  The Content of the page should be similar to the example code below, although knowledgeable developers may customize this. You should definitely update the text in the title and description to name and describe your business:

<?xml version="1.0"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <channel>
        <title>Your store name here</title>
        <link>{{ site_url('/') }}</link>
        <description>Your store description here</description>

    {% set displayVariantsCollection = 'display-variants'|collection %}
    {% set ids = [] %}
    
    {% for product in displayVariantsCollection.products %}
        {% set ids = ids|merge([product.id]) %}
    {% endfor %}
    {% for product in products %}
        {% if product.id in ids %}
            {% for variant in product.productVariants %}
                {{ partial('shop-fb-product-list-xml', {'product': product, 'variant': variant}) }} 
            {% endfor %}
        {% else %}          
            {{ partial('shop-fb-product-list-xml', {'product': product}) }}
        {% endif %}
    {% endfor %} 
    
    </channel> 
</rss>

In this page we also will push some products and any related variants to our feed. All the products in the collection 'display-variants' will have their variants displayed in the feed alongside the rest of the products.

Next, create a partial block with the Code set to "shop-fb-product-list-xml" and include the code below in the Content section:

{% set variant = variant|default(null) %}
{% if variant %}
    {% set id = "Variant_#{variant.id}" %}
    {% set url = "https:#{site_url('/')}product/#{product.url_name}?" %}
    {% for key, value in variant.getOptionsArray %}
        {% set url = url ~ "options[#{key}]=#{value}&" %}
    {% endfor %}
    {% set image = 'https:' ~ product.images.first.thumbnail('auto','auto') %}
    {% set price = variant.base_price ? variant.base_price : product.price %}
    {% set sku = variant.sku %}
    {% set gtin = variant.barcode %}
    {% set weight = variant.weight %}
{% else %}
  {% set id = "Product_#{product.id}" %}
  {% set url = "https:#{site_url('/')}product/#{product.url_name}" %}
  {% set image = 'https:' ~ product.images.first.thumbnail('auto','auto') %}
  {% set price = product.price %}
  {% set sku = product.sku %}
  {% set gtin = product.barcode %}
  {% set weight = product.weight %}
{% endif %}
{% set item = variant ? variant : product %}
{% if not item.isOutOfStock() %}
    {% set availability = 'in stock' %}
{% elseif product.allow_preorder %}
    {% set availability = 'preorder' %}
{% else %}
    {% set availability = 'out of stock' %}
{% endif %}
    
<item> 
    <g:id>{{ id }}</g:id> 
    <g:title>{{ product.name }} </g:title>
    <g:description>{{ product.description|striptags }} </g:description>
    <g:link>{{ url }}</g:link>
    <g:image_link>{{ image }}</g:image_link>
    <g:price>{{ price }} USD</g:price>
    <g:condition>new</g:condition>
    <g:availability>{{ availability }}</g:availability>
    <g:brand>{{ product.manufacturer.name }} </g:brand>
    <g:mpn>{{ sku }} </g:mpn>
    <g:gtin>{{ gtin }} </g:gtin>
    
</item>

The unit for price may need to be adjusted to match the units you're using for your store. Also, Facebook has some strict guidance around image dimensions (see excerpt from their feed specification below) - so you may need to manually set the dimensions in the product.images.first.thumbnail() call shown in the feed, which defaults to auto sizing images to their natural size: 

The URL for the image used in your ad. For square (1:1) aspect ratios in the carousel ad format, your image should be 600x600. For single image ads, your image should be at least 1200x630.

Note that this example doesn't include all of the possible fields you can send in a Facebook product feed, but it does include all required fields as well as some others that are often used. You can get more information about the Facebook product feed here.