Event rules

Every time an event is sent, we run the event rules associated with its channel. They are predefined actions to extract properties, reshape data or identify a user from a property.

If the action you wish to do on each event is not possible with an event rule, you should have a look at Activity Analyzers.

How to add event rules

You can go to a channel's settings, edit, and then scroll down to event rules.

Available event rules

Property To Origin Copy

This Event Rule will help you take an existing property from an event and copy it into the origin of the activity. You can copy:

  • The URL of the Event

  • The Referrer of the Event

  • Any Event Property

Url Match

This Event Rule allows you to write a pattern that will be matched against all the $url values of incoming $page_view events. The pattern can extract some values from the Url Path and from the Url Query String.

If you want more information about the different parts of an URL, please read this article.

Limitations

Url Match only works for $page_view events. Any other event won't be processed by the Url Match event rule.

Please note that $page_view events will be deleted at the end of the activity processing stage.

Use case

Useful if for technical and/or organizational reasons, you can't customize the Tracking JS Snippet on a web page to retrieve information from the data layer.

  1. Use the default JS Snippet that will automatically track $page_view events with the URL of the page.

  2. Use the Url Match event rule to extract properties from the page's URL and add them to the event.

For example, if a $page_view event is tracked with the URL https://foo.bar/category/0001/article/super-awesome-article, you would be able to generate this kind of event

{
    "$ts": 1568296040000,
    "$event_name": "article_view",
    "$properties": {
        "category": "0001",
        "article_id": "super-awesome-article",
        "source": "web"
    }
}

How to

The URL Match is taking 2 parameters:

  1. The URL Pattern that will be used to match the $url value of $page_view events

  2. The event template that will be used to generate the event if the $url is matching the URL pattern

Patterns are URL in which you can add:

  • A variable extraction rule for path parameters with:variableName

  • A wildcard with *

Wildcards can be placed several times in the URL pattern. For instance, you can do https://foo.bar/*.* which will match for a route shaped as https://foo.bar/a/b/c.xls

Example *//foo.bar/category/:categoryId/article/:articleId

  • * at the beginning will match both URLs in and in http in the URL

  • :categoryId will extract the value in the URL corresponding to the categoryId. As it is a named variable, it can be used as a value in the event that will be generated.

  • :articleId works as:categoryId

The Query String values are automatically extracted in variables that have the name of the parameter in the Query String. https://foo.bar/a/b/c?var=value&var2=value2 extracts both value and value2 in variables named var and var2.

The event template is containing the following information:

  • The $event_name that will be used for the generated event as a static string

  • A list of properties in a key-value way that will be added in the event properties

In the properties values you can either pass:

  • A static string directly. Ex: sport

  • A string in the format {{variableName}} that will be replaced by a value extracted in the URL pattern

If a variable used in the event template is not extracted from the URL (either from the path or from the Query String), it's value will be {{variableName}} in the generated event.

Examples

Let's take the following event rule:

  • Url pattern: *//foo.bar/category/:categoryId/article/:articleId

  • Event template:

PropertyValue

article_id

{{articleId}}

category_id

{{categoryId}}

visit_origin

{{origin}}

source_event_rule

1

$page_view event with Url: https://foo.bar/category/0001/article/super-awesome-article?origin=email will generate

{
    "$ts": 1568296040000,
    "$event_name": "article_view",
    "$properties": {
        "category": "0001",
        "article_id": "super-awesome-article",
        "visit_origin": "email",
        "source_event_rule": "1"
    }
}

$page_view event with Url http://foo.bar/category/0001/article/super-awesome-article will generate

{
    "$ts": 1568296040000,
    "$event_name": "article_view",
    "$properties": {
        "category": "0001",
        "article_id": "super-awesome-article",
        "visit_origin": "{{origin}}",
        "source_event_rule": "1"
    }
}

$page_view event with Url https://oof.bar/category/0001/article/super-awesome-article will generate nothing as the Url domain (oof.bar) is not matching the pattern.

page_view event with Url https://foo.bar/category/0001/article/super-awesome-article will generate nothing as the "source" event name is not $page_view.

User Identifier Insertion

This event rule allows you to extract a property from an event to convert it into a user identifier, such as an Email Hash or a User Account Id.

You can apply a hash on this extraction. We currently support the following hash methods:

  • SHA_256

  • SHA_1

  • SHA_384

  • SHA_512

  • MD5

  • MD2

This event rule is useful when you don't want to pass an identifier as a global property of the activity, but rather have it computed directly by your datamart.

If several values of an identifier are found within an activity, we keep only the last one.

{
    "$event_name": "PageView",
    "$properties": {
        "user_id": "<USER_ID>"
    }
}

In the scenario above, you will be able to extract the user_id, store it as a User Account Id.

Last updated