Skip to main content

Introduction to DataLayer

The Shoptet dataLayer is a JavaScript object that acts as a source of data on the frontend. It enables developers to access relevant data using JavaScript.

Package information

The Shoptet DataLayer is also available as an NPM package: @shoptet/datalayer.

Developers can use the provided JSON schema, as well as TypeScript and Zod schemas, to work with the data layer effectively.

Helper function and event

getShoptetDataLayer helper function

The helper function getShoptetDataLayer improves working with dataLayer. This getter can be useful for making your code clearer. It can be used instead of the dataLayer[0].shoptet notation and can also bring a specific key.

Example

// As a simple alias for dataLayer[0].shoptet
var myDataLayer = getShoptetDataLayer();

// Or use it to get a specific key
var cart = getShoptetDataLayer('cart');

ShoptetDataLayerUpdated event

The ShoptetDataLayerUpdated event is triggered after all tracking scripts are evaluated. It can be used to observe and capture changes in dataLayer, e.g., when a new item is added to the cart. The event is fired on the document element. Use Shoptet Developer Tools to see how and when Shoptet events are fired.

Example

document.addEventListener('ShoptetDataLayerUpdated', function() {
var freshDataLayerData = dataLayer[0].shoptet;
console.log(freshDataLayerData);
});

DataLayer schema

This is an up-to-date schema of the Shoptet DataLayer.

Loading ....
View raw JSON Schema
{
"type": "object",
"properties": {
"order": {
"$ref": "#/definitions/Order"
},
"customer": {
"$ref": "#/definitions/Customer"
},
"category": {
"$ref": "#/definitions/Category"
},
"cart": {
"type": "array",
"items": {
"$ref": "#/definitions/CartItem"
}
},
"cartInfo": {
"$ref": "#/definitions/CartInfo"
},
"pageType": {
"$ref": "#/definitions/PageTypes"
},
"currency": {
"type": "string"
},
"currencyInfo": {
"type": "object",
"properties": {
"decimalSeparator": {
"type": "string"
},
"exchangeRate": {
"type": "number"
},
"priceDecimalPlaces": {
"type": "number"
},
"symbol": {
"type": "string"
},
"symbolLeft": {
"type": "number"
},
"thousandSeparator": {
"type": "string"
}
},
"required": [
"decimalSeparator",
"exchangeRate",
"priceDecimalPlaces",
"symbol",
"symbolLeft",
"thousandSeparator"
]
},
"language": {
"type": "string"
},
"projectId": {
"type": "number"
},
"traffic_type": {
"anyOf": [
{
"const": "internal",
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"currency",
"currencyInfo",
"language",
"pageType",
"projectId"
],
"definitions": {
"Order": {
"type": "object",
"properties": {
"orderNo": {
"type": "string"
},
"storeName": {
"type": "string"
},
"total": {
"type": "number"
},
"totalWithoutVat": {
"type": "number"
},
"shipping": {
"type": "number"
},
"shippingWithoutVat": {
"type": "number"
},
"shippingTax": {
"description": "The tax of the shipping",
"type": "number"
},
"netto": {
"type": "number"
},
"tax": {
"type": "number"
},
"city": {
"type": "string"
},
"district": {
"type": "string"
},
"country": {
"type": "string"
},
"countryCode": {
"type": "string"
},
"estimatedDeliveryDate": {
"type": "string",
"format": "date-time"
},
"content": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": [
"null",
"number"
]
},
"sku": {
"type": "string"
},
"name": {
"type": "string"
},
"variant": {
"type": "string"
},
"price": {
"type": "number"
},
"priceRatio": {
"type": "number"
},
"totalPrice": {
"type": "object",
"properties": {
"withoutVat": {
"type": "number"
},
"withVat": {
"type": "number"
}
},
"required": [
"withVat",
"withoutVat"
]
},
"quantity": {
"type": "number"
},
"category": {
"type": "string"
}
},
"required": [
"category",
"id",
"name",
"price",
"priceRatio",
"quantity",
"sku",
"totalPrice",
"variant"
]
}
},
"currencyCode": {
"type": "string"
},
"discountCoupons": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"code": {
"type": "string"
}
},
"required": [
"code",
"id",
"name"
]
}
}
},
"required": [
"city",
"content",
"country",
"countryCode",
"currencyCode",
"discountCoupons",
"district",
"estimatedDeliveryDate",
"netto",
"orderNo",
"shipping",
"shippingTax",
"shippingWithoutVat",
"storeName",
"tax",
"total",
"totalWithoutVat"
]
},
"Customer": {
"type": "object",
"properties": {
"guid": {
"type": "string"
},
"email": {
"type": "string"
},
"fullName": {
"type": [
"null",
"string"
]
},
"priceRatio": {
"description": "Price ratio of the discount",
"minimum": 0,
"maximum": 1,
"type": "float"
},
"priceListId": {
"type": "number"
},
"groupId": {
"type": [
"null",
"number"
]
},
"registered": {
"type": "boolean"
},
"mainAccount": {
"type": "boolean"
}
},
"required": [
"groupId",
"mainAccount",
"priceListId",
"priceRatio",
"registered"
]
},
"Category": {
"type": "object",
"properties": {
"guid": {
"type": [
"null",
"string"
]
},
"path": {
"type": "string"
},
"parentCategoryGuid": {
"type": [
"null",
"string"
]
}
},
"required": [
"guid",
"parentCategoryGuid",
"path"
]
},
"CartItem": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"guid": {
"description": "The unique identifier of the product",
"type": "string"
},
"priceId": {
"type": "number"
},
"quantity": {
"type": "number"
},
"priceWithVat": {
"type": "number"
},
"priceWithoutDiscount": {
"type": "number"
},
"discounts": {},
"itemId": {
"type": "string"
},
"name": {
"type": "string"
},
"weight": {
"description": "The weight of the product",
"minimum": 0,
"type": "integer"
}
},
"required": [
"code",
"discounts",
"guid",
"itemId",
"name",
"priceId",
"priceWithVat",
"priceWithoutDiscount",
"quantity",
"weight"
]
},
"CartInfo": {
"type": "object",
"properties": {
"freeShipping": {
"type": "boolean"
},
"leftToFreeGift": {
"type": "object",
"properties": {
"formattedPrice": {
"type": "string"
},
"priceLeft": {
"type": "number"
}
},
"required": [
"formattedPrice",
"priceLeft"
]
},
"freeGift": {
"anyOf": [
{
"type": "array",
"items": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"selected": {
"type": "boolean"
}
},
"required": [
"code",
"selected"
]
}
},
{
"const": false,
"type": "boolean"
}
]
},
"leftToFreeShipping": {
"type": "object",
"properties": {
"formattedPrice": {
"type": "string"
}
},
"required": [
"formattedPrice"
]
},
"discountCoupon": {
"anyOf": [
{
"type": "array",
"minItems": 0,
"maxItems": 0
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"id": {
"type": "number"
}
},
"required": [
"code",
"id"
]
}
}
]
},
"getNoBillingShippingPrice": {
"type": "object",
"properties": {
"withVat": {
"type": "number"
},
"withoutVat": {
"type": "number"
},
"vat": {
"type": "number"
}
},
"required": [
"vat",
"withVat",
"withoutVat"
]
},
"cartItems": {
"type": "array",
"items": {
"$ref": "#/definitions/CartItem"
}
},
"taxMode": {
"type": "string"
},
"trackingContainer": {
"type": "string"
}
},
"required": [
"cartItems",
"discountCoupon",
"freeGift",
"freeShipping",
"getNoBillingShippingPrice",
"leftToFreeGift",
"leftToFreeShipping",
"taxMode"
]
},
"PageTypes": {
"enum": [
"article",
"billingAndShipping",
"cart",
"category",
"customerDetails",
"homepage",
"parametricCategory",
"productDetail",
"section",
"thankYou",
"unknown"
],
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}