Methods
addOrder(order) → {Action}
Create a new action for an order page. This should only be used on order
confirmation / thank you pages.
You do not need to specify the page-type explicitly as it is inferred from the action.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
You must invoke the load method on the resultant action in order for the request to be made.
Parameters:
Name | Type | Description |
---|---|---|
order |
Order | the information about the order that was placed |
Example
nostojs(api => {
api.defaultSession()
.addOrder({
external_order_ref: "145000006",
info: {
order_number: "195",
email: "mridang@nosto.com",
first_name: "Mridang",
last_name: "Agarwalla",
type: "order",
newsletter: true
},
items: [{
product_id: "406",
sku_id: "243",
name: "Linen Blazer (White, S)",
quantity: 1,
unit_price: 455,
price_currency_code: "EUR"
}]
})
.setPlacements(["order-related"])
.load()
.then(data => {
console.log(data.recommendations);
})
})
reportAddToCart(product, element) → {Action}
Creates an action to report that product was added to the shopping cart,
e.g. from the recommendation slot with "Add to cart" button.
You must invoke the load method on the resultant action in order for the request to be made.
Parameters:
Name | Type | Description |
---|---|---|
product |
||
element |
Example
nostojs(api => api
.defaultSession()
.reportAddToCart("123", "reco-slot-1")
.load()
.then(data => console.log(data)))
setCart(cart) → {Session}
Sets the information about the user's current shopping cart. It the user
does not have any items in his shopping cart, you can pass
null.
Passing null will nullify the user's shopping cart on Nosto's
end. You must also pass in the shopping cart content in it's entirety as
partial content are not supported.
Parameters:
Name | Type | Description |
---|---|---|
cart |
Cart | null | the details of the user's shopping cart contents |
Example
nostojs(api => api
.defaultSession()
.setCart({
items: [
product_id: "101",
sku_id: "101-S",
name: "Shoe",
unit_price: 34.99
price_currency_code: "EUR"
]
})
.viewCart()
.setPlacements(["free-shipper"])
.update()
.then(data => console.log(data)))
setCustomer(customer) → {Session}
Sets the information about the currently logged in customer. If the current
customer is not provided, you will not be able to leverage features such as
triggered emails. While it is recommended to always provide the details of
the currently logged in customer, it may be omitted if there are concerns
about privacy or compliance.
Parameters:
Name | Type | Description |
---|---|---|
customer |
Customer | the details of the currently logged in customer |
Example
nostojs(api => api
.defaultSession()
.setCustomer({
first_name: "Mridang",
last_name: "Agarwalla",
email: "mridang@nosto.com",
newsletter: false,
customer_reference: "5e3d4a9c-cf58-11ea-87d0-0242ac130003"
})
.viewCart()
.setPlacements(["free-shipper"])
.load()
.then(data => console.log(data)))
setResponseMode(mode) → {Session}
Sets the response type to HTML or JSON_ORIGINAL. This denotes the preferred
response type of the recommendation result.
If you would like to access the raw recommendation data in
JSON
form, specify
JSON
. When you specify JSON, you will need to template the result yourself.
If you require a more simplified approach, specify HTML
. When you specify
HTML
, you get back HTML blobs, that you may simply inject into
you placements.
Parameters:
Name | Type | Description |
---|---|---|
mode |
String | the response mode for the recommendation data |
Example
nostojs(api => api
.defaultSession()
.setResponseMode("HTML")
.viewCart()
.setPlacements(["free-shipper"])
.load()
.then(data => console.log(data)))
setRestoreLink(restoreLink) → {Session}
Sets the restore link for the current session. Restore links can be leveraged
in email campaigns. Restore links allow the the user to restore the cart
contents in a single click.
Read more about how to leverage the restore cart link
Read more about how to leverage the restore cart link
Parameters:
Name | Type | Description |
---|---|---|
restoreLink |
String | the secure URL to restore the user's current session |
Example
nostojs(api => api
.defaultSession()
.setRestoreLink("https://jeans.com/session/restore?sid=6bdb69d5-ed15-4d92")
.viewCart()
.setPlacements(["free-shipper"])
.load()
.then(data => console.log(data)))
setVariation(variation) → {Session}
Sets the current variation identifier for the session. A variation identifier
identifies the current currency (or the current customer group). If your site
uses multi-currency, you must provide the ISO code current currency being viewed.
Parameters:
Name | Type | Description |
---|---|---|
variation |
String | the case-sensitive identifier of the current variation |
Example
nostojs(api => api
.defaultSession()
.setVariation("GBP")
.viewCart()
.setPlacements(["free-shipper"])
.load()
.then(data => console.log(data)))
viewCart() → {Action}
Create a new action for a cart page. This should be used on all cart and
checkout pages. If your site has a multi-step checkout, it is recommended
that you send this event on each checkout page.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
Example
nostojs(api => api
.defaultSession()
.viewCart()
.setPlacements(["free-shipper"])
.load()
.then(data => console.log(data)))
viewCategory(categories) → {Action}
Create a new action for a category page. This should be used on all
category, collection of brand pages.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
Parameters:
Name | Type | Description |
---|---|---|
categories |
Array.<String> |
Example
nostojs(api => api
.defaultSession()
.viewCategory("/men/shoes")
.setPlacements(["category123"])
.load()
.then(data => console.log(data)))
viewCustomField(customFields) → {Action}
Create a new action with custom fields.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action. Note: tags are not case-sensitive.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action. Note: tags are not case-sensitive.
Parameters:
Name | Type | Description |
---|---|---|
customFields |
Object | custom fields being viewed. |
- Deprecated:
-
- as this is an advanced action with a limited a use case
Example
nostojs(api => api
.defaultSession()
.viewCustomField({material: "cotton"})
.load()
.then(data => console.log(data)))
viewFrontPage() → {Action}
Create a new action for a front page. This should be used when the user
visits the home page.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
Example
nostojs(api => api
.defaultSession()
.viewFrontPage()
.setPlacements(["best-seller"])
.load()
.then(data => console.log(data)))
viewNotFound() → {Action}
Create a new action for a not found page. This should be used only on 404
pages.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
Example
nostojs(api => api
.defaultSession()
.viewNotFound()
.setPlacements(["best-seller"])
.load()
.then(data => console.log(data)))
viewOther() → {Action}
Create a new action for a general page. This should be used only on
pages that don't have a corresponding action. For example, if the user
is viewing a page such as a "Contact Us" page, you should use the viewOther
action.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
viewProduct(product) → {Action}
Create a new action for a product page. This must be used only when a
product is being viewed.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action.
Parameters:
Name | Type | Description |
---|---|---|
product |
Example
nostojs(api => api
.defaultSession()
.viewProduct("101")
.setCategories(["/men/trousers"])
.setRef("123", "example_reco_id")
.setPlacements(["cross-seller"])
.load()
.then(data => console.log(data)))
viewSearch(searchTerms) → {Action}
Create a new action for a search page. This should be used only
on search pages. A search page action requires you to pass the search
term. For example, if the user search for "black shoes", you must pass
in "black shoes" and not an encoded version such as "black+shoes".
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action. Search terms are not case-sensitive.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action. Search terms are not case-sensitive.
Parameters:
Name | Type | Description |
---|---|---|
searchTerms |
Array.<String> | the non-encoded search terms |
Example
nostojs(api => api
.defaultSession()
.viewSearch("black shoes")
.load()
.then(data => console.log(data)))
viewTag(tags) → {Action}
Create a new action for a tag page. This should be used only on tag pages.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action. Note: tags are not case-sensitive.
You must invoke the load method on the resultant action in order for the request to be made.
You do not need to specify the page-type explicitly as it is inferred from the action. Note: tags are not case-sensitive.
Parameters:
Name | Type | Description |
---|---|---|
tags |
Array.<String> | the set of the tags being viewed. |
- Deprecated:
-
- as this is an advanced action with a limited a use case