Events

What’s an Event?

Event can be any thing that happen in a system. For example login operation, tweets, adding an item to cart, sensor signal. Herogi scenarios are built on events. Once events floated to Herogi engine, they can trigger multiple actions defined on scenarios.

Event Structure

Each event consist of several items.

sessionId: Defines a unique identifier for the event. It can be anything like user id, member id, email, device id

eventName: Name of event. E.g. login, addToCart, forgetPassword

scenarioName: Name of scenario. Defines scenario to handle the event.

data: Key/value pair of additional event parameters. E.g. addToCart can have parameters like itemId, amount, date

Event Types

Regular Events

Default event type. Any events which created by user is called regular events. Regular events are sent via rest api or client libraries.

Timer Events

Timer event is special event type which is generated by Herogi engine. It works similar to cron jobs. User can set it’s time, when the time comes, engine generates timer event in a specific scenario for the session.

Event Parameters

Event parameters are additional data about your event. You can put more informations into a event to use later in actions and validations.

Parameters are just simple key/value pairs;


 {
    "itemId" : "1",
    "amount" : "100$",
    "date" : "2017-02-15"
 }

Parameter Types

Numeric Parameters

Numeric parameters can be used in mathematical operations. You can compare it with other numeric values in validations.

Aggregating Numeric Parameters

In addition to these, numeric parameters also have advanced feature is called, aggregations. You can enable aggregation on numeric parameters for a time period. Whenever an event comes to Herogi engine, Herogi aggregates it’s value and calculate values like sum, min, max, avg, count and make it available in actions and validations context.

1. Sliding Window Aggregations

With sliding window aggregation, aggregation window is basically sliding in time.

E.g;

  Aggregate for last 2 hours
  From now to 2 hours ago. 
  
  If time is 15:00pm, it's between 13:00pm to 15:00pm.
  If time is 15:01pm, it's between 13:01pm to 15:00pm.
  

You can use sliding aggregations for scenarios like if a user sign-ins 5 times in 2 hours, send her a promotion coupon

2. Fixed Window Aggregations

With fixed window aggregation, aggregation window is basically starts from a fixed base time.

E.g;

  Aggregation Base Time: 00:00
  Aggregate for 2 hours
  Split time into windows of 2 hours as referencing base time. 
  In this case 00:00 - 02:00, 02:00 - 04:00 and etc.
  
  If time is 15:00pm, it's between 14:00pm to 16:00pm.
  If time is 15:01pm, it's still between 14:00pm to 16:00pm.
  

You can use fixed aggregations for scenarios like if a user spend $100 total between 09:00am to 09:00pm, send her a promotion coupon

Creating Your First Event

Event creating is really simple. Just go scenarios page and select the scenario you want to add event.

Create Event

After you create your events, now you can start sending events to Herogi.