The following topics provide a tutorial on how to edit events in Advanced mode in the Event Manager, which enables editing access to the JavaScript™ in which events and event-related objects are created.
For most event objects, creating and editing them in Basic mode is sufficient; the user interface enables configuration of all object properties necessary to define the object and to apply it to the session data stream.
For some types of configuration, however, Experience Analytics users must manipulate the JavaScript in which the event object is defined. For example, if you are using regular expressions in the evaluation of hit attributes, they must be defined through Advanced mode. After these objects were changed in Advanced mode, they must be edited in Advanced mode only thereafter.
Referencing event values
When an event fires and writes a value, those values are written into facts. A fact is a combination of an event and the reports groups on the event. These values are recorded in the request of a session.
In JavaScript, when you reference an event in another event, you are actually referencing the written facts from that event and not the event directly.
Below, you can see an example of a recorded fact (TLFID=75
), its value
(TLFactValue=954.8
) and dimension values. Dimension values are recorded in plain
text (TLDim1=/store/defaultpage
) for review in the request data by Experience Analytics users and as hashed values
(TLDimHash1=C6F8B06175B0630687EB80DF913A30CE
), which are required for searching for
complete values if the length of the value is greater than 32 characters.
[TLFID_75]
Searchable=True
TLFID=75
TLFactValue=954.8
TLDimHash1=C6F8B06175B0630687EB80DF913A30CE
TLDimHash2=7954797EAEBD4BD8B816EA63AF1CE05A
TLDimHash3=7954797EAEBD4BD8B816EA63AF1CE05A
TLDimHash4=7954797EAEBD4BD8B816EA63AF1CE05A
TLDim1=/store/defaultpage
TLDim2=TLT$NULL
TLDim3=TLT$NULL
TLDim4=TLT$NULL
In the example above, one dimension group to which the event is assigned is not listed. Each
event is automatically assigned the No Dimension Report Group
. So, if Event A has
Report Groups 1, 2, and 3 associated with it, there are actually four facts for that event: 1-3, and
the No Dimension Report Group
, which is hidden on the event as Report Group 0.
Object type identifiers
There are several type identifiers available in Advanced mode.
In Advanced mode, objects may be referenced in the following manner:
$F.setFact("NS.F_E__ADVANCED_MODE_EVENT__634286306745774758", factCount);
In the above, the $F
indicates that you are referencing the fact object type and
using the setFact
method.
Identifier | Description |
---|---|
E | Event |
P | Custom hit attributes |
H | System hit attributes |
S | Session attributes, both system and custom |
F | Facts that are a combination of Event and Report Group |
Extracting values from inconsistent patterns using regular expressions
Sometimes, you are looking for patterns on a hit that are not consistent.
For example, an error message could be formatted like the following:
<error id="35">Coupon Code is Invalid<\error>
The id="35"
part is variable, since it represents the actual message itself. If
you only want to retrieve the text part (Coupon Code is Invalid
), you can't use a
Basic Mode hit attribute, since the hit attribute requires strictly consistent patterns to match.
You must use a hit attribute to return a much larger string of text and then extract the wanted
portions to be the value.
So, first make a hit attribute that matches the consistent parts of the pattern:
This configuration returns 35">Coupon Code is Invalid
as the value. However, The
wanted value may be just the Coupon Code is Invalid
message.
To limit the pattern to only match for the message, you must apply a regular expression to the pattern to extract the wanted text. Below is the modified JavaScript:
function NS$E__ERROR_IN_RESPONSE_WITH_REGEXP__634290902173496582()
{
if ($P["NS.P__ERROR_IN_RESPONSE__634290901401436582"].patternFound())
{
$P["NS.P__ERROR_IN_RESPONSE__634290901401436582"].lastValue().
match('.*?">(.*)$ ');
$F.setFact
("NS.F_E__ERROR_IN_RESPONSE_WITH_REGEXP__634290902173496582", RegExp.$1);
}
}
The regular expression is defined in the following snippet:
$P["NS.P__ERROR_IN_RESPONSE__634290901401436582"].lastValue().
match('.*?">(.*)$ ');
The match('.*?">(.*)$')
part runs the regular expression on value that is
returned by the last match of hit attribute
NS.P__ERROR_IN_RESPONSE__634290901401436582
on the hit.
- If you wanted to run the RegEx on the first value, replace
lastValue()
withfirstValue().
- Since the starting value is
35">Coupon Code is Invalid
and we want {{Coupon Code is Invalid,}}, we want to match on the part after35">
. That is what the.*?">
part of the regex code does. The(.*)$
is the part that is extracted.
$F.setFact("NS.F_E__ERROR_IN_RESPONSE_WITH_REGEXP__634290902173496582",
RegExp.$1);
- For the fact value, this snippet defines a
setFact
except for the modifier:RegExp.$1
, which takes the first extracted value of the regular expression operation. Regular expressions can theoretically extract multiple values. To use the second extracted value, insertRegExp.$2
. To use the third value, insertRegExp.$3
. - RegExp is a global variable on an event. You do not have to declare it or set it. It is set automatically.
The basic syntax is as follows:
function <EVENT>()
{
if <CONDITION>
{
<OBJECT>.match('<REGULAR EXPRESSION>');
$F.setFact("<FACT>", RegExp.$<EXTRACTED VALUE#>);
}
}
The RegExp variable gets it values from the nearest previous match function. Suppose the code looks like the following:
<OBJECT 1>.match('<REGULAR EXPRESSION 1>');
$F.setFact("<FACT>", RegExp.$1>);
<OBJECT 2>.match('<REGULAR EXPRESSION 2>');
$F.setFact("<FACT>", RegExp.$1>);
The second RegExp.$1
reference uses the first match from the second regular
expression for object 2, instead of the match from the regular expression for object
1.