Shopify International - Front End addition
Shopify International - JS API version
How it works
This approach is based on a new JS API migrateToShopifyMarket.
Using this API, you can load Nosto campaigns with following details updated for the current market, automatically.
Product URL - updates Product URL for every product in the recommendation to match the URL of the store's market. At the same time, the URL will retain all the attribution parameters from the original URL
Product Title - updates Product Title, for every product in the recommendation, to reflect the language of the current market
Product Description - updates Product description, for every product in the recommendation, to reflect the language of the current market
Product Category - updates Product category, for every product in the recommendation, to reflect the language of the current market. Please note that this only affects the main category (fetched from Shopify's "Product Type" field).
Product Variant Options - For those recommendations containing variant selectors, this API translates all the variant options and title to reflect the language of the current market.
Product Price - updates Price & List-Price showing to match currency and price of customers location.
Before you start
There are two small changes needed in your Shopify code.
You need to manually remove or comment out the following code-snipped from
nosto-tagging.liquid
:
You need to manually add the following snipped to your
theme.liquid
:
Usage
The API takes an Object RecProductElementSelectors
as a single parameter. The following table lists all the allowed mandatory and optional parameters of RecProductElementSelectors
Object
productSectionElement
Required
String
CSS selector of the element containing all the product details and the variant options
productUrlElement
Required
String
CSS selector of all a
elements within productSectionElement
containing the product URL
productTitleElement
Required
String
CSS selector of all elements within the productSectionElement
element containing the product title
productHandleAttribute
Required
String
Attribute name for fetching the product handle. This value can be fetched in recommendation template using $!product.lastPathOfProductUrl
. This attribute has to be part of the same element referenced by productSectionElement
priceElement
Required
String
CSS selector of all elements within the productSectionElement
element containing the product price
listPriceElement
Optional
String
CSS selector of all elements within the productSectionElement
element containing the product list price. This is used only when the product has a discounted price and the recommendation displays both old & new price.
defaultVariantIdAttribute
Optional
String
Attribute name for selecting the product variant. The first product variant is used if this is not provided. This attribute has to be part of the same element referenced by productSectionElement
.
descriptionElement
Optional
String
CSS selector of all elements within the productSectionElement
element containing the product description
totalVariantOptions
Optional
Number
Number of variant options used in the recommendation template. Useful when the recommendation doesn't display all the product variant options in the recommendation
variantSelector
Optional
Object/VariantOptionSelector
Needed only when recommendations display variant options. More on this in the next section
The following table lists all the allowed mandatory and optional parameters of VariantOptionSelector
Object. This parameter is required only when the recommendation displays variant options.
titleElement
Optional
String
CSS classname selector/Id of the element hosting the variant option title. Either this or optionElement
selector must be provided. Both are not mandatory. Title element won't be updated when this option is ignored
optionElement
Optional
String
CSS classname selector of all the elements hosting the variant option values. This selector should be in-depth such that it directly points to the element hosting the option value. Either this or titleElement
selector must be provided. Both are not mandatory. Option elements won't be updated when this option is ignored
selectedElement
Optional
String
Must be provided when optionElement
selector is provided. CSS selector/id of the element selected in the variant option. In case of multiple variant options, It's required to use the same selector across all the variant options to avoid any issues.
position
Optional
Number
Must be provided when optionElement
selector is provided. Numeric value of the order number/position of the variant option as declared in the Shopify admin product page. It's not required to display the elements, in the same order, in the recommendations, but it's requred to supply the appropriate position number and it should match the order in the Shopify admin
dependentVariantSelector
Optional
Object/VariantOptionSelector
Selectors configuration for sub-level variants that changes based on the value selected in this primary variant. A maximum of 5 sub-level variants can be supported
Error reporting
In case of any issues with the API call or element structuring, the API will promptly report the errors in the browser console. Please contact Nosto support in case you come across these issues.
Limitations
Only allows up to 5 sub-level variants
Only allows 1 primary variant
Strict structuring necessary. In other words, it's necessary to follow the rules defined in the description of each API parameters.
While providing multiple variant options, it's not possible to pre-configure the option to be selected for sub-level variants. The API selects the first option automatically.
Currency conversion is not compatible with Search and Category Merchandising (Universal).
Examples
There are two ways of using the JS API and it totally depends on the content of recommendation template.
Without variant options
With variant options
In this section, we discuss about both the approaches with an example
Using API without variant options
Only the necessary part of the template is shown below. It's not a complete recommendation template.
For the template above, you can call the JS API
With all the parameters as below:
With only the necessary parameters as below:
Using API with variant options
Only the necessary part of the template is shown below. It's not a complete recommendation template. While loading the variant options, is not necessary to load the values for the sub-variants. The API loads the data automatically for the selected market and language
For the template above, you can call the JS API
triggerMigration
method declared in the above example invokes the JS API,
With all the parameters as below:
With only the necessary parameters as below:
Last updated