Send Adobe Client Data Layer data with the Web SDK
The Adobe Client Data Layer (ACDL) collects data and events on the page, but it doesn’t send them anywhere. To send them to the Adobe Experience Platform Edge Network, connect ACDL events to the Web SDK in one of the following ways:
- JavaScript library: Your own code listens for ACDL events and calls the Web SDK
sendEventcommand. - Tag extensions: Tag rules use the ACDL extension to trigger on ACDL events and the Web SDK extension to send the data.
Each section of this page shows both approaches.
Prerequisites prerequisites
Your site code pushes the data and events that you want to send. The examples on this page use the following push for each page view:
window.adobeDataLayer = window.adobeDataLayer || [];
window.adobeDataLayer.push({
event: "page view",
page: { title: "Home", language: "en" }
});
You also need the following, depending on your approach:
- ACDL is installed on your pages.
- The Web SDK base code and library are installed, and the Web SDK is configured with a datastream.
The Web SDK base code queues commands until its library loads, and ACDL queues items until its library loads. Because of these queues, you can add the code on this page anywhere after the Web SDK base code, regardless of which library loads first.
- The ACDL extension is installed and configured in your tag property.
- The Web SDK extension is installed and configured with a datastream.
Choose how to map your data mapping
The Web SDK sends data in two objects. Choose one or both:
Choose where values come from value-sources
When an ACDL event triggers your code or rule, you can read data layer values from two places:
event.page.title, where event is the listener’s argument%event.message.page.title%adobeDataLayer.getState("page.title")page.titleUse the pushed object for values that describe the event itself, such as the product in a cart addition. Use the computed state for values that were pushed earlier, such as user details. When the code or rule runs, the computed state already includes the data from the push that triggered it. See What listeners receive and Use the pushed data in rules.
Send XDM data xdm
The following examples send a page view with the page title from the pushed object.
Listen for the event and call sendEvent:
| code language-js |
|---|
|
For all listener options, see addEventListener().
-
Create a Variable data element with the Web SDK extension. Select XDM, then select your sandbox and schema. This example names the data element
XDM variable. -
Create a rule, and add an event:
- Extension: Adobe Client Data Layer
- Event type: Data layer push
- Triggers on: Specific named events, with the event name
page view - Time scope: All
-
Add an action that fills in the XDM object:
- Extension: Adobe Experience Platform Web SDK
- Action type: Update variable
- Data element:
XDM variable - Set
web.webPageDetails.nameto%event.message.page.title%, and setweb.webPageDetails.pageViews.valueto1.
-
Add an action that sends the event:
- Extension: Adobe Experience Platform Web SDK
- Action type: Send event
- Type:
web.webpagedetails.pageViews - XDM:
%XDM variable%
-
Save the rule, add it to a library, and build the library.
For all event options, see Data layer push.
Each time your site pushes a page view event, the code or rule sends a page view to the Edge Network.
Send interactions the same way. For example, for a push such as { event: "cart add", eventInfo: { sku: "HT105" } }, listen for or trigger on cart add, and read the product from eventInfo. For the XDM fields that describe commerce interactions, see Collect commerce, product, and order information.
Send the data layer for mapping in the datastream data
To map in the datastream instead of in code or rules, send data layer values in the data object, and include an XDM eventType so that the event is classified correctly.
| code language-js |
|---|
|
Inside an ACDL listener, this refers to the data layer, so this.getState() returns the computed state. To send only part of it, pass a path, such as this.getState("page").
-
Create a Data layer computed state data element with the ACDL extension. Select Entire computed state, or select Specific path and enter the path of the data that you want to send. This example names the data element
ACDL state. -
Create a rule with the same Data layer push event as in Send XDM data.
-
Add a Send event action from the Web SDK extension:
- Type:
web.webpagedetails.pageViews - Data:
%ACDL state%
- Type:
-
Save the rule, add it to a library, and build the library.
Then, in your datastream, map the fields that you send to your XDM schema. See Data Prep for Data Collection. Data that you don’t map, and that no configured service reads, isn’t stored. Sending the entire computed state also increases the size of each request, so on pages with a large data layer, send only the parts that you map.
Single-page applications spa
In a single-page application, the page stays open while the visitor views many virtual pages, and the data layer history keeps growing. Push a page view event for each virtual page view, and clear the history after you send it. Clearing the history doesn’t change the computed state or remove listeners and rules.
Clear the history at the end of your page view listener:
| code language-js |
|---|
|
See Clear the history.
Timing and duplicates timing
Follow these practices so that each event is sent exactly once:
- Use the
allscope. It’s the default in both approaches: thescopeoption in JavaScript and the Time scope setting in tags. It sends events that were pushed before your listener or rule started listening, such as a page view that was pushed before your script or tag library loaded. Usefutureonly if another part of your implementation already sent the earlier events. See Scope. - Send each event from one place. If both your own code and a tag rule send the same data layer event, Adobe receives it twice.
- JavaScript library: use named functions, and add each listener once. ACDL ignores a second registration of the same function for the same event. However, if code that runs repeatedly passes a new anonymous function each time, ACDL adds a new listener each time, and each event is sent more than once.
- Tag extensions: trigger on specific event names. A rule that triggers on All data changes runs for every data push, which can send many more events than you expect.
Related pages related
sendEventcommand and Send event action: All Web SDK options for sending events.addEventListener()and Data layer push: All options for listening to ACDL events.