The W3C data layer is a tool-agnostic data layer standard that can be used by many tools and vendors, and can be a good starting point for sites that don't already have a standard.
Below are examples of commonly used W3C Data Layer objects, in JSON format. These are by no means a global, golden standard, but could be used as a starting point.
Top of Page
|
I tend to declare the main object, digitalData, at the top of the page. I may also choose to define digitalData.event so I can freely use digitalData.event.push() later.
|
digitalData={}
digitalData.event=[]
Then I can add each sub-object (such as cart, page, or user) appropriately later on the page.
|
|
For documenting all pages:
|
digitalData.page={
pageInfo:{
pageName:"wug shop> clearance> blue wugs> Sally the wug: product details",
language: "en-US"
},
category:{
primaryCategory: "wug shop",
subCategory1:"wug shop > clearance",
subCategory2:"wug shop > clearance > blue wugs",
pageType: "product details"
}
}
|
Other common pageInfo items: author, issueDate, publisher.
|
|
A typical digitalData.user object.
|
digitalData.user={
profile:{
profileID:"sel2564wskrtjnho",
userName: "jkunz123",
email: "jkunz123@fakeEmail.com"
},
segment:{
authState: "logged in"
}
}
|
Note, authentication state is NOT part of the W3C standard, but the standard is flexible enough to allow for additional objects based on your requirements.
|
|
The cart object, which should appear on all pages of a retail site, reflecting the current contents of the user's cart.
|
digitalData.cart = {
cartID: "306702397",
price:{
cartTotal: "72.59",
voucherCode: "", //promo code
voucherDiscount: "" //promo amount
},
//CART ITEMS
item:[
//product 1 example: shipped
{
quantity:"1",
price:{
basePrice: "2.97"
},
productInfo:{
sku: "100087613",
productName: "Green Wug",
fulfillmentMethod: "shipped"
}
},
//product 2 example: pickup
{
quantity:"3",
price:{
basePrice: "36.94"
},
productInfo:{
sku: "204642286",
productName: "Blue Wug",
fulfillmentMethod: "pick up in store",
fulfillmentStore: "101"
}
},
//product 3 example: on backorder
{
quantity:"1",
price:{
basePrice: "29.98"
},
productInfo:{
sku: "203202930",
productName: "Red Wug",
fulfillmentMethod: "backorder"
}
}
]
}
|
See the s.products example page for tips on how to pull this into Analyics tracking.
|
|
A typical digitalData.event array object, for post-page-load tracking
|
eventHolder={
eventInfo:{
eventName: "submitted example form",
type: "form"
},
details: {
userName: document.getElementById("firstName").value
}
}
digitalData.event.push(eventHolder)
|
See the Single Page Apps and Data Layers example page for a working example.
|
|