skip to Main Content

The data layer is a javascript object defined in the page’s header. It tells Persoo, what has been happening on the page and what is displayed – which product ID, which category, etc. It’s necessary for correct setup of recommendation boxes.

How to set up Data Layer

  • Define data layer variable and fill it with data, both above the Persoo Snippet!
  • Fill it with correctly formatted valuessee the list of required values bellow
  • Use one data layer variable for multiple services – if you already use data layer for another services (GA, GTM etc.), you can use same variable name (typicaly “dataLayer”) also for Persoo.

Example of a Data Layer:

Place data layer before Persoo Snippet!

The reasons are:

  • Data pushed to dataLayer before loading Persoo Snippet are reported as properties of a pageview event, which is automatically triggered by the snippet.
  • Data reported later are kept in dataLayer and are reported with next persoo event. Those are usually statistics (impression, clicks, …)
  • Moreover if you push "event": "name" property to dataLayer, this will trigger an event to Persoo with the given name.

Tip: If you use Enhaced Ecommerce (Google Analytics specification) or Google Tag Manager (GTM), you can use the same dataLayer variable for both GA/GTM and Persoo.

Important! Do not send empty variables to the dataLayer. E.g. empty transaction object transaction: {} would create a new transaction in Persoo!

Mandatory Data Layer values

Data values differs according to the page type. Page type mostly corresponds to your html template of your eshop / CMS.

Note: If you use Enhanced Ecommerce for Google Analytics (correctly according to the Google specification), you don’t neet to set Persoo specific values below.

pageType: ‘page_type_name’ (string) – required – the Page Type has to be specified on all pages. 

Please take note of the required Page Type naming convention:

  • ‘homepage’ – on the homepage
  • ‘detail’ – on the product detail page
  • ‘category’ – on the product list (category) page
  • ‘basket’ – on the page of basket and through the checkout process all the way to the order confirmation page
  • ‘error’ – on the error “404 page not found” page
  • ‘search’ – on the page with search results
  • ‘other’ – on other pages (contacts, blog, terms and conditions etc.)

currency: ‘eur’ (string) – required – currency as specified by ISO 4217 Currency Codes

impressedProducts: ‘locationID’ [product ids] (object) – optional – an object with locations containing IDs of their displayed products. Useful, if we want to prevent showing a product already displayed by the e-shop. Remember to keep the product IDs in the same format as in the product feed.

pageType: ‘homepage’ (string) – povinné

pageType: ‘detail’  (string) required

itemID  (string) required – id of the currently displayed product. Needs to be identical with the id in the product feed.

categoryID  (string) optional – id of the category of the currently displayed product

hierarchy  (string) optional – tree structure of the categories of the currently displayed product. IDs of categories should be divided with colons and without spaces.

[product parameters] (string or array) – optional – product parameters such as brand, gender, color etc. Variable is string if single value exists or an array if multiple values exist.

pageType: ‘category’  (string) required 

hierarchy  (string)required– hierarchy of the currently displayed category. IDs of categories should be divided with colons and without spaces.

categoryID  (string) – optional– id of the currently displayed category

[filterParameters] (string or array) – optional – Those are the currently selected filters. If only one item is selected, the value is a string, if more than one is selected, return an array of strings. These parameters are especially important in stores that do not use traditional tree hierarchy, and use only parametrical filtering (e.g. very common in e-shops with clothing).
Important: the naming convention here has to be the same as in the product feed (e.g. if the product feed has “brand”: “adidas”, the data layer has to have the same “brand”: “adidas” when the filter is applied).

Empty basket correctlyconfirmationrequired

When visitor empty basket (delete items or make purchase) then during pageview rendered after that empty basket in dataLayer:

  1. set basketTotal to zero (basketTotal:0)
  2. romove basketItems

Example: There are two products “Red t-shirt with a short sleeve” with id ‘333’ and also “Black outdoor shoes” with id ‘546’.

Note: if there is a discount included in the process, this price in the data layer is after the discount.

pageType: ‘basket’ (string) – required 
(Important! We need the variables basketItems and basketTotal on every page, if there is something in the basket.

basketItems (object) – required – contains products placed in the basket. Insert on all pages. If the basket is emptied, reset the whole basketItems.

quantity (number) – required – amount of that particular product in the basket

price (number) – required – price of the particular product, with VAT

basketTotal (number) – required – total price of the products in the basket. Insert on each page, even the transaction confirmation page. If the basket is emptied, reset also basketTotal. This is with VAT.

basketID (string) – optional – persistent basket ID to be referred to (e.g. in the e-mails). If we insert it into a URL parameter, server will be able to recollect this particular basket’s contents.

Example: The visitor finished the order, and has the transaction ID = “transNo123” on the confirmation page.

pageType (string) required 

basketItems (object) – required – see above section “Basket status” (Note: the following page after this confirmation will have the basket reset).

quantity (number) – required – see above section “Basket status”

price (number) – required – see above section “Basket status”

basketTotal (number) – required – see above section “Basket status”. Must be filled with the whole order value. (Note: the following page after this confirmation will have the basket reset).

transaction (object) – required – contains info about the currently sent order.

id (string) – required – unique order ID

revenue (number) – required – total value of the order with VAT ( or the same number that is sent to Google Analytics).

Empty basket after transaction confirmationrequired

During the next pageview, coming after confirmation page pageview, empty basket in dataLayer:

  1. set basketTotal to zero (basketTotal:0)
  2. remove basketItems

Optional Data Layer values

The user’s id (usually email) needs to be sent to the data layer with each log-in, order finish, newsletter subscription etc.

pageType: ‘error’ (string)

pageType: ‘search’ (string)

query (string) – searched query

results (string) – number of results


Important! If you use Persoo to recommend products, it is essential that the data in the Data Layer and Product Feed match (product IDs, category IDs etc.).
Otherwise it won’t be possible to match correctly displayed category with products from this category, or categories often sold together (such as phones and phone accessories).

Updating Persoo boxes when dynamically changing page content

Important: If you load content dynamically through AJAX, you need to update the data layer and send a new “pageview” event with each content refresh.

The function for sending data on dynamic content change:

where key:value will correspond with the data layer contents + new changes (e.g. new filter selected). For example:

More on data reporting

See this section on data reporting through events.

Back To Top
×Close search