Create New Rule
To create a new Rule, open the Rule Tab in Events section.
Steps to Create a Rule
- Click on the Add Rule button
- Fill in the details to create rule instantly:
| PROPERTY | TYPE | REQUIRED | DESCRIPTION |
|---|---|---|---|
| Key | String | Yes | Rule identifier. Use snake_case format. Example: high_value_customer |
| Description | String | No | Description helps to understand the rule's purpose |
| Tags | Dropdown | No | Tags to categorize rules. You can manage tags in the company profile section |
| Expression | String | Yes | Rule expression. For example- if the number of orders in the last 24 hours is > 10, consider it as high-value customer. The rule expression would be: no_of_orders_24h >10 See Logical Expression for syntax details. |
Evaluating Rules
To determine whether a rule evaluates to true or false for a specific user, you can evaluate the rule using either the Datablit SDK or direct API calls.
Method 1: Using Datablit SDK
The recommended approach is to use the Datablit SDK for your platform. Check out the Datablit SDK documentation and navigate to your platform's specific implementation.
Method 2: Direct API Call
sh
curl --location 'https://api.datablit.com/api/1.0/rule/eval' \
--header 'apiKey: 01JSWDEZYM0E19ZF3RMHS75PB1' \
--header 'Content-Type: application/json' \
--data '{
"key": "high_value_customer",
"user_id": "1",
"params": {
"os_name": "android"
}
}'Parameters
key: The rule key identifieruser_id: The user ID to evaluate the rule forparams: Optional parameters that can be referenced in the rule expression
Using Parameters in Rules
You can pass optional parameters in JSON format and reference them inside the rule:
json
{
"os_name": "android",
"user_plan": "premium"
}Inside the rule expression, you can reference these parameters:
go
no_of_orders_24h > 10 && os_name == 'android'Method 3: Console Evaluation
You can also test rules directly in the Datablit Console:
- Navigate to the Rules section in your project
- Click on the three dots next to your rule and select "Evaluate"
- Enter the
user_idand any optional parameters - Click submit to see the evaluation result (true or false)