# How to build Google Shopping feeds with publications

Streamline your workflow and guarantee top-notch data quality with Struct PIM Publications, ensuring your product files always adhere to Google’s rigid feed requirements.

In this guide you will learn how to set up a publication template that fits the requirements for uploading product data to Google Merchant Center with Razor.

### Getting started

To get started, we first need to create the publication template that will outline the structure for our data that we want to submit to Google Merchant Center.&#x20;

First, navigate to the 'Publication'-page, and navigate to 'Publication template'.

<figure><img src="/files/1B9TBsRKgicsSWtXqKnf" alt=""><figcaption></figcaption></figure>

### Building the template

To create a new template, click the 'Create publication template' in the top right corner. This will take you to the template creation page.

The most important thing for this template is that we set the 'Type' to 'Data'. The reason for this is that we want to export the data in a specific format, and the 'Data' type allows this.

Give it a relevant name, and if you want to, an external ref.

<figure><img src="/files/o5fBmx6a4IovVc0jE4eT" alt=""><figcaption></figcaption></figure>

Click 'Create'.

The page will expand, and you will be met with further settings. To learn more about what they are individually, you can read more about them in our [references](/reference/publication/publication-template.md).

For this guide, we will select a rendering engine, file format and value properties.&#x20;

1. Add 'RenderedValue' to value properties.
2. Set the rendering engine to 'Razor'.
3. Set the file format to XML since Google Merchant Center accepts XML.

<figure><img src="/files/ohn75jQs6MCkazErDM0x" alt=""><figcaption></figcaption></figure>

Click 'Update'.

The template settings are now saved. The next step is designing the actual structure of the data. To do so, find the newly created template in the list, hover over it and click the <i class="fa-eye">:eye:</i>-icon to open the designer.

### Designing the template

Now we will go ahead and design the template so that it complies with Google Merchant Center requirements. You can read more about what specific requiremenets are relevant on this [Google Merchant Center support article](https://support.google.com/merchants/answer/7052112?sjid=16651467138675662121-EU\&visit_id=639075318603304852-1809807655\&rd=1).

The most essential required tags are <kbd>id</kbd>, <kbd>title</kbd>, <kbd>description</kbd>, <kbd>link</kbd>, <kbd>image\_link</kbd>, <kbd>brand</kbd>, <kbd>gtin</kbd>, <kbd>availability</kbd>, <kbd>price</kbd> and <kbd>condition</kbd>. However, additional tags will be required depending on what you are trying to publish. The requirements for products differ from the requirements for categories for example.

{% code title="XML" lineNumbers="true" %}

```xml
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <channel>
      <link></link>
      <description></description>
      <item>
        <g:id></g:id>
        <g:title></g:title>
        <g:description></g:description>
        <g:link></g:link>
        <g:image_link></g:image_link>
        <g:brand></g:brand>
        <g:gtin></g:gtin>
        <g:availability></g:availability>
        <g:price></g:price>
        <g:condition></g:condition>
      </item>
    </channel>
  </rss>
```

{% endcode %}

{% hint style="info" %}
Google is very strict regarding what you can type into the different tags. You can learn more about the field specific values [here](https://support.google.com/merchants/answer/7052112?sjid=16651467138675662121-EU\&visit_id=639075318603304852-1809807655\&rd=1).
{% endhint %}

Now that we have the template, we can go ahead and build an automated structure that fills out the different tags with the relevant product information. The following Razor-code should be placed inside the "HTML"-tab in the 'Content'-window.

{% code title="ASP.NET Razor" lineNumbers="true" %}

```razor
    <channel>
        @{
            string website = "https://my-webshop.com";
        }
        <link>@website/</link>
        <description>Product feed from Struct PIM to Google Merchant Center</description>

        @foreach(var product in Model.Products)
        {
            @{

                string price = string.Empty;
                string currency = string.Empty;
                var priceValue = product.AttributeValues.CostPrices?.Values;
                if(priceValue != null) {
                    price = priceValue[0].SubAttributeValues?.Price.RenderedValue;
                    
                    var currencyValue = product.AttributeValues.CostPrices?.Values[0].SubAttributeValues?.Currency.Values;
                    if(currencyValue != null) {
                        currency = currencyValue[0].SubAttributeValues?.Name.RenderedValue;
                    }
                }

                string priceWithCurrency = $"{price} {currency}";

                string descriptionValue = product.AttributeValues.Description.RenderedValue ?? "";
                string description = string.IsNullOrEmpty(descriptionValue) ? "" : descriptionValue;

                string gtinValues = product.AttributeValues.GTIN?.RenderedValue;
                string gtin = string.IsNullOrEmpty(gtinValues) ? "" : gtinValues;

                var inStockValue = product.AttributeValues.InStock;
                var inStock = inStockValue ?? "False";

                string imageLinkValue = product.AttributeValues.WebshopLink?.RenderedValue ?? "";
                string imageLink = !string.IsNullOrEmpty(imageLinkValue) 
                    ? $"{imageLinkValue.TrimEnd('/')}/{product.ProductRef}.jpg" 
                    : "";

                var brandValues = product.AttributeValues.Brand?.Values;
                string brandName = (brandValues != null && brandValues.Count > 0) 
                    ? brandValues[0].SubAttributeValues?.Name?.RenderedValue 
                    : "N/A";

                var statusValues = product.AttributeValues.EnrichmentStatus?.Values;
                string condition = (statusValues != null && statusValues.Count > 0) 
                    ? statusValues[0].RenderedValue.ToLower() 
                    : "new";

                string entityWebsiteLink = $"{website}/product/{product.Id}";
            }

            <item>
                <g:id>@product.Id</g:id>
                <g:title><![CDATA[@product.AttributeValues.Name.RenderedValue]]></g:title>
                <g:description><![CDATA[@description]]></g:description>
                <g:link>@entityWebsiteLink</g:link>
                <g:image_link>@imageLink</g:image_link>
                <g:brand><![CDATA[@brandName]]></g:brand>
                <g:gtin>@gtin</g:gtin>
                <g:availability>@inStock</g:availability>
                <g:price>@priceWithCurrency</g:price>
                <g:condition>@condition</g:condition>
            </item>
        }
    </channel>
```

{% endcode %}

Next, we need to add the base template so that Google Merchant Center can recognize the format.

Go to the 'Base template'-window and paste the following code:

{% code title="XML" lineNumbers="true" %}

```xml
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <content></content>
</rss>
```

{% endcode %}

The reason behind this is that by default, the designer encapsulates your XML with a <kbd>\<products></kbd> tag and Google Merchant Center requires that the first tag of the file is a <kbd>\<rss></kbd> tag.

### Create the print publication

The next step we need to do is print the publication and make sure everything works as expected. To do so, head over to 'Print publications' in the menu on the left hand side of the screen.

Here, we can create a new print publication, which will use the template we have just created.

<figure><img src="/files/9csEsNfkmh68pF0rjgbl" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If you are unfamiliar with print publications, you can read more about them in our [references](/reference/publication.md).
{% endhint %}

Give it a relevant name, select the product category you want to print and set the data template to the template we created above.

<figure><img src="/files/FSTNBx1iGa2Qh6uq52J0" alt=""><figcaption></figcaption></figure>

The only thing left is printing the publication.

Click 'Create', and hover over the print publication in the grid. Click the 'Produce print publication'-icon.

Click 'Confirm'.

<figure><img src="/files/o7gURIkpFgm5JrylPswk" alt=""><figcaption></figcaption></figure>

The publication will be downloaded as an XML file to your computer.

You are now all set and ready. The last thing to do is upload it to Google Merchant Center. Read more about how to upload files [here](https://support.google.com/merchants/answer/11586438?hl=en\&ref_topic=12672304\&sjid=3610985262738847032-EU#sync-file).

#### Download the template

You can download and experiment with the template shown in this guide below.

{% file src="/files/30zPjOoZtkDGwFuu8xuR" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.struct.com/tutorials/guides/how-to-use-publications/how-to-build-google-shopping-feeds-with-publications.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
