Google Product Feeds - Adding variants, color, and age_group to the Google Feed

MilesbdMilesbd Posts: 15Moderator, Lightspeed Staff moderator
edited February 4 in Tips, Tricks & How-To's

Introduction

This article aims to explain how to submit a feed of your products to Google Shopping, using a Custom Feed, Custom Template data, to include variants that exist in for your products. In this tutorial, we'll be using the "Color" and "Size" variants as examples,  (common variant attributes to many clothing retailers), along with "gender" and "age_group" which are product specifications that Google requires for all clothing products.

Google shopping is an excellent addition to any eCommerce site, and a great way to increase visibility on your products, and have them appear in search results to drive traffic directly to your site, and increase sales

Resources:

Prerequisites:

  • Comfortable working with Feeds
  • Google Merchant Account
  • Site Verified by Google
  • Google Shopping Codes for all products

Adding your Custom Feed

In Lightspeed:

  1. Navigate to Settings > Workflow and activate "Custom Template Data" (more about this in Configuring workflow settings for your online store)
  2. Navigate to Settings > Feeds > Go to Custom Feeds and click the "Add feed" button in the top right"
    1. Give the feed a new name (Suggested name: "Custom Google Shopping Feed"), and choose to copy from "Google Shopping", and hit save.
  3. You will be presented with a page full of code, don't panic, this is a good thing!



To add the "gender" and the "age_group" Product specifications:
  1. On this page, locate where it says 
    <description>{{ product.description | cdata }}</description>

  2. Beneath that is where we'll insert the product Specifications that are required by Google:
    1. Copy in the following beneath that line:
      <g:age_group> {{ product.data_03 | cdata }} </g:age_group>
      <g:gender> {{ product.data_02 | cdata }} </g:gender>
    2. Save changes once the page looks like this:
    3. In the above, we are using the "g:age_group" and the the "g:gender" specifications from Google, and sending the product data that you will be entering in those fields in the next step. If you need to specify another type of data, simply find the expected XML data format on the Google - Product data specification help page, and replace surrounding data identifiers with the data identifiers you need to provide:

    4. For example, instead of specifying "gender" for the product, you may need to specify "condition", therefore you would change "gender" from the example to "condition"":
      <g:gender> {{ product.data_02 | cdata }} </g:gender>
       
      becomes:
       
      <g:condition> {{ product.data_02 | cdata }} </g:condition>
    5. Add the gender to the data 02 and age group to the data 03 fields for products 
      1. this can be done on the product page , or by  editing products through an import
      2. Once completed, this is how it should look on the product's page (note we used "male" as the gender and "adult" as the age group in this example):                                                                            


To include the variants:

The first step we'll have to do is to create a duplicate of the "<item>" section, for the variants.

  1. Highlight the entire "item" section, which goes from "<item>" to "</item>"
  2. Locate in the code the following section that begins like this (it's near the beginning):
    {% for product in products %}
                <item>
                    <g:id>{{ product.id }}</g:id>
  3. Paste the copied "item" section between the "{% for product in products %}" and "<item>" lines.

Next we'll create a loop to use different code for items with variants

  1. Once again, Locate in the code the following section that begins like this (it's near the beginning):

    {% for product in products %}
                <item>
                    <g:id>{{ product.id }}</g:id>
  2. Insert the following lines  between the "{% for product in products %}" and "<item>" lines. We are first checking if there are more than one variant for the product, and if so, cycling through the variants to create separate items for each variant:
    {% if product.variants | length > 1 %}
              {% for variant in product.variants %}
  3. Next locate the two sections where one item ends and the next begins, it'll look like this:

    </item>
    <item>
  4. After the "</item>" line, insert the following, to stop the loop of cycling through variants for a product, and also to proceed to the regular single product code if there is only one variant:

    {% endfor %}
            {% else %}
  5. Locate in the code the following section that begins like this (it's near the end):
            {% endif %}
        </item>
    {% endfor %}
  6. Add in a second "{% endif %}" after the "</item>" line, making the section look like the following. This is done to close the "if statement that looks to see if there are multiple variants from a product:
                {% endif %}
            </item>
        {% endif %}
    {% endfor %}


Building out the code for the variants, the first "item" section.

  1. Firstly, we'll change the ID and add a group ID for the product, to do this, locate the section that looks like:
    {% if product.variants | length > 1 %}
             {% for variant in product.variants %}
               <item>
                   <g:id>{{ product.id }}</g:id>
  2. And insert the following to replace the <g:id>{{ product.id }}</g:id> iso that it looks like this (this is done to allow the products to be grouped together by Google): {% for product in products %} <item> <g:id> {{ product.id }}.{{ variant.id }} </g:id> <g:item_group_id>{{ product.id }}</g:item_group_id>
  3. Next, just a few lines below that, locate the section that looks like this:
    {% if product.google_category %}
    <g:google_product_category>{{ product.google_category | cdata }}</g:google_product_category>
    {% endif %}
    1. Add in the following code beneath it, which will parse the variant title to remove the words "Color :" and/or "Size :" , and add it as the relevant product identifier for a single attribute variant (i.e. size or color), or as product identifiers if a two attribute variant (if using both size and color). 

      {% for variant in product.variants %}
         {% if loop.index <=1 %}  {# only including the default variant attributes in the first product #}
      {# Parsing the title of the variants #}
           {% if 'Color' in variant.title and 'Size' not in variant.title %}
              <g:color>{{ variant.title | replace('Color : ', '') | cdata}}</g:color>
           {% elseif 'Size' in variant.title and 'Color' not in variant.title %}
              <g:size>{{ variant.title | replace('Size : ', '') | cdata}}</g:size>
           {% elseif 'Color:' in variant.title and 'Size:' in variant.title %}
              {% set splittitle = variant.title | split('","')[0] %}
              <g:color>{{ splittitle | replace('"Color: ', '') | cdata}}</g:color>
              {% set splittitle = variant.title | split('"Size: ')[1] %}
              <g:size>{{splittitle[:-1] | cdata}}</g:size>
              {% endif %}
        {% endif %}
      {% endfor %}

    2. If you're using a different variant attributes, such as "Material" and "Pattern" you would replace all instances of "Color" (spaces included) with "Material" and all instances of  "Size" with "Pattern" so that it looks like this:

      {% for variant in product.variants %}
         {% if loop.index <=1 %}  {# only including the default variant attributes in the first product #}
      {# Parsing the title of the variants #}
           {% if 'Material' in variant.title and 'Pattern' not in variant.title %}
              <g:material>{{ variant.title | replace('Material : ', '') | cdata}}</g:material>
           {% elseif 'Pattern' in variant.title and 'Material' not in variant.title %}
              <g:pattern>{{ variant.title | replace('Pattern : ', '') | cdata}}</g:pattern>
           {% elseif 'Material:' in variant.title and 'Pattern:' in variant.title %}
              {% set splittitle = variant.title | split('","')[0] %}
              <g:material>{{ splittitle | replace('"Material: ', '') | cdata}}</g:material>
              {% set splittitle = variant.title | split('"Pattern: ')[1] %}
              <g:pattern>{{splittitle[:-1] | cdata}}</g:pattern>
              {% endif %}
        {% endif %}
      {% endfor %}


  4. Next we'll want to add a link to the specific variant. Locate the line that looks like this:
    <link>{{ (product.url ~ '?source=googlebase') | url }}</link>

    And Replace the line with this one:
    <link> {{ ( product.url ~ '?id=' ~ variant.id ~ '?source=googlebase') | url }} </link>


  5. Almost done! Now we'll be adding availability based on variant stock level. Further down the page, locate the following section:
    {% if product.available %}
        <g:availability>in stock</g:availability>
    {% else %}
        <g:availability>out of stock</g:availability>
    {% endif %}

    Replace these lines with the following code:
    {% if variant.stock_level > 0 and product.stock_track %}
        <g:availability>in stock</g:availability>
    {% elseif not product.stock_track %}
        <g:availability>in stock</g:availability>
    {% else %}
        <g:availability>out of stock</g:availability>
    {% endif %}

    OPTIONAL: you can replace the same section in the second item section, to always show items for which you allow backorders as available with the following code:
    {% if product.stock_level > 0 and product.stock_track %}
        <g:availability>in stock</g:availability>
    {% elseif not product.stock_track %}
        <g:availability>in stock</g:availability>
    {% else %}
        <g:availability>out of stock</g:availability>
    {% endif %}
  6. Lastly, we'll be improving the pricing sent to Google, so that it is either inclusive or exclusive, depending on region. You can do the same Locate on the page the section that looks like this:
    {% if product.price.price_old_incl %}
        <g:price>{{ product.price.price_old_incl | money_float }} {{ shop.currency | upper }}</g:price>
        <g:sale_price>{{ product.price.price_incl | money_float }} {{ shop.currency | upper }}</g:sale_price>
    {% else %}
        <g:price>{{ product.price.price_incl | money_float }} {{ shop.currency | upper }}</g:price>
    {% endif %}

    Replace the section with the following code for tax exclusive shops (Mainly North America shops):
    {% if product.price.price_old_excl %}
        <g:price>{{ product.price.price_old_excl | money_float }} {{ shop.currency | upper }}</g:price>
        <g:sale_price>{{ product.price.price_excl | money_float }} {{ shop.currency | upper }}</g:sale_price>
    {% else %}
        <g:price>{{ product.price.price_excl | money_float }} {{ shop.currency | upper }}</g:price>
    {% endif %}

    Replace the section with the following code for tax inclusive shops (Mainly European shops):
    {% if product.price.price_old_incl %}
        <g:price>{{ product.price.price_old_incl | money_float }} {{ shop.currency | upper }}</g:price>
        <g:sale_price>{{ product.price.price_incl | money_float }} {{ shop.currency | upper }}</g:sale_price>
    {% else %}
        <g:price>{{ product.price.price_incl | money_float }} {{ shop.currency | upper }}</g:price>
    {% endif %}
  7. Save your changes!

To test your feed, close the feed editor by clicking on "Close" and then click the "View link" button, to ensure that it is working properly.

If your feed shows up in a new tab without errors, you're good to go!


In your Google Merchant Center

Now you have a feed that includes both the product identifiers for "gender" and "age_group" and can send over your variants to Google!

Follow the instructions from Google - Submit feeds via Scheduled Fetches Merchant Center. The URL of the feed you will be using is the URL of the Custom Feed that you have created, and to be sure to add:

  • "?google=true" (without quotes) to the end of your link after the forward slash ("/") to include Google Categories
  • "?include_variants=true" (without quotes) to the end of your link after the forward slash ("/") to include the Product Variants
  • "?google=true&include_variants=true"(without quotes) to the end of your link after the forward slash ("/") to include both Google Categories and Product Variants


Post edited by Milesbd on

3 comments

  • adlamoureuxadlamoureux Posts: 11Member

    I have tried to do this several times and it will not show variants. I have found this line of code does nothing - {% if product.variants | length > 1 %} .. please advise.

  • MilesbdMilesbd Posts: 15Moderator, Lightspeed Staff moderator

    Hi @adlamoureux !

    I'm sorry to hear that you're not seeing the variants show up!

    Have you added the "?google=true&includevariants=true" to the end of the XML feed? The "includevariants=true" is necessary in order for the feed to load the variants, and have the "{% if product.variants | length > 1 %}" conditional be true.

    If you're still having issues after that, please let us know!

  • DGsClaireDGsClaire Posts: 1Member

    I followed these instructions to the T, and I'm getting an internal server error. Did I do something wrong, or is this on AdVision's side?

Sign In or Register to comment.