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;

  1. location is the page or pages on the site where the rule fires
  2. event is the trigger for the rule
  3. purpose is the main action performed by the rule
  4. 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:

  1. Go to Extensions

  2. Filter to Adobe Client Data Layer

  3. Select Install

    Add Adobe Client Data Layer extension

  4. Leave the default settings

  5. Select Save

NOTE
It is not necessary to use the Adobe Client Data Layer to implement Experience Platform Web SDK. Many other types of events are commonly used in tags implementations (Library Loaded, DOM Ready, Window Loaded, and so on) to fire rules.

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:

  1. Use the Update variable action to define a “global configuration” of XDM fields.

  2. 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).

  3. 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:

  1. Open the tag property that you are using for this tutorial

  2. Go to Rules in the left navigation

  3. Select the Create New Rule button

    Create a rule

  4. Name the rule all pages - adobeDataLayer push - set global variables - 1

  5. In the Events section, select Add

    Name the rule and add an event

  6. Use the Adobe Client Data Layer extension and select Data Pushed as the Event Type

  7. Select Advanced dropdown and enter 1 as the Order

    note note
    NOTE
    The lower the order number, the earlier it executes. Therefore, we give our “global configuration” a low order number.
  8. Listen to All Events

  9. Select Keep Changes to return to the main rule screen
    Select Library Loaded Trigger

  10. In the Actions section, select Add

  11. As the Extension, select Adobe Experience Platform Web SDK

  12. As the Action Type, select Update variable

  13. As the Data element, select the XDM Variable you created in the Create data elements lesson

    Update Variable Schema

  14. 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
    eventType Web Webpagedetails Page Views (begin typing to see the suggested values)
    identityMap Identity Map data element
    web.webPageDetails.name Page Name data element
    web.webPageDetails.pageViews.value 1
    note 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 Map data element is null, the identityMap object will not be sent. This is why we can safely define it in our “global configuration”.
    note tip
    TIP
    Setting web.webPageDetails.pageViews.value provides 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.
  15. When you are done, your XDM Variable will look something like this. Note how the populated and partially populated fields are indicated with the blue circles:
    XDM Variable

  16. 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.

TIP
Rule order determines which rule runs first when an event is triggered. If two rules have the same event type, the rule with the lowest order number runs first.

Start by tracking product views on the product detail page of Luma:

  1. Select Add Rule

  2. Name it product detail pages - adobeDataLayer push - set product details variables - 20

  3. Select the + symbol under Event to add a new trigger

  4. Under Extension, select Adobe Client Data Layer

  5. Under Event Type, select Data Pushed

  6. Select to open Advanced Options, type in 20. This order value ensures the rule runs after the global variables rule.

  7. Listen to a Specific Event

  8. Enter productView as the Event / Key to register for

  9. Select Keep changes

    Analytics XDM rules

  10. Under Actions select Add

  11. Select Adobe Experience Platform Web SDK extension

  12. Select Action Type as Update variable

  13. Select XDM Variable as the Data element

  14. 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
    eventType Commerce Product Views (begin typing to see the suggested values)
    commerce.productViews.value 1
    productListItems.name Ecommerce Product Name data element (Select Provide individual items and Add Item first )
    productListItems.sku Ecommerce Product Id data element
  15. Select Keep Changes

  16. Select Save to save the rule

    note note
    NOTE
    Because this rule has a higher order, it will overwrite the eventType set in the “global configuration” rule. eventType can 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 prodView event 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):

XDM object array format

Compare the data element to the productListItems structure (hint, it should match).

NOTE
You will not be able to run _satellite.getVar('Ecommerce Cart Products') at this point in the tutorial.
IMPORTANT
When mapping fields from your data layer to XDM, make sure the fields match the data type of the XDM field. In the example above quantity and priceTotal must be integers or the record will not ingest into Platform.
XDM schema data type

Now, let’s map our array to the XDM object:

  1. Create a new rule named cart page - adobeDataLayer push - set cart variables - 20

  2. Select the + symbol under Event to add a new trigger

  3. Under Extension, select Adobe Client Data Layer

  4. Under Event Type, select Data Pushed

  5. Select to open Advanced Options, type in 20. This order value ensures the rule runs after the global variables rule.

  6. Listen to a Specific Event

  7. Enter cartView as the Event / Key to register for

  8. Select Keep Changes

    Event for Cart rule

  9. Under Actions select Add

  10. Select Adobe Experience Platform Web SDK extension

  11. Select Action Type as Update variable

  12. Select XDM Variable as the Data element

  13. Map these XDM fields to appropriate values:

    table 0-row-2 1-row-2 2-row-2 3-row-2
    XDM Field Map to
    eventType Commerce Product List (Cart) Views (begin typing to see the suggested values)
    commerce.productListViews.value 1
    productListItems Ecommerce Cart Products data element (Select Provide entire array first )
    note tip
    TIP
    Setting commerce.productListViews.value=1 in XDM automatically maps to the scView event in Analytics
  14. Select Keep Changes

  15. Select Save to save the rule

Order confirmation fields

Create another rule for purchase events:

  1. Create a new rule named order confirmation - adobeDataLayer push - set purchase variables - 20

  2. Select the + symbol under Event to add a new trigger

  3. Under Extension, select Adobe Client Data Layer

  4. Under Event Type, select Data Pushed

  5. Select to open Advanced Options, type in 20. This order value ensures the rule runs after the global variables rule.

  6. Listen to a Specific Event

  7. Enter purchase as the Event / Key to register for

  8. Select Keep Changes

  9. Under Actions select Add

  10. Select Adobe Experience Platform Web SDK extension

  11. Select Action Type as Update variable

  12. Select XDM Variable as the Data element

  13. 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
    eventType Commerce Purchases (begin typing to see the suggested values)
    commerce.productListViews.value 1
    commerce.order.purchaseID Ecommerce Purchase Id data element
    commerce.order.currencyCode USD
    productListItems Ecommerce Cart Products data element(Select Provide entire array first )
    note tip
    TIP
    Setting commerce.productListViews.value to 1, commerce.order.purchaseID, and commerce.order.currencyCode in XDM automatically maps to the purchase, s.purchaseID, and s.currencyCode variables in Analytics, respectively.
  14. Select Keep Changes

  15. 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.

  1. Create a new rule named all pages - adobeDataLayer push - send event - 50

  2. Select the + symbol under Event to add a new trigger

  3. Under Extension, select Adobe Client Data Layer

  4. Under Event Type, select Data Pushed

  5. 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.

  6. Listen to a All Events

  7. Select Keep Changes

  8. Under Actions select Add

  9. Select Adobe Experience Platform Web SDK extension

  10. Select Action Type as Send Event variable

  11. As the Action Type, select Send event

  12. As the XDM, select the XDM Variable data element created in the previous lesson

  13. Select Keep Changes to return to the main rule screen

    Add the Send Event action

  14. Select Save to save the rule

    Save the rule

You should have the following rules in your property:

Verify list of rules

Publish the rules in a library

Next, publish the rule to your development environment so you can verify it works.

To create a library:

  1. Go to Publishing Flow in the left navigation

  2. Select Add Library

    Select Add Library

  3. For the Name, enter Luma Web SDK Tutorial

  4. For the Environment, select Development

  5. 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.
  6. Select Save & Build for Development

    Create and build the library

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:

Build complete

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.

NOTE
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
recommendation-more-help
8cbc0fd8-ca1d-433b-9c3d-bc3f113347d4