Create tag rules
Learn how to send events to the Adobe Experience Platform Edge Network using tag rules. A tag rule is a combination of events, conditions, and actions that tells the tag property to do something. With Platform Web SDK, rules are used to send events to Platform Edge Network with the right data.
Learning objectives
At the end of this lesson, you are able to:
- Use a naming convention for managing rules within tags
- Send an event with XDM fields using Update Variable and Send Event actions
- Stack multiple sets of XDM fields across multiple rules
- Map individual or entire array data elements to the XDM object
- Publish a tag rule to a development library
Prerequisites
You are familiar with Data Collection tags and the Luma demo website and have completed the previous lessons in the tutorial:
Naming Conventions
To manage rules in tags, it is recommended to follow a standard naming convention. This tutorial uses a four-part naming convention:
- [location] - [event] - [purpose] - [order]
where;
- location is the page or pages on the site where the rule fires
- event is the trigger for the rule
- purpose is the main action performed by the rule
- order is the order in which the rule should fire in relation to other rules sharing the same event
Add Adobe Client Data Layer extension
The Luma website uses an event-driven data layer called the Adobe Client Data Layer (ACDL). Whenever an data layer event occurs, it is pushed into the adobeDataLayer array. This tutorial uses a tags extension called Adobe Client Data Layer to conveniently tap into these events to construct our rules.
To add the extension:
-
Go to Extensions
-
Filter to Adobe Client Data Layer
-
Select Install
-
Leave the default settings
-
Select Save
Create tag rules
In tags, rules are used to execute actions such as setting variables and firing network calls under various conditions. The Experience Platform Web SDK tags extension includes two actions that are used in rules:
- Update variable maps data elements to your XDM or data variables
- Send Event makes the network call to send data to Experience Platform Edge Network
In the rest of this lesson we:
-
Use the Update variable action to define a “global configuration” of XDM fields.
-
Use the Update variable action again to override our “global configuration” and contribute additional XDM fields under certain conditions (for example, adding product details on product pages).
-
Use the Send Event action to send the data to Adobe Experience Platform Edge Network.
All of these rules will be sequenced properly using the “order” option.
This video gives an overview of the process:
Global configuration fields
To create a tag rule for the global XDM fields:
-
Open the tag property that you are using for this tutorial
-
Go to Rules in the left navigation
-
Select the Create New Rule button
-
Name the rule
all pages - adobeDataLayer push - set global variables - 1 -
In the Events section, select Add
-
Use the Adobe Client Data Layer extension and select Data Pushed as the Event Type
-
Select Advanced dropdown and enter
1as the Ordernote note NOTE The lower the order number, the earlier it executes. Therefore, we give our “global configuration” a low order number. -
Listen to All Events
-
Select Keep Changes to return to the main rule screen
-
In the Actions section, select Add
-
As the Extension, select Adobe Experience Platform Web SDK
-
As the Action Type, select Update variable
-
As the Data element, select the
XDM Variableyou created in the Create data elements lesson
-
Now, specify the XDM fields by mapping them to appropriate values:
table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 XDM Field Map to eventTypeWeb Webpagedetails Page Views(begin typing to see the suggested values)identityMapIdentity Mapdata elementweb.webPageDetails.namePage Namedata elementweb.webPageDetails.pageViews.value1note tip TIP XDM fields will not be included in the network request if the data element is null. Therefore, when the user is not authenticated and the Identity Mapdata element is null, theidentityMapobject will not be sent. This is why we can safely define it in our “global configuration”.note tip TIP Setting web.webPageDetails.pageViews.valueprovides a standard way to indicate a page view for other downstream applications. It is not required for Adobe Analytics to process a network call as a page view. -
When you are done, your
XDM Variablewill look something like this. Note how the populated and partially populated fields are indicated with the blue circles:
-
Select Keep Changes and then Save the rule
Product page fields
Now, start to use Update variable in additional, sequenced rules to enrich the XDM object before sending it to Platform Edge Network.
Start by tracking product views on the product detail page of Luma:
-
Select Add Rule
-
Name it
product detail pages - adobeDataLayer push - set product details variables - 20 -
Select the
under Event to add a new trigger -
Under Extension, select Adobe Client Data Layer
-
Under Event Type, select Data Pushed
-
Select to open Advanced Options, type in
20. This order value ensures the rule runs after the global variables rule. -
Listen to a Specific Event
-
Enter
productViewas the Event / Key to register for -
Select Keep changes
-
Under Actions select Add
-
Select Adobe Experience Platform Web SDK extension
-
Select Action Type as Update variable
-
Select
XDM Variableas the Data element -
Map these XDM fields to appropriate values:
table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 XDM Field Map to eventTypeCommerce Product Views(begin typing to see the suggested values)commerce.productViews.value1productListItems.nameEcommerce Product Namedata element (Select Provide individual items and Add Item first )productListItems.skuEcommerce Product Iddata element -
Select Keep Changes
-
Select Save to save the rule
note note NOTE Because this rule has a higher order, it will overwrite the eventTypeset in the “global configuration” rule.eventTypecan only contain one value and we recommend setting it with the most valuable event.note tip TIP Setting commerce.productViews.value=1 in XDM automatically maps to the prodViewevent in Analytics
Shopping cart fields
You can map entire array to an XDM object, provided the array matches the format of the XDM schema. The custom code data element Ecommerce Cart Products you created earlier loops through the adobeDataLayer.ecommerce.cart.items data layer object on the Luma website and translates it into the required format of the productListItems object of the XDM schema.
To illustrate, see the comparison below of the Luma site data layer (left) to the translated data element (right):
Compare the data element to the productListItems structure (hint, it should match).
_satellite.getVar('Ecommerce Cart Products') at this point in the tutorial.quantity and priceTotal must be integers or the record will not ingest into Platform.
Now, let’s map our array to the XDM object:
-
Create a new rule named
cart page - adobeDataLayer push - set cart variables - 20 -
Select the
under Event to add a new trigger -
Under Extension, select Adobe Client Data Layer
-
Under Event Type, select Data Pushed
-
Select to open Advanced Options, type in
20. This order value ensures the rule runs after the global variables rule. -
Listen to a Specific Event
-
Enter
cartViewas the Event / Key to register for -
Select Keep Changes
-
Under Actions select Add
-
Select Adobe Experience Platform Web SDK extension
-
Select Action Type as Update variable
-
Select
XDM Variableas the Data element -
Map these XDM fields to appropriate values:
table 0-row-2 1-row-2 2-row-2 3-row-2 XDM Field Map to eventTypeCommerce Product List (Cart) Views(begin typing to see the suggested values)commerce.productListViews.value1productListItemsEcommerce Cart Productsdata element (Select Provide entire array first )note tip TIP Setting commerce.productListViews.value=1 in XDM automatically maps to the scViewevent in Analytics -
Select Keep Changes
-
Select Save to save the rule
Order confirmation fields
Create another rule for purchase events:
-
Create a new rule named
order confirmation - adobeDataLayer push - set purchase variables - 20 -
Select the
under Event to add a new trigger -
Under Extension, select Adobe Client Data Layer
-
Under Event Type, select Data Pushed
-
Select to open Advanced Options, type in
20. This order value ensures the rule runs after the global variables rule. -
Listen to a Specific Event
-
Enter
purchaseas the Event / Key to register for -
Select Keep Changes
-
Under Actions select Add
-
Select Adobe Experience Platform Web SDK extension
-
Select Action Type as Update variable
-
Select
XDM Variableas the Data element -
Map these XDM fields to appropriate values:
table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 5-row-2 XDM Field Map to eventTypeCommerce Purchases(begin typing to see the suggested values)commerce.productListViews.value1commerce.order.purchaseIDEcommerce Purchase Iddata elementcommerce.order.currencyCodeUSDproductListItemsEcommerce Cart Productsdata element(Select Provide entire array first )note tip TIP Setting commerce.productListViews.valueto1,commerce.order.purchaseID, andcommerce.order.currencyCodein XDM automatically maps to thepurchase,s.purchaseID, ands.currencyCodevariables in Analytics, respectively. -
Select Keep Changes
-
Select Save
Send event rule
Now that you have set the variables, you can create the rule to send the complete XDM object to Platform Edge Network with the Send event action.
-
Create a new rule named
all pages - adobeDataLayer push - send event - 50 -
Select the
under Event to add a new trigger -
Under Extension, select Adobe Client Data Layer
-
Under Event Type, select Data Pushed
-
Select to open Advanced Options, type in
50(which is probably the default). This order value ensures the rule runs after the variable-setting rules. -
Listen to a All Events
-
Select Keep Changes
-
Under Actions select Add
-
Select Adobe Experience Platform Web SDK extension
-
Select Action Type as Send Event variable
-
As the Action Type, select Send event
-
As the XDM, select the
XDM Variabledata element created in the previous lesson -
Select Keep Changes to return to the main rule screen
-
Select Save to save the rule
You should have the following rules in your property:
Publish the rules in a library
Next, publish the rule to your development environment so you can verify it works.
To create a library:
-
Go to Publishing Flow in the left navigation
-
Select Add Library
-
For the Name, enter
Luma Web SDK Tutorial -
For the Environment, select
Development -
Select Add All Changed Resources
note note NOTE You should see all the tag components created in previous lessons. The Core extension contains the base JavaScript required by all web tag properties. -
Select Save & Build for Development
The library may take a few minutes to build and when it is complete it displays a green dot to the left of the library name:
As you can see on the Publishing Flow screen, there is a lot more to the publishing process, which is beyond the scope of this tutorial. This tutorial just uses a single library in your Development environment.
Now, you are ready to validate the data in the request using the Adobe Experience Platform Debugger.