Build tag rules

Learn how to create rules so you can execute commands in tags. Events and conditions determine when to do stuff while actions determine what to do. For more information, see the rules documentation.

Transcript
In this video, We’ll explain the concept of rules and tags and how to build them in the tags interface. A rule is a set of instructions that tells your tags build how to respond to certain events and conditions on your digital property, whether that property is a website, mobile app, or server. Every rule is essentially an event statement. If a certain event happens and certain conditions are true, then the rule will take certain actions in response. Rule of law at the heart of the capabilities offered by tags, everything that you manage to configure in tags from installing extensions, defining data elements, building and publishing libraries and so on ultimately revolves around creating testing and evolving different sets of rules that let you collect data from your digital properties in real time. In other words, rules are the tool that lets you control exactly what kinds of customer activities are tracked on your properties and how data related to those events is handled. So let’s jump into the tags interface and see how these rules are set up. You can see that I’m working in a web property here since I’m going to be setting up a rule that listens for a certain event on our website and then sends data about that event to Adobe Experience Cloud. But keep in mind that the fundamentals we go over here work the same way in mobile properties and for the most part event forwarding properties as well. We’ll start by selecting rules on the left navigation. If we created rules for this property previously they’d appear here in a list. But as you can see, we’ve yet to make one for this property. So let’s go ahead and select create new rule. And here we are, the rule builder. This is where we’ll configure everything we need to build out the rules Logic. Note that the canvas is neatly divided into two sections between if and then so we can clearly see what will trigger the rule and what it will do as a result respectively. But obviously there’s nothing here yet. So let’s add some logic to this rule, starting with the F section. This is where we determine when we want the rule to fire. Specifically, we need to choose at least one kind of event that the rule should respond to. And optionally, we can also include further conditions on top of that event if we want to get more specific. Now, as an aside, keep in mind that for mobile properties, rules work the exact same way where we choose between events and conditions. For the F section. But if we were working with an event forwarding property, we’d only be able to set conditions here. This is because event forwarding rules listen to all server side events that stream through and only certain conditions within those events can be used to differentiate when some rules fire and others don’t. All right, so back to our Web property. Let’s pick an event to start. Click add under events and were taken to the event configuration view. So to begin, we need to pick what type of event we want our rule to respond to. But in order to do that, we need to confirm the extension for that event type first. All rule components are tied to an extension, so the available event types you can use depends on the extensions you have installed on your property. When I click the extension dropdown, we can see I just had the experienced platform where SDK extension installed in addition to the default core extension that comes pre-installed with every property. Clicking the event type dropdown below. You can see I have a ton of options for the kinds of events that can trigger the rule. These are the default events provided by the core extension. So this collection captures some very general common events that happen on websites. These include programmatic events like pages being rendered and media assets being loaded, as well as user triggered events like clicks, key presses, form interactions, and so on. If I switch the extension over to the web SDK, the event type list changes to include those specific to that extension. So in this example, I want to build a rule that fires whenever a page is loaded on our website so we can send some simple data about the page View event to Adobe Experience Cloud. In this case, for my event topic, the core extension and then select library loaded for the event type choosing. This event type will cause the rule to fire as soon as the tags library is loaded on the web page. I’ll click Keep changes and now our event is added to the canvas. Notice that we can keep adding events to this rule if we want to doing this because the rule to have multiple events that could potentially trigger it in this can be useful if we want our tags implementation to take the same actions in response to different kinds of events. However, keep in mind that when adding multiple events to a rule and order relationship between each event is assumed. In other words, only one of the events you add needs to occur in order for the rule to be triggered. So with adding more event types doesn’t constrain the rule at all. What happens if we don’t want this rule to fire on every page load but only on certain pages within the website? Well, in that case we can add a condition. Click add under conditions and we’re brought to the configuration view. Just like events, we need to pick the extension that provides the type of condition we want to use and then pick the condition type itself from the dropdown below. For example, under the core extension we can make conditions based on cookie values, the user’s device type, the current website path, and so on. However, we also have this additional logic type dropdown at the top where we can choose between regular and exception. A regular condition must be evaluated as true in order for the rule to fire, whereas an exception condition is one that cannot be true for the rule to fire. You can think of a regular condition as an and statement, whereas an exception would be a not statement. In this example here you can see that I’ve added two conditions to the rule and from the canvas it’s clear what kinds of conditions they are. The one preceded by not is an exception and the one preceded by end is a regular condition. If I switch the order of these around, you can see the semantics change too, and not for the exception when it comes after the regular condition. We’ll just get rid of these conditions. For now, though, since this rule is going to be tracking all page view events, we want this rule to fire on every page load without exception. That’s it for the sections. So let’s move on to then. Now that our rule knows when to fire, we need to give it at least one action to take in response. So just like before, we’ll click add and landed the action configuration view. If I leave the extension on core, you can see that I only have a couple options to choose from when it comes to action types. The custom code action is worth noting though, as this lets you write and execute any custom JavaScript code or HTML script as an action so your rules are never limited to just the action types provided by other extensions. In our case, though, we’re going to use an action from the Web SDK, so we’ll switch over to that extension. The SDK has several very commonly used action types, but the one we’re interested in for this video is said event. When we add this action, whenever this rule fires on our site. The SDK will send data about the triggering event to our experience. Cloud applications. You can see I have a ton of options here, but since we’re just introducing rules in this video, we won’t get too deep in the weeds when it comes to how to use this particular action from the web SDK. We’ll just do the bare minimum here, which means providing a string to tell the SDK what kind of event this is. In this case I’ll use the dropdown and select page views since we know that’s what this rule is tracking and then selecting the data that we want to send, which I happen to have here at a data limit that I made previously. And from there I’ll keep changes. And here we basically have a rule logic complete. We have an event that will trigger the rule to fire and an action for that rule to take when it executes. All we need to do now is give it a name. It’s best practice to name your rules descriptive and consistently so others in your organization can see what each rule is doing at a glance without having to click into its details. We encourage you to find a naming scheme that works best for your organization. But in my case, I usually start with something that indicates where the rule will fire. In this case, that will be all pages. Then follow it up with the event type that this rule will be triggered by and the type of action it will take in response, which for this rule would be library a loaded send event. I’ll click Save. And now the rule has been added to the list where it can now be included in the libraries that we build and publish on this property. Once you’ve added your rules to a library and published it as a build on your website, it’s easy to test which rules are firing and when using console.log to see if they’re working as expected. One way of doing this is by using Adobe Experience Platform debugger on your website. Open the extension and select tags in the left NAV followed by the configuration tab. Check the console.log in box and hit save to enable the logging feature. Doing this causes the page to stop refresh so when we switch over to logs on the left nav, we can see some rules here already. If I clear the isn’t, load the home page again. I get new logs for these rules in real time from the stamp so we can confirm the order in which they’re triggered as well as which ones fired and which ones didn’t fire due to conditions not being met like this rule here that’s only meant to run on the website’s product pages. Alternatively, you can also view these logs using the browser console without needing to use the debugger extension. Simply open the console while you’re on your site and then start typing in satellite, which will bring up the client side satellite object that’s automatically set when tags is running on your site. From here we’ll invoke the set debug method from that object and set it to true. And when we run it, our rules will start appearing directly in the browser console when they fire. You can see that we have all the same info here as we get debugger, including the time stands for each rule trigger and whether the rules expected conditions were met for it to fire. So that was a quick introduction to rules and tags, including how to create them in the tags interface and how to test their behavior on a website. Keep in mind that there’s a ton we didn’t cover here, like how multiple rules can build off each other for more advanced use cases. So be sure to check out the documentation in our other videos for a deeper dive into rule capabilities. Thanks for watching.
recommendation-more-help
9cc2b5f3-7a2d-451f-950c-f8f7136b6390