Tracking Data With The Adobe Client Data Layer: Europe'S Leading Aem Developer Conference
Tracking Data With The Adobe Client Data Layer: Europe'S Leading Aem Developer Conference
2
Agenda
3
The Adobe Client Data Layer
4
What is a data layer?
5
What does the Adobe Client Data Layer do?
The Adobe Client Data Layer is a JavaScript store for data and
events happening on a page within the scope of a request. It
provides an API to:
§ Register data that is to be merged into the data layer state.
§ Trigger events that relate to the data stored in the data layer.
§ Get the current data layer state of all merged data.
§ Register listeners that are called for specific events or data
changes.
6
Getting the Data Layer ready
7
adobeDataLayer.push()
8
adobeDataLayer.push()
9
adobeDataLayer.push()
10
adobeDataLayer.push()
§ Pushing a Function:
11
adobeDataLayer.getState()
12
adobeDataLayer.getState()
§ Console output:
13
adobeDataLayer.addEventListener()
14
adobeDataLayer.addEventListener()
§ Console output:
15
adobeDataLayer.removeEventListener()
16
Contributions welcome!
17
Integration with the AEM Core Components
18
Data Layer in a nutshell
19
Core Components data push
20
Client-side data generation
<div data-sly-use.accordion="com.adobe.cq.wcm.core.components.models.Accordion"
id="${accordion.id}"
class="cmp-accordion"
data-cmp-is="accordion"
data-cmp-data-layer="${accordion.data.json}">
...
</div>
21
JS pushing component data
var components = document.querySelectorAll("[data-cmp-data-layer]");
components.forEach(function(component) {
addComponentToDataLayer(component);
});
dataLayer.push({
event: "cmp:loaded"
});
22
Registering event handlers
<a data-sly-unwrap="${!image.link}"
class="cmp-image__link"
href="${image.link}"
data-cmp-clickable="${image.data ? true : false}"
data-cmp-hook-image="link">
...
</a>
clickableElements.forEach(function(element) {
attachClickEventListener(element);
});
23
Components XDM schemas
Page data structure:
{
@type // resource type
repo:modifyDate // last modified date
dc:title // title
dc:description // description
xdm:text // text
xdm:linkURL // link URL
xdm:tags // page tags
repo:path // page path
xdm:template // page template
xdm:language // page language
}
https://github.com/adobe/xdm/blob/master/docs/reference/content/componentized-page.schema.md
24
How it’s generated
public abstract class AbstractComponentImpl implements Component
{
...
@Nullable
public ComponentData getData() {
...
return componentData;
}
@NotNull
protected ComponentData getComponentData() {
return new ComponentDataImpl(this, resource);
}
...
} data-cmp-data-layer="${accordion.data.json}"
25
How it’s generated
public class ComponentDataImpl implements ComponentData
{
public ComponentDataImpl(AbstractComponentImpl component, Resource resource)
{
this.component = component;
this.resource = resource;
}
26
Enabling Data Layer integration
27
Integration with Custom Components
28
Data Layer for Custom Components
29
Using existing integration
30
Custom HTL data generation
<div data-sly-use.mycomp="com.example.custom.Model"
id="${mycomp.id}"
class="cmp-custom-model"
data-cmp-is="custom-component"
data-cmp-data-layer="${mycomp.data.json}">
...
</div>
31
Custom component data
public class CustomComponentDataImpl implements ComponentData
{
public CustomComponentDataImpl(Component customComponent, Resource resource) {
...
}
@Override
public String getTitle() {
return customComponent.getTitle();
}
...
@Override
public String getJson() {
// return a JSON like {componentId: { componentDataJson }}
}
...
}
32
Custom component model
public class CustomModel implements Component
{
...
@Nullable
public ComponentData getData() {
...
componentData = getComponentData();
return componentData;
}
@NotNull
protected ComponentData getComponentData() {
return new CustomComponentDataImpl(this, resource);
}
...
}
33
Data Layer Events for Custom Components
34
Integration with Adobe Launch
35
ACDL Launch Extension
36
Live Demo
37
ACDL Launch Extension
38
Launch Extension: Events
39
Launch Extension: Actions
40
Launch Extension: Data Elements
41
Resources
42
Q&A
43
Thank You!
44