The W3C Data Layer - Part II
20 Sep 2015 » Data Layer
Now, looking into the standard, we will get into the different sections that conforms recommended data layer. Let’s review each of them in the following posts.
Root: digitalData
The JavaScript object should always be called digitalData
.
Page Identifier Object
Although I personally do not find it very useful for Web analytics, this identifier should be completely unique. In particular:
This value SHOULD distinguish among environments, such as whether this page is in
development, staging, or production.
Page Object
This is where you store all the information about the page. It is very well suited for page name, section, subsection… In particular, s.pageName
and s.channel
usually are taken from this object. For example:
s.pageName = digitalData.page.pageInfo.pageName;
s.channel = digitalData.page.category.primaryCategory;
If you want to track additional information from the page, just add more props to the analytics object s
.
Product Object
This is the start of a set of objects that can be used in various ways. In particular, digitalData.product[n]
is an array of product objects. You should this object for products that are shown on the page, irrespective of whether they have already been added to the basket. In a PLP (Product Listing Page), the contents of the array are straight forward.
However, in a PDP (Product Description/Details Page), it is not as obvious. Initially, you might think of only including one element in the array, the main product, but it might also be useful to include other product shown: similar products, recommended products, people who bought this product also bought these others… In the latter case, you may set digitalData.product[0]
as the main product and digitalData.product[n]
for n>0 for the other products. This is useful to set the prodView event only on the main product.
Regarding the data that you can set, most of the elements are self explanatory and most of them are optional. Some comments from the sub-objects and nodes of this object:
-
productInfo.productID: it does not have to be the SKU, especially if you have a unique productID for each product, but the same SKU can be used for different colours, sizes… in which case, the productID is what you would use for the
s.products
variable -
productInfo.productName: I would not suggest that you used it as the product ID in the
s.products
variable -
category.primaryCategory: in version 15 of SiteCatalyst/Adobe Analytics, the category slot in the
s.products
variable was fixed, although I have never seen an implementation that uses it consistently; in general, I suggest to create a merchandising eVar for the category - attributes: in case you want to know what kind of secondary product this is (similar products, recommended products, people who bought this product also bought these others…), you can set an attribute for this
- linkedProduct: in the case of secondary products that are related to the main, you could link that secondary product to the main using this property
With all the previous comments, you could use the following code to create the s.products
variable:
// In PLP
s.products = "";
for (var i = 0 ; i < digitalData.product ; ++i) {
if (i > 0) {
s.products += ",";
}
s.products += ";" + digitalData.product[i].productInfo.productID;
}
// In PLP with merchandising eVar25 for category
s.products = "";
for (var i = 0 ; i < digitalData.product ; ++i) {
if (i > 0) {
s.products += ",";
}
s.products +=
";" +
digitalData.product[i].productInfo.productID +
";;;;" +
"eVar25=" + digitalData.product[i].category.primaryCategory
;
}
// In PDP
s.products = ";" + digitalData.product[0].productInfo.productID;
Cart Object
Although the cart object might look similar to the Product Object, in fact, they serve different purposes. As it name implies, all products that are already in the cart should be added to this object. So, as a consequence, it is entirely possible to have both the Product and the Cart objects on the same page, with different contents: the user has already added some products to the basket and it is still browsing in order to add new products to it. It is up to the development team to decide whether it makes sense to include this object on all pages or only on those pages where it makes sense to have it; for example, you might want to remove it in the help section of the website.
Some comments from the sub-objects and nodes of this object:
- cartID: a unique ID of the cart, that is usually created when the cart is opened
- price: all details about the price of the contents of the cart; however, the values might not be 100% accurate, as you only know some values as you progress through the checkout process; the voucher and shipping detailsshould only contain cart-wide information
-
item[n].productInfo: this is exactly the same as
digitalData.product[n].productInfo
- item[n].quantity is the total number of units for this particular item; however, remember that Adobe Analytics does not track units in the cart
- item[n].price is where you would keep product-specific vouchers
Since you can have both Product and Cart objects, it is up to the implementation to decide which one to use on each page. For example, in a PLP, the Product Object will generally be used, but in a cart page, the Cart Object is the one to be used.
[UPDATE 16/08/2022] I do not recommend the W3C Customer Experience Digital Data Layer (CEEDL) any more. See my post on the EDDL