Last update on .


Don't forget to share this post



JS Code for Merchant Listing Requirements
JS Code for Merchant Listing Requirements

Google has recently introduced new guidelines regarding shipping details and merchant return policies to enhance merchant listings experience. These guidelines have been added to the product structured data help section.

This update is significant for businesses selling products. By including merchant return policy and shipping details in their structured data, along with the product price, reviews, and other rich result properties, businesses can enhance their visibility and attract more attention within Google Search. This, in turn, may impact their click-through rates positively from Google Search.

If you have exceptional shipping details and return policies, it is advisable to emphasize them through the Google Merchant Center and structured data to ensure their visibility within Google Search.

OfferShippingDetails and MerchantReturnPolicy are key requirements for the Rich Result experience in the Merchant listings of the Product schema. Your schema must include these properties, in addition to other specifications such as offer and price, to ensure compliance with the Rich Result guidelines.

Google Tag Manager can be used as a convenient method for adding offer shipping details and merchant return policy to an existing product schema using JavaScript.

If you have a WordPress website with an existing Product schema that lacks the necessary requirements for a merchant listing experience, and you're unsure how to add them, this article is tailored to help you.

I would like to express my gratitude to my friend Marcelo for bringing this issue to my attention. It is an important matter since numerous WordPress users face the same problem. Marcelo, a professional SEO consultant from Uruguay who has found a paid yet straightforward solution to this problem. I personally recommend him if you are in need of assistance.

In this article, I will guide you step by step on how to optimize the merchant listing experience to successfully pass the rich result test with no errors or warnings.

MerchantReturnPolicy Technical Details:

MerchantReturnPolicy has the following required properties:
Additionally, MerchantReturnPolicy has the following recommended properties:
  • merchantReturnDays: Specifies either a fixed return date or the number of days (from the delivery date) that a product can be returned. Used when the returnPolicyCategory property is specified as MerchantReturnFiniteReturnWindow.

  • returnFees: This property describes the type of return fees. It is required only if there are no costs associated with returning the product. When using this property, the value must be set to https://schema.org/FreeReturn. Other return fee types are not supported. If there are fees, the returnShippingFeesAmount property should be used instead.

  • returnMethod: This property specifies the type of return method offered. It is recommended only if the returnPolicyCategory is set to either MerchantReturnFiniteReturnWindow or MerchantReturnUnlimitedWindow.

  • If you have different return methods you can find all the options here:
    1. https://schema.org/ReturnAtKiosk: The item can be returned at a kiosk.
    2. https://schema.org/ReturnByMail: The item can be returned by mail.
    3. https://schema.org/ReturnInStore: The item can be returned in store.
  • returnShippingFeesAmount: This property denotes the cost of shipping for product returns. It is required only if there is a shipping cost associated with returning a product. If the cost is zero, the returnFees property should be used instead.

OfferShippingDetails Technical Details:

OfferShippingDetails has the following required propeties:
  • deliveryTime: The total delay between the receipt of the order and the goods reaching the final customer. The following properties can be nested in the deliveryTime property:
    • handlingTime
    • transitTime
    • Don't provide more than one deliveryTime
  • shippingDestination: Specify the shippingDestination.addressCountry information. See also the list of DefinedRegion properties supported by Google.
  • shippingRate: Information about the cost of shipping to the specified destination. At least one of shippingRate.value or shippingRate.maxValue must be specified, along with shippingRate.currency.
    • You can only specify one shippingRate per OfferShippingDetails property. To indicate multiple rates for your product, specify multiple OfferShippingDetail properties.
  • shippingRate currency: The currency of the shipping cost, in 3-letter ISO 4217 format. The currency must be the same as the currency of the offer.
  • shippingRate value or shippingRate.maxValue: The cost of shipping to the shippingDestination. If a string is used to provide the value, don't include currency symbols, thousands separators, or spaces.To specify free shipping, set the value to 0.

To begin, let's review and examine the existing free-built Woocommerce schema on your WordPress website. This schema consists of properties, which are essentially key-value pairs that describe the attributes of your product. Here is an example of how the schema appears:

Wordpress Original Product Code

Shipping details and merchant return policy are often missing from the default schemas of most free plugins in WordPress. here is an example of a default Product schema:

product schema code *example*

<script type="application/ld+json">
{
      "@context": "https://schema.org/",
      "@type": "Product",
      "@id": "#product",
      "name": "Product Name",
      "url": "page URL",
      "description": "product description",
      "image": "https://schemantra.com/static/sqwizo/assets/img_new/optimized.gif",
      "sku": 321,
      "offers": 
        {
          "@type": "Offer",
          "price": "69",
          "priceCurrency": "USD",
          "availability": "http://schema.org/InStock",

          "seller": {
            "@type": "Organization",
            "name": "company name here",
            "url": "company url here"
          }
       }
}
</script>

Upon validating this product schema code using the rich result testing tool, the following outcome is obtained: missing shippingDetails and hasMerchantReturnPolicy schema

The validation results clearly indicate the absence of the shippingDetails field (optional), the hasMerchantReturnPolicy field (optional).

To address these issues and improve the merchant listing experience, let's begin by incorporating shippingDetails to the product schema.

italicised text

Creating a OffershippingDetails Object for a Product Schema

To make your products eligible for the merchant listing experience, let\’s start by creating an offerShippingDetails object.

You can easily create an OfferShippingDetails schema using Schemantra and add all these properties by clicking on add sub-schema.

Here is an illustrative instance of a shipping details object for an offer, encompassing all the essential attributes. It is important to note that this object adheres to the structure of a typical schema, with the exclusion of the JSON-LD script tag \<script type="application/ld+json/>. Instead, it has been replaced with a JavaScript object named \"Shipping\"

Shipping = 
{
          "@type": "OfferShippingDetails",
          "@id": "#shipping",
          "shippingRate": {
            "@type": "MonetaryAmount",
            "value": 3.49,
            "currency": "USD"
          },
          "shippingDestination": {
            "@type": "DefinedRegion",
            "addressCountry": "US"
          },
          "deliveryTime": {
            "@type": "ShippingDeliveryTime",
            "handlingTime": {
              "@type": "QuantitativeValue",
              "minValue": 0,
              "maxValue": 1,
              "unitCode": "DAY"
            },
            "transitTime": {
              "@type": "QuantitativeValue",
              "minValue": 1,
              "maxValue": 5,
              "unitCode": "DAY"
            }
          }
        }

Creating MerchantReturnPolicy Object for a Product Schema

Below is a practical demonstration of a MerchantReturnPolicy, showcasing all the essential attributes. It is worth noting that this schema follows the conventional structure but with the omission of the JSON-LD script tag \<script type="application/ld+json">.

Instead, it has been replaced with a JavaScript object named "Merchant"

You can easily create MerchantReturnPolicy schema by using Schemantra

Merchant = 
{
          "@type": "MerchantReturnPolicy",
          "id": "#merchant", 
          "applicableCountry": "CH",
          "returnPolicyCategory": "https://schema.org/MerchantReturnFiniteReturnWindow",
          "merchantReturnDays": 60,
          "returnMethod": "https://schema.org/ReturnByMail",
          "returnFees": "https://schema.org/FreeReturn"
        }

Having successfully established the offerShippingDetails and MerchantReturnPolicy, our next objective is to integrate them into the current product schema, thereby enriching the merchant listing experience.

Finding and selecting the Product schema

To inject the previously created objects into the product schema, we need to locate and select the existing product schema on the page.

To find the product schema:

  • Go to the product page you intend to enhance, right-click, and choose \"Inspect\" from the context menu.
  • Go to the console tab as shown in image (A)
  • In the \"Console\" tab, copy and paste the following code as in (B):
  • document.querySelectorAll("script[type='application/ld+json']")
  • Note that in (C) there are two scripts available, and our goal is to identify and select the right script containing the product code. chrome inspect mode console tab

Let's start by selecting the first script and verifying if it corresponds to the desired code.

  • In the console tab, enter the following code:
  • document.querySelectorAll("script[type='application/ld+json']")[0] select JSON-LD
  • Select the code, copy it and paste it in the schema validator.
  • If it is the product schema then this is the code we are looking for, if not we do the same for the second code, apparently this is not the code we are looking for.
  • Now let’s select the second script.
  • Go back to the inspect mode - console tab and type the following code document.querySelectorAll("script[type='application/ld+json']")[1] select second JSON-LD
  • Copy the output code and paste it in the schema validator.

product schema validator example

As you can see its the product schema so we want to keep the selection code, note that this code contains two codes, one for breadcrumbs and the other is for the Product code, so the product schema is not the first code it is the second code but both codes are written in the same graph, so we still have to select the second code within the second script.

product and breadcrumb list schema validator example

In most common programming languages such as Python, Javascript and C counting or indexing of elements begins from 0, This implies that to access the first element, we utilize the index 0. Similarly, to retrieve the second element, we use the index 1, and the pattern continues for subsequent elements.

But in this case selecting the second code is not a straightforward approach, hence that 2 codes are embedded in the same graph, so first we have to select the code and then parse it in order to select its elements so this is what we do:

  • Select the second code: schema = document.querySelectorAll("script[type='application/ld+json']")[1]
  • Parse the schema object parseSchema = JSON.parse(schema.innerHTML)
  • Select the product inside the parsed object (note that the product is the second object within the code and thats why we used the number one) parseSchema['@graph'][1]
  • Assign hasMerchantPolicy inside the product offer Object.assign(parseSchema['@graph'][1]['offers'], {"hasMerchantReturnPolicy" : merchant})
  • Assign shippingDetails inside the product offer Object.assign(parseSchema['@graph'][1]['offers'], {"shippingDetails" : shipping})

Now that I have explained the most important elements in the code, I will proceed to compile them all together and create a unified script.

The entire code looks like this:

<script>
    // find the right json ld code
    var schema = document.querySelectorAll("script[type='application/ld+json']")[1]
    // add merchan listing object
    var Merchant = {
      "@context": "http://www.schema.org",
      "@type": "MerchantReturnPolicy",
      "id": "#merchant",
      "applicableCountry": "UY",
      "returnPolicyCategory": "https://schema.org/MerchantReturnFiniteReturnWindow",
      "merchantReturnDays": 2,
      "returnFees": "https://schema.org/FreeReturn",
      "returnMethod": ["https://schema.org/ReturnByMail", "https://schema.org/ReturnInStore"]

  }
    // add shipping details
    var Shipping = {
          "@type": "OfferShippingDetails",
          "@id": "#shipping",
          "shippingRate": {
            "@type": "MonetaryAmount",
            "value": 3.49,
            "currency": "USD"
          },
          "shippingDestination": {
            "@type": "DefinedRegion",
            "addressCountry": "US"
          },
          "deliveryTime": {
            "@type": "ShippingDeliveryTime",
            "handlingTime": {
              "@type": "QuantitativeValue",
              "minValue": 0,
              "maxValue": 1,
              "unitCode": "DAY"
            },
            "transitTime": {
              "@type": "QuantitativeValue",
              "minValue": 1,
              "maxValue": 5,
              "unitCode": "DAY"
            }
          }
        }

    // parse the schema
    parseSchema = JSON.parse(schema.innerHTML)
    schema.innerHTML = ""
   //remove the old schema
    schema.remove()

    // add hasmerchantreturnpolicy and shippingDetails
    parseSchema['@graph'][1]['offers'] = parseSchema['@graph'][1]['offers'][0]
    Object.assign(parseSchema['@graph'][1]['offers'], {"hasMerchantReturnPolicy" : Merchant})
    Object.assign(parseSchema['@graph'][1]['offers'], {"shippingDetails" : Shipping})

    // create the code
    var myBody = document.getElementsByTagName("body")
    var myScript = document.createElement('script')
    myScript.type = 'application/ld+json'
    myScript.id = "Schemantra"
    myScript.innerHTML = JSON.stringify(parseSchema) 
    myBody[0].appendChild(myScript)

</script>

Notes:

  • you can copy paste the code above to optimize your own merchant listing expoerience except for the following changes.
  • The properties in Merchant and Shipping objects in line 6 and line 18 has to be changed according to your product details. MerchantReturnPolicy schema code
  • The number in line 4 has to be changed according to your product location on the page. JS selection highlight
  • The highlighted code in line 54, 55 and 56 are all the same, if you change one, you have to make the others similar. 2nd selection JavaScript
  • The code in line 54 has to be changed to the right selection in order to select the right element.
  • Everything else stays the same.

To add the JavaScript code, you can paste it directly on the page at the end of the body section or you can add it through Google Tag Manager

How to add JavaScript code using Google Tag Manager

  • Log into Google Tag Manager
  • In the Tags section click New to Create new tag. GTM create new tag
  • In the tag configuration choose custom HTML. GTM tag configration
  • Paste the entire code above and name the tag anything you want. GTM tag name
  • In the Triggering section click the plus sign in the top right corner. GTM trigger section
  • In the trigger configration select pageView. GTM pageview
  • And then select which page you want the page to be triggered by choosing Page URL, contains and the page URL. GTM tag rule
  • Save everything and then click Submit. GTM submit

Now the code is live

To check the code, go to the schema validator and the rich result testing tool and test your page If you have any problem please explain it in the structured data forum, or in the schema markup community group, please paste your code and the URL you are trying to setup and i will help you out.

Pingbacks

Pingbacks are closed.

Comments

No comments yet.

Login to comment