Learn how to create data elements in tags for content, commerce, and identity data on the Luma demo site. Then populate fields in your XDM schema with the Adobe Experience Platform Web SDK extension Variable data element type.
At the end of this lesson, you are able to:
You have an understanding of what a data layer is and have completed the previous lessons in the tutorial:
The data for this lesson comes from the digitalData
data layer on the Luma site. To view the data layer, open your developer console and type in digitalData
to see the full data layer available.
There are multiple ways to map data from your data layer to XDM using the tags functionality of Adobe Experience Platform. Below are a few pros and cons of three different approaches. It is possible to combine approaches, if desired:
The examples in this tutorial follow the Map to XDM in tags approach.
This approach involves using the fully defined XDM object as the structure for your data layer. Then you map the entire data layer to an XDM object data element in tags. If your implementation is not using a tag manager, this approach may be ideal because you can send data to XDM directly from your application using the XDM sendEvent command. If you do use tags, you can create a custom code data element capturing the entire data layer as a pass-through JSON object to the XDM. Then, you map the pass-through JSON to the XDM object field in the Send Event Action.
Below is an example of how the data layer would look like using the Adobe Client Data Layer format:
window.adobeDataLayer.push({
"eventType": "web.webPageDetails.pageViews",
"web":{
"webInteraction":{
"linkClicks":{
"id":"",
"value":""
},
"URL":"",
"name":"",
"region":"",
"type":""
},
"webPageDetails":{
"pageViews":{
"id":"",
"value":"1"
},
"URL":"https://luma.enablementadobe.com/",
"isErrorPage":"",
"isHomePage":"",
"name":"luma:home",
"server":"enablementadobe.com",
"siteSection":"home",
"viewName":""
},
"webReferrer":{
"URL":"",
"type":""
}
}
});
Pros
Cons
This approach involves mapping individual data layer variables OR data layer objects to data elements in tags and eventually to XDM. This is the traditional approach to implementation using a tag management system.
Google Data Layer
If your organization already uses Google Analytics and has the traditional Google dataLayer object on your website, you can use the Google Data Layer extension in tags. This allows you to deploy Adobe technology quicker without having to request support from your IT team. Mapping the Google data layer to XDM would follow the same steps as above.
This approach uses functionality built-into the datastream configuration called Data Prep for Data Collection and skips mapping data layer variables to XDM in tags.
As noted earlier, the examples in this tutorial follow the Map to XDM in tags approach.
Before you create the XDM object, create the following set of data elements for the Luma demo site data layer:
Go to Data Elements and select Add Data Element (or Create New Data Element if there are no existing data elements in the tag property)
Name the data element page.pageInfo.pageName
Use the JavaScript Variable Data Element type to point to a value in Luma’s data layer: digitalData.page.pageInfo.pageName
Check the boxes for Force lowercase value and Clean text to standardize the case and remove extraneous spaces
Leave None
as the Storage Duration setting since this value is different on every page
Select Save
Create these additional data elements by following the same steps:
page.pageInfo.server
mapped to
digitalData.page.pageInfo.server
page.pageInfo.hierarchie1
mapped to
digitalData.page.pageInfo.hierarchie1
user.profile.attributes.username
mapped to
digitalData.user.0.profile.0.attributes.username
user.profile.attributes.loggedIn
mapped to
digitalData.user.0.profile.0.attributes.loggedIn
product.productInfo.sku
mapped to digitalData.product.0.productInfo.sku
product.productInfo.title
mapped to digitalData.product.0.productInfo.title
cart.orderId
mapped to digitalData.cart.orderId
product.category
using the Custom Code Data Element type and the following custom code to parse the site URL for the top-level category:
var cat = location.pathname.split(/[/.]+/);
if (cat[5] == 'products') {
return (cat[6]);
} else if (cat[5] != 'html') {
return (cat[5]);
}
cart.productInfo
using the following custom code:
var cart = digitalData.cart.cartEntries;
var cartItem = [];
cart.forEach(function(item, index, array){
cartItem.push({
"SKU": item.sku
});
});
return cartItem;
cart.productInfo.purchase
using the following custom code:
var cart = digitalData.cart.cartEntries;
var cartItem = [];
cart.forEach(function(item, index, array){
var qty = parseInt(item.qty);
var price = parseInt(item.price);
cartItem.push({
"SKU": item.sku,
"quantity": qty,
"priceTotal": price
});
});
return cartItem;
The JavaScript variable data element type treats array references as dots instead of brackets, so referencing the username data element as digitalData.user[0].profile[0].attributes.username
will not work.
The data elements you just created will be used to build an XDM object (for Platform applications) and a data object (for Analytics, Target, and Audience Manager). These objects have their own special data elements called Variable data elements which are very easy to create.
To create the Variable data element for XDM, you tie it to the schema you created in the Configure a schema lesson:
Select Add Data element
Name your Data Element xdm.variable.content
. It is recommended you prefix with “xdm” the Data Elements specific to XDM to better organize your tag property
Select the Adobe Experience Platform Web SDK as the Extension
Select the Variable as the Data Element Type
Select XDM as the property
Select the Sandbox in which you created the schema
Select the appropriate Schema, in this case Luma Web Event Data
Select Save
Next, create the Variable data element for your data object:
Select Add Data element
Name your Data Element data.variable
. It is recommended you prefix with “data” the Data Elements specific to data object to better organize your tag property
Select the Adobe Experience Platform Web SDK as the Extension
Select the Variable as the Data Element Type
Select data as the property
Select the Experience Cloud solutions you wish to implement as part of this tutorial
Select Save
At the end of these steps, you should have the following data elements created:
Core Extension Data Elements | Platform Web SDK Extension Data Elements |
---|---|
cart.orderId |
data.variable |
cart.productInfo |
xdm.variable.content |
cart.productInfo.purchase |
|
page.pageInfo.hierarchie1 |
|
page.pageInfo.pageName |
|
page.pageInfo.server |
|
product.category |
|
product.productInfo.sku |
|
product.productInfo.title |
|
user.profile.attributes.loggedIn |
|
user.profile.attributes.username |
In a future Create tag rules lesson, you learn how the Variable data elements allow you to stack multiple rules in tags using the Update Variable Action type.
With these data elements in place, you are ready to start sending data to Platform Edge Network with a tags rule. But first, learn about collecting identities with Web SDK.
Thank you for investing your time in learning about Adobe Experience Platform Web SDK. If you have questions, want to share general feedback, or have suggestions on future content, please share them on this Experience League Community discussion post