Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Event attributes are one of the most important sources of data for computation in a rule because they convey information about the context of the event. In Chapter 3, you saw how eventexes can use expressions on event attributes as filters for which events match a given primitive eventex. Event attributes can also be used in KRL expressions. To avoid conflict with user-declared variables names, event attributes are namespaced using the keyword event. (Prepending the namespace name and a colon to a variable forms namespaces in KRL.)

 


Assume that a rule has been selected based on a pageview event with an event attribute url. The following KRL expression could be used to extract the domain name from the url attribute:
AnchorOLE_LINK3OLE_LINK3 AnchorOLE_LINK4OLE_LINK4 

event:url.extract(#http://(\[^/?]+)#)

 

 

Event attributes can be sent to an event in several different ways. If one is submitting an event using a GET or POST request, the GET or POST arguments can be accessed using the following syntax:

 

event:attr("argument_name")

 

 

Event attributes can also be sent when raising an explicit event using the with keyword. The following KRL would raise an event with event attributes:

 

raise explicit event testEventAttributes for a1x100
   with foo = "bar";

 

This attribute could be used in the following rule:

 

rule testEventAttributes {
   select when explicit testEventAttributes
      pre {
         foo = event:attr("foo"); // Equals bar at this point
      }
      noop()
}