Understanding and utilizing the Event Object in Adobe Launch

Adobe Launch provides a lot of comfort and clever features to make tag management super easy. Quite a few of those features, like the amazing Constant Data Element, are provided directly in the Launch UI. However, there are a bunch of nice surprises waiting for us once we start exploring the more backend-y technical capabilities.

One place where we can catch a glimpse of what Launch has in store for us is in the configuration of Custom Code Actions from the Core Extension. All we have to do is hover our mouse over the Execute globally tool tip:

Adobe Launch Custom Code tool tip

Adobe points us towards three technical variables which we can use in our implementations. One of them is, in my experience, especially useful: The event object. But what is it and why should you use it? Let’s start exploring!

What is the Event Object in Adobe Launch?

As you are probably aware, Launch relies on Events to trigger any of the Rules we configure. Any Rule can have many Events to make it fire on multiple occasions, like on page load and on a link click. We can add new Events to any Rule by clicking the little plus-icon under the Events section:

Events section of a Rule in Adobe Launch

When a Rule is being triggered, Extension developers can choose to provide additional information about the event and provide it to later Rule components, like Conditions, Actions, or Data Elements therein. For example, the Click event from the Core Extension attaches information about the HTML element which was clicked.

If a developer decides to provide information about the Event to later Rule components, they can do it using the event object. We can take a look at how this looks in practice by logging the full event object to the browser console through a Custom Code Action like this:

Logging the event object

In the example below, I used this in a simple Rule with a Click Event configured. On my test page, whenever I now click a link, I can now see the content of the event object in the browser console:

Event object for a Click Event Rule

That’s quite a bunch of useful content! You can see some super helpful information about the Rule that was triggered in the $rule property, like the name or ID of the Rule, along with the type of Rule in the $type property. Thanks to the amazing Launch Core Extension developers we have some more useful properties, like the element property.

As the name implies, the element property gives us the HTML element I just clicked on (similar to the this and target objects). Using this event.element property I can now extract information from the clicked HTML element, like the link text, quite easily. We could print it to the console like this:

Extracting the clicked link text in Adobe Launch

When I now click a link on my page, Launch prints the display text of the link (“Back to homepage”) to the console as expected:

Link text

Launch gives us a handy way to access this information directly using the familiar %% syntax we know from referencing Data Elements. We can use it in other places within Launch now, for example to fire a link click event for Adobe Analytics containing the link text:

Tracking the clicked element to Adobe Analytics

How neat! Of course we can make our lives even easier, especially using Data Elements…

Making our lives simpler using Data Elements

As I’ve written before, I’m a huge fan of the Constant Data Element Type in Launch. If we want to track information like the link text as shown above, the Constant Data Element Type can make the implementation quite a bit easier. For this use case, we could put the reference to the event.element.innerText into a Constant Data Element like this:

Referencing the clicked element’s display text in a Data Element

Now we are able to simply use this Data Element from everywhere where we want to have the display text of a clicked element, like many Adobe Analytics Rules.

But for this use case, what if there is no displayed text on the link itself? We could then use two more Data Elements to create a clever fallback. First, I added another Constant Data Element, but this time for the link target through the href attribute (“%event.element.href%”) instead of the display text. Then, I can use the amazing Sequence Data Element Type from the Data Element Assistant Extension to define a hierarchy of values to return:

Using a hierarchy of link attributes as identifier

As you can see, this new Data Element will try to use the display text of the clicked element first. If there is no display text to return, it will try to use the link target next. If there still is nothing to return, it will default to “No identifier” (note the Default Value field on the left). If you are familiar with how Adobe Analytics’ Activity Map determines which link has been clicked this will look quite familiar. Now, let’s take a look at…

Using it in Conditions and modifying it in Actions

With the above Data Element which identifies any clicked element on our page, it is pretty easy to utilize for Conditions in Rules. For example, imagine that we want to track only clicks on a button that has “Register Now” on it. A Condition like below would look at all clicked elements and only execute the Rule for the desired one:

Using the element identifier in a Rule Condition

That was super easy, no CSS selector required! Besides this custom link identifier, we could also use any other property of the event object in a Condition. Let’s imagine that we only want our Rule to fire on click Events but not any other that may be defined in the Events section of the Rule (so the full rule is part of the Launch Library). We could achieve this in a Condition like below:

Using the Event Type of a Rule in a Condition

But that is not all we can do! In addition to reading the content of the event object we can also modify it. A Custom Code Action gives us the same power as the Launch Extension developers have in providing additional information. Consider this simple sequence of Actions in a Rule:

Action sequence in Adobe Launch

You can probably guess what I’m doing in the second Action. But what is the first one doing? See for yourself:

Modifying the event object in Adobe Launch

You guessed correctly! By simply defining a new key, like event.myKey here, I can add some custom information which then gets carried over to the second Action, as we can see in the console log from the later Action:

Verifying the custom information

Awesome! This feature can be really handy for a bunch of use cases: Maybe we want to call an API and, in a later Action, use the result for Adobe Analytics. Or maybe we would want to transform a Java Script object and use it later in the Rule. No problem! While one would probably try and centralize functionality like that in a Data Element we can totally get away with doing it directly in the Rule!

Wrap up

There is not much to wrap up here. I hope this post was able to show what the event object is and maybe gave you some ideas how you can use it to make your life just a bit easier. Let me know which cool applications you can think of and have a great rest of your day!