Prerequisites

You should have already completed the lessons in Configure tags and Add the Identity Service.

Additionally, you will need at least one report suite ID and your tracking server. If you don’t have a test/dev report suite that you can use for this tutorial, please create one. If you are unsure how to do that, see the documentation. You can retrieve your tracking server from your current implementation, Adobe Consultant or Customer Care representative.

Add the Analytics Extension

The Analytics extension consists of two main parts:

  1. The extension configuration, which manages the core AppMeasurement.js library settings and can set global variables

  2. Rule actions to do the following:

    1. Set Variables
    2. Clear Variables
    3. Send the Analytics Beacon

To add the Analytics extension

  1. Go to Extensions > Catalog

  2. Locate the Adobe Analytics extension

  3. Click Install

    Install the Analytics extension

  4. Under Library Management > Report Suites, enter the report suite ids you would like to use with each tag environment. If your users has access to Adobe Analytics, note that as you start typing in the box, you will see a pre-populated list of all of your report suites. (It’s okay to use one report suite for all environments in this tutorial, but in real life you would want to use separate report suites, as shown in the image below)

    Enter the report suite ids

    TIP
    We recommend using the Manage the library for me option as the Library Management setting as it makes it much easier to keep the AppMeasurement.js library up-to-date.
  5. Under General > Tracking Server, enter your tracking server, e.g. tmd.sc.omtrdc.net. Enter your SSL Tracking Server if your site supports https://

    Enter the tracking servers

  6. In the Global Variables section, under Additional Settings, set the Page Name variable using your Page Name data element. Click the data element icon icon to open the modal and choose the page Page Name data element)

  7. Click Save to Library

    Set the page name variable and save

NOTE
Global variables can be set in the extension configuration or in rule actions. Be aware that when setting variables in the extension configuration, the data layer must be defined before the tag embed codes.

Send the Page View Beacon

Now you will create a rule to fire the Analytics beacon, which will send the Page Name variable set in the extension configuration.

You have already created an “All Pages - Library Loaded” rule in the Add a data element, a rule and a library lesson of this tutorial, which is triggered on every page when the tag library loads. You could use this rule for Analytics as well, however this setup requires all data layer attributes used in the Analytics beacon to be defined before the tag embed codes. To allow more flexibility with the data collection, you will create a new “all pages” rule triggered on DOM Ready to fire the Analytics beacon.

To Send the Page View Beacon

  1. Go to the Rules section in the left navigation and then and then click Add Rule

    Add Rule

  2. Name the rule All Pages - DOM Ready

  3. Click Events > Add to open the Event Configuration screen

    Name the rule and add the event

  4. Select Event Type > DOM Ready (Note that the order of the rule is “50”)

  5. Click Keep Changes
    Configure the Event

  6. Under Actions, click the Click the Plus icon to add a new action

    Click the Plus icon to add a new action

  7. Select Extension > Adobe Analytics

  8. Select Action Type > Send Beacon

  9. Leave Tracking set to s.t(). Note that if you wanted to make an s.tl() call in a click-event rule you could do that using the Send Beacon action, as well.

  10. Click the Keep Changes button

    Click the Plus icon to add a new action

  11. Click Save to Library and Build

    Click Save to Library and Build

Validate the Page View Beacon

Now that you have created a rule to send an Analytics beacon, you should be able to see the request in the Experience Cloud Debugger.

  1. Open the Luma site in your Chrome browser

  2. Click the Debugger icon Open the Experience Cloud Debugger to open the Adobe Experience Cloud Debugger

  3. Make sure the Debugger is mapping the tag property to your Development environment, as described in the earlier lesson

    Your tags development environment shown in Debugger

  4. Click to open the Analytics tab

  5. Expand your Report Suite name to show all of the requests made to it

  6. Confirm the request has fired with the Page Name variable and value

    Validate the page hit

NOTE
If the Page Name is not showing up for you, go back through the steps in this page to make sure that you haven’t missed anything.

Add Variables with Rules

When you configured the Analytics Extension, you populated the pageName variable in the extension configuration. This is a fine location to populate other global variables such as eVars and props, provided the value is available on the page before the tag embed code loads.

A more flexible location to set variables—as well as events—is in rules using the Set Variables action. Rules allow you to set different Analytics variables and events under different conditions. For example, you could set the prodView only on product detail pages and the purchase event only on order confirmation pages. This section will teach you how to set variables using rules.

Use Case

Product Detail Pages (PDP) are important points for data collection on retail sites. Typically, you want Analytics to register that a product view occurred and which product was viewed. This is helpful in understanding which products are popular with your customers. On a media site, article or video pages could use similar tracking techniques to the ones you will use in this section. When you load a Product Detail Page, you might want to put that value into a “Page Type” eVar, as well as set some events and the product id. This will allow us to see the following in our analysis:

  1. How many times product detail pages are loaded
  2. Which specific products are viewed and how many times
  3. How other factors (campaigns, search, etc) affect how many PDP’s people load

Create Data Element for Page Type

First you need to identify which pages are the Product Detail pages. You will do that with a Data Element.

To Create the Data Element for Page Type

  1. Click Data Elements in the left navigation

  2. Click Add Data Element

    Add a new Data Element

  3. Name the data element Page Type

  4. Select Data Element Type > JavaScript Variable

  5. Use digitalData.page.category.type as the JavaScript variable name

  6. Check the Clean text and Force Lower Case options

  7. Click Save to Library

    Add a new Data Element for Page Type

Create Data Element for Product Id

Next, you will collect the product id of the current Product Detail page with a Data Element

To Create the Data Element for Product Id

  1. Click Data Elements in the left navigation

  2. Click Add Data Element

    Add a new Data Element

  3. Name the data element Product Id

  4. Select Data Element Type > JavaScript Variable

  5. Use digitalData.product.0.productInfo.sku as the JavaScript variable name

  6. Check the Clean text and Force Lower Case options

  7. Click Save to Library

    Add a new Data Element for Page Type

Add the Adobe Analytics Product String Extension

If you are already familiar with Adobe Analytics implementations, you are probably familiar with the products variable. The products variable has a very specific syntax and gets used slightly different ways depending on the context. To help make the population of the products variable easier in tags, three additional extensions have already been created in the tag extension marketplace! In this section you will add an extension created by Adobe Consulting to use on the Product Detail page.

To add the add the Adobe Analytics Product String extension

  1. Go to the Extensions > Catalog page

  2. Find the Adobe Analytics Product String extension by Adobe Consulting Services and click Install
    Add the Adobe Analytics Product String extension by Adobe Consulting

  3. Take a moment to read the instructions

  4. Click Save to Library

    Save the extension and build it to your library

Create the Rule for Product Detail Pages

Now, you will use your new data elements and extension to build your Product Detail page rule. For this functionality, you will create another page load rule, triggered by DOM Ready. However, you will use a condition so that it only fires on the Product Detail pages and the order setting so that it fires before the rule that sends the beacon.

To build the Product Detail page rule

  1. Go to the Rules section in the left navigation and then and then click Add Rule

    Add Rule

  2. Name the rule Product Details - DOM Ready - 40

  3. Click Events > Add to open the Event Configuration screen

    Name the rule and add the event

  4. Select Event Type > DOM Ready

  5. Set the Order to 40, so that the rule will run before the rule containing the Analytics > Send Beacon action

  6. Click Keep Changes
    Configure the Event

  7. Under Conditions, click the Click the Plus icon to open the Condition Configuration screen
    Click the Plus icon to add a new condition

    1. Select Condition Type > Value Comparison

    2. Use the data element picker, choose Page Type in the first field

    3. Select Contains from the comparison operator dropdown

    4. In the next field type product-page (this is the unique part of the page type value pulled from the data layer on PDP’s)

    5. Click Keep Changes

      Define the condition

  8. Under Actions, click the Click the Plus icon to add a new action

    Click the Plus icon to add a new action

  9. Select Extension > Adobe Analytics Product String

  10. Select Action Type > Set s.products

  11. In the Analytics E-commerce Event section, select prodView

  12. In the Data layer variables for product data section, use the Data Element picker to choose the Product Id data element

  13. Click Keep Changes

    Add the Product String Variable using the Adobe Analytics Product String extension

  14. Under Actions, click the Click the Plus icon to add a new action

    Add another Action for the Product String

  15. Select Extension > Adobe Analytics

  16. Select Action Type > Set Variables

  17. Select eVar1 > Set as and enter product detail page

  18. Set event1, leaving the optional values blank

  19. Under Events, click the Add Another button

  20. Set the prodView event, leaving the optional values blank

  21. Click Keep Changes

    Set Analytics Variables in PDP Rule

  22. Click Save to Library and Build

    Save the rule

Validate the Product Detail Page Data

You just created a rule that sets variables before the beacon is sent. You should now be able to see the new data going out in the hit in the Experience Cloud Debugger.

To validate the Product Detail page data

  1. Open the Luma site in your Chrome browser

  2. Navigate to any product detail page

  3. Click the Debugger icon Open the Experience Cloud Debugger to open your Adobe Experience Cloud Debugger

  4. Click to the Analytics tab

  5. Expand your Report Suite

  6. Notice the Product Detail Variables that are now in the debugger, namely that eVar1 has been set to “product detail page”, that the Events variable has been set to “event1” and “prodView”, that the products variable is set with the product id of the product you are viewing, and that your Page Name is still set by the Analytics extension

    Validate the page hit

When a page loads, you typically fire a page load beacon triggered by the s.t() function. This automatically increments a page view metric for the page listed in the pageName variable.

However, sometimes you don’t want to increment page views on your site, because the action that is taking place is “smaller” (or maybe just different) than a page view. In this case, you will use the s.tl() function, which is commonly referred to as a “track link” request. Even though it is referred to as a track link request, it doesn’t have to be triggered on a link click. It can be triggered by any of the events that are available to you in the tag rule builder, including your own custom JavaScript.

In this tutorial, you will trigger an s.tl() call using one of the coolest JavaScript events, an Enters Viewport event.

The Use Case

For this use case, you want to know if people are scrolling down on our Luma home page far enough to see the Featured Products section of our page. There is some internal discord at our company about whether people are even seeing that section or not, so you want to use Analytics to determine the truth.

Create the Rule in tags

  1. Go to the Rules section in the left navigation and then click Add Rule
    Add Rule

  2. Name the rule Homepage - Featured Products enters Viewport

  3. Click Events > Add to open the Event Configuration screen

    Add Featured Products Rule

  4. Select Event Type > Enters Viewport. This will bring up a field where you need to enter the CSS selector that will identify the item on your page that should trigger the rule when it enters view in the browser.

  5. Go back to the home page of Luma and scroll down to the Featured Products section.

  6. Right-click on the space between the “FEATURED PRODUCTS” title and the items in this section, and select Inspect from the right-click menu. This will get you close to what you want.

  7. Right around there, possibly right under the selected section, you are looking for a div with class="we-productgrid aem-GridColumn aem-GridColumn--default--12". Locate this element.

  8. Right-click on this element and select Copy > Copy Selector

    Configure the Enters Viewport Event

  9. Go back to tags, and paste this value from the clipboard into the field labeled Elements matching the CSS selector.

    1. On a side note, it is up to you to decide how to identify CSS selectors. This method is a bit fragile, as certain changes on the page may break this selector. Please consider this when using any CSS selectors in tags.
  10. Click Keep Changes
    Configure the Enters Viewport Event

  11. Under Conditions, click the Click the Plus icon to add a new condition

  12. Select Condition Type > Value Comparison

  13. Use the data element picker, choose Page Name in the first field

  14. Select Equals from the comparison operator dropdown

  15. In the next field type content:luma:us:en (this is the page name of the home page as pulled from the data layer - we only want this rule to run on the home page)

  16. Click Keep Changes

    Configure the Homepage Condition

  17. Under Actions, click the Click the Plus icon to add a new action

  18. Select Extension > Adobe Analytics

  19. Select Action Type > Set Variables

  20. Set eVar3 to Home Page - Featured Products

  21. Set prop3 to Home Page - Featured Products

  22. Set the Events variable to event3

  23. Click Keep Changes

    Configure the Enters Viewport Event

  24. Under Actions, click the Click the Plus icon to add another new action

  25. Select Extension > Adobe Analytics

  26. Select Action Type > Send Beacon

  27. Choose the s.tl() tracking option

  28. In the Link Name field, enter Scrolled down to Featured Products. This value will be placed into the Custom Links report in Analytics.

  29. Click Keep Changes

    Config Featured Products Beacon

  30. Click Save to Library and Build

    Save the rule and build

Now you will want to make sure that this hit goes in when you scroll down to the Featured Products section of the Home Page of our site. When you first load the homepage, the request shouldn’t be made, but as you scroll down and the section comes into view, the hit should fire with our new values.

  1. Open the Luma site in your Chrome browser and make sure you are at the top of the home page.

  2. Click the debugger icon Open the Experience Cloud Debugger to open your Adobe Experience Cloud Debugger

  3. Click to the Analytics tab

  4. Expand your Report Suite’s hit

  5. Notice the normal page view hit for the home page with the page name, etc. (but nothing in eVar3 or prop3).

    Debugger with a Page View

  6. Leaving the Debugger open, scroll down on your site until you can see the Featured Products section

  7. View the Debugger again, and another Analytics hit should have appeared. This hit should have the params associated with the s.tl() hit that you set up, namely:

    1. LinkType = "link_o" (this means that the hit is a custom link hit, not a page view hit)

    2. LinkName = "Scrolled down to Featured Products"

    3. prop3 = "Home Page - Featured Products"

    4. eVar3 = "Home Page - Featured Products"

    5. Events = "event3"

      Debugger with a Page View