Data Layer

What is dataLayer

Google Tag Manager (GTM) is a web-based measurement code management system. Its function principle is that only one code is placed on the web, and then individual measurement codes are inserted through the web interface. This makes working with codes (also referred to as “tags”) easier and faster, when programmers are omitted out of the deployment.

For more information: https://marketingplatform.google.com/about/tag-manager/

Useful tips

JavaScript Event

ShoptetDataLayerUpdated

This event is triggered after all tracking scripts are evaluated. Can be used to observe and capture changes in dataLayer e.g. new item added to cart.
Event is fired on the document element, use Shoptet Developers Tools to see how and when Shoptet events are fired.

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

Helper function

getShoptetDataLayer

Helper getShoptetDataLayer improves work with dataLayer, this getter can be useful for make your code more clear. Can be used instead of dataLayer[0].shoptet notation as well as bring specific key. See example bellow.

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

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

Updating DataLayer

Cart actions

DataLayer is updated everytime your cart is changed. Whenever items are added, removed or amount is changed we follow and populate structure described here. So you can easily target removeFromCart or addToCart events which can be useful.

These product attributes are being updated:
id, name, brand, category, variant, price, quantity

Reference to individual pages

Home page

[
  {
    "shoptet": {
      "pageType": "homepage",
      "currency": "CZK",
      "language": "cs",
      "projectId": 10000,
      "cart": []
    }
  }
]

Category page (with an item in basket)

[
  {
    "shoptet": {
      "pageType": "category",
      "currency": "CZK",
      "language": "cs",
      "projectId": 10000,
      "cart": [
        {
          "code": "DS37867464",
          "quantity": 1
        }
      ]
    }
  }
]

Product detail

[
  {
    "shoptet": {
      "pageType": "productDetail",
      "currency": "CZK",
      "language": "cs",
      "projectId": 10000,
      "product": {
        "id": 15,
        "guid": "356eb81e-d966-11e0-b04f-57a43310b768",
        "hasVariants": true,
        "codes": [
          {
            "code": "15/FIA"
          },
          {
            "code": "15/ZEL"
          },
          {
            "code": "15/ZEL2"
          },
          {
            "code": "15/ZEL3"
          },
          {
            "code": "15/ZLU"
          }
        ],
        "name": "Jamie Buckle Satchel  Kombinace parametrů",
        "appendix": "Kombinace parametrů",
        "manufacturer": "Jamie",
        "currentCategory": "Pro radost",
        "defaultCategory": "Pro radost",
        "currency": "CZK",
        "priceWithVat": 699
      },
      "stocks": [
        {
          "id": 4,
          "title": "Brno Krpole",
          "isDeliveryPoint": 1
        },
        {
          "id": 1,
          "title": "Praha Francouzská",
          "isDeliveryPoint": 1
        },
        {
          "id": "ext",
          "title": "Externí sklad",
          "isDeliveryPoint": 0
        }
      ],
      "cart": [
        {
          "code": "DS37867464",
          "quantity": 1
        }
      ]
    }
  }
]

Basket

[
  {
    "shoptet": {
      "pageType": "cart",
      "currency": "CZK",
      "language": "cs",
      "projectId": 10000,
      "cart": [
        {
          "code": "DS37867464",
          "quantity": 1
        }
      ]
    }
  }
]

Completed order

[
  {
    "shoptet": {
      "pageType": "thankYou",
      "language": "cs",
      "projectId": 10000,
      "order": {
        "orderNo": "2017000027",
        "storeName": "fenix.myshoptet.com",
        "total": 444,
        "shipping": 0,
        "shippingTax": 0,
        "netto": 366.94,
        "tax": 77.06,
        "city": "Praha 2",
        "district": null,
        "estimatedDeliveryTime": "2019-03-21 14:30:00"
        "country": "Czech Republic",
        "countryCode": "CZ",
        "content": [
          {
            "sku": "DS53437473",
            "name": "Batman's mug",
            "variant": null,
            "price": "366.94",
            "quantity": 1,
            "category": "For home | For kitchen"
          }
        ],
        "currencyCode": "CZK",
        "customer": {
            "groupId": 1,
            "priceListId": 1,
            "priceRatio": 0.85,
            "registered": true,
            "mainAccount": true
        },
        "discountCoupons": [
            {
                id: 3,
                name: "Slevový kupon č. 123456 - Sleva 10%",
                code: "123456"
            }
        ]
      },
      "cart": []
    }
  },
  {
    "transactionId": "2017000027",
    "transactionAffiliation": "fenix.myshoptet.com",
    "transactionTotal": 444,
    "transactionShipping": 0,
    "transactionTax": 77.06,
    "transactionProducts": [
      {
        "sku": "DS53437473",
        "name": "Batman's mug",
        "variant": null,
        "price": "366.94",
        "quantity": 1,
        "category": "For home | For kitchen"
      }
    ]
  }
]

Description of items

pageType – Page type

Value Description
homepage Home page
category Category
productDetail Product detail
cart Basket
thankYou Thank you page, when your order is complete

currency – the chosen currency of the e-shop

language – the chosen language of the e-shop

projectId – e-shop identificator

product – product information

Item Type Example Description
id string 15A Internal unique identifier
guid string 356eb81e-d966-11e0-b04f-57a43310b768 Unique identifier
hasVariants bool true Flag whether the product has variants
codes field See below for a description of the pattern features Product variant field (if any)
name string Jamie Buckle Satchel Combination of parameters Product or variant name
appendix string Free replacement Supplement to the product name
manufacturer string Nike Product brand
currentCategory string Winter sports The sub-category in which the product is classified
defaultCategory string Sports equipment Default (master) product category. The product must be classified in such a category, otherwise it is not visible in the e-shop.
currency string CZK Currency
priceWithVat decimal number 699.90 Price of the product including VAT
stocks field Description of the pattern features, see below List of warehouses

codes – product variant field

Item Type Example Description
code string 15/FIA Variant code (identifier)

stocks – warehouses field

Item Type Example Description
id whole number 4 Warehouse identification number
title string Brno Krpole Warehouse name
isDeliveryPoint whole number 1 = yes, 0 = no Whether the warehouse is a collection point

cart – field of the ordered items

Item Type Example Description
code string 51/ZEL Product code
quantity whole number 1 Number of items in the basket

cartInfo – additional cart information

Item Type Example Description
freeShipping boolean false True if a free shipping discount coupon has been applied
leftToFreeShipping.priceLeft number 999 Zero or negative value = free shipping is available
leftToFreeShipping.formattedPrice string € 999 Same as priceLeft, formatted as string with currency symbol
leftToFreeShipping.dependOnRegion boolean false Indicates whether free shipping is dependent on the region selected
discountCoupon.id number 3 Coupon id
discountCoupon.code string “123456” Coupon code

order – order

Item Type Example Description
orderNo string AB2017000027 Order number
storeName string fenix.myshoptet.com Store name (e-shop)
total whole number 444 Resulting price
shipping whole number 0 Transportation
shippingTax whole number 0 Import tax
netto decimal number 366.94 Weight of the consignment
tax decimal number 77.06 Tax
city string Praha 2 City
district string Region
country string Czech Republic Country of delivery
content Order item field – see below Order items
currencyCode string CZK Currency code

content – order items

Item Type Example Description
sku string 556/XLL Product or variant code
name string Batman’s mug Product or variant name
variant string Color: Red Variant name. Exactly parameter: value
price decimal number 366.94 Price
quantity whole number 1 Quantity of pieces
category string For home / for kitchen Product category

Google Analytics ecommerce – items for Google Analytics electronic commerce

Item Type Example Description
transactionId string AB2017000027 Unique identifier of the transaction
transactionAffiliation string fenix.myshoptet.com The name of the shop or partner
transactionTotal decimal number 444 Total transaction value
transactionShipping decimal number 120.00 Shipping fee per transaction
transactionTax decimal number 77.06 Transaction tax amount
transactionProducts Items field – see below List of items purchased during the transaction

transactionProducts – products that are part of the transaction

Item Type Example Description
sku string 55/MOD Product or variant code
name string Batman’s mug Product or variant name
variant string Color: Blue Variant name. Exactly parameter: value
price decimal number 366.94 Price
quantity whole number 1 Quantity of pieces
category string For home / for kitchen Product category