Rules

Rules define automations that execute in response to collected Events.


Overview

Rules allow you to control the Actions that should be taken based on a set of Conditions that have passed a truth test.

Rules execute all of their Actions when all of their specified Conditions are true. Conditions may reference Events, Sessions, Profiles, Sources, and Segments, while Actions may utilize Connections when interacting with external systems.

For example, suppose you fire an event Form Completed after a visitor to your website completes a form. You may define a Rule that depends on a Condition where event must equal Form Completed, and which fires an Action that sends a notification email.

How Rules are Evaluated and Executed

Rules are retrieved based on an inbound Event's information and are processed via a structured lifecycle:

  1. A client (Javascript library, HTTP request) sends an Event to Firstparty
  2. Firstparty looks up the Source based on that Event's write_key value
  3. Firstparty saves the Event, Session, and Profile, and sends a response to the Client
  4. Firstparty now retrieves all Rules enabled for that Source, evaluates the Conditions, and executes the appropriate Actions.
  5. The Event, Session, and Profile are saved once more.

Rules are executed after a response is sent to the client. This is appropriate when used in conjunction with the JavaScript Source, since the client browser making a request won't have to wait for the Rule to evaluate - it will just receive a super fast response.