Skip to main content
View as Markdown

Rules Engine - Gamification

Rules Engine​

The rules engine evaluates analytics events against configured rules and triggers scoring, achievement, and certification actions. Rules are the core abstraction that ties all gamification features together.

6.1 Rule Entity​

FieldRequiredDescription
gameObjectTypeYesleaderboard, certificate, badge, leadScoring
gameObjectIdYesID of the parent game object
nameYesRule display name
conditionsYesArray of {fact, operator, value} — all must match (AND)
typeYessum, count, countUnique, countBoolean, external, override
modeYesdistribute_points, dont_distribute_points, block_root_rule_while_in_progress, block_root_rule_if_exhausted
metricYesEvent field to evaluate: playTime, kuserId, like, score, pollId
groupByYesScope fields, comma-separated: kuserId, kuserId,entryId
goalYesThreshold to trigger point distribution
pointsYesFixed value ("50") or dynamic event field name ("score")
maxPointsNoCap on total points. Fixed, dynamic, or "unlimited"
reportFormatNodefault or in_minutes
statusNoenabled or disabled
subRulesNoArray of child rules for multi-stage logic
userIdOverrideNoMap points to a different user (e.g., upvote recipient)

6.2 Rule Types​

TypeDescriptionExample
sumSum the metric value across eventsSum playTime — when total reaches goal seconds, distribute points
countCount matching eventsCount pollAnswered events — when count reaches goal, distribute points
countUniqueCount unique metric valuesCount unique entryId values — "watch N different sessions"
countBooleanCount events where metric is truthyCount events where like is true
externalAccept external/3rd-party scoresMetric must be "score"; points come from the event's score field
overrideReplace existing score entirelyOverride with new value instead of accumulating

6.3 Rule Modes​

ModeDescription
distribute_pointsWhen goal is met, distribute points to the user's score
dont_distribute_pointsTrack progress without adding to score (for badge rules that track activity separately)
block_root_rule_while_in_progressSub-rule must complete before the root rule can accumulate
block_root_rule_if_exhaustedOnce this sub-rule reaches its max, the root rule stops accumulating

6.4 Condition Operators​

equal, notEqual, lessThan, greaterThan, in, notIn, contains, doesNotContain

6.5 Condition Facts (Event Fields)​

FactDescription
eventTypeviewPeriod, quizSubmitted, pollAnswered, comment, like, registered, etc.
entryIdKaltura entry ID
categoriesCategory IDs the entry belongs to
virtualEventIdVirtual event ID

Single category:

{"fact": "categories", "operator": "in", "value": "325222712"}

Multiple categories (OR):

{
"any": [
{"fact": "categories", "operator": "contains", "value": "$CATEGORY_ID_1"},
{"fact": "categories", "operator": "contains", "value": "$CATEGORY_ID_2"}
]
}

6.6 Analytics Events That Feed Rules​

SourceEvent TypesExample Rules
PlaybackviewPeriodWatch duration, per-session completion
In-Video QuizzesquizSubmittedQuiz completion, first-to-complete bonus
Chat & CollaborationpollAnswered, comment, like/upvotePoll participation, chat engagement
Live Q&AquestionAsked, questionPromotedQ&A participation
KMEparticipated, quizAnswerMeeting attendance
RegistrationregisteredEvent registration, first-to-register bonus

6.7 Rule CRUD​

# Create rule for a leaderboard
curl -X POST "$KALTURA_SCM_URL/rule/create" \
-H "Authorization: Bearer $KALTURA_KS" \
-H "Content-Type: application/json" \
-d '{
"gameObjectType": "leaderboard",
"gameObjectId": "'$LEADERBOARD_ID'",
"name": "Watch sessions",
"description": "10 points per 60 seconds watched",
"conditions": [{"fact": "eventType", "operator": "equal", "value": "viewPeriod"}],
"type": "sum",
"mode": "distribute_points",
"metric": "playTime",
"groupBy": "kuserId,entryId",
"goal": "60",
"points": "10",
"maxPoints": "100",
"reportFormat": "default"
}'

# List rules for a game object
curl -X POST "$KALTURA_SCM_URL/rule/list" \
-H "Authorization: Bearer $KALTURA_KS" \
-H "Content-Type: application/json" \
-d '{"gameObjectType": "leaderboard", "gameObjectId": "'$LEADERBOARD_ID'"}'

# Update rule (enable)
curl -X POST "$KALTURA_SCM_URL/rule/update" \
-H "Authorization: Bearer $KALTURA_KS" \
-H "Content-Type: application/json" \
-d '{"id": "'$RULE_ID'", "status": "enabled"}'

# Delete rule
curl -X POST "$KALTURA_SCM_URL/rule/delete" \
-H "Authorization: Bearer $KALTURA_KS" \
-H "Content-Type: application/json" \
-d '{"id": "'$RULE_ID'"}'

6.8 Sub-Rules​

Sub-rules enable multi-stage logic. Example: root rule awards points per upvote, sub-rule caps total upvotes per user.

curl -X POST "$KALTURA_SCM_URL/rule/create" \
-H "Authorization: Bearer $KALTURA_KS" \
-H "Content-Type: application/json" \
-d '{
"gameObjectType": "leaderboard",
"gameObjectId": "'$LEADERBOARD_ID'",
"name": "Upvotes on comments",
"conditions": [{"fact": "eventType", "operator": "equal", "value": "like"}],
"type": "count",
"mode": "distribute_points",
"metric": "like",
"groupBy": "kuserId,entryId",
"goal": "1",
"points": "20",
"maxPoints": "100",
"subRules": [
{
"name": "Cap at 5 upvotes",
"type": "count",
"metric": "commentId",
"groupBy": "kuserId",
"goal": "1",
"maxPoints": "5",
"mode": "block_root_rule_if_exhausted"
}
]
}'