Skip to main content

Triggers

Triggers in TrackVision AI are event-driven mechanisms that automatically execute automation workflows, data chains, or custom operations in response to specific system events, data changes, or external conditions. They serve as the activation points for all automated processes within the platform.

Overview

Triggers enable reactive automation by monitoring system events and data changes, then initiating appropriate responses. They provide real-time responsiveness to business events and ensure that automated processes execute precisely when needed.

Key capabilities:

  • Real-time event monitoring and response
  • Flexible condition-based activation
  • Integration with flows and data chains
  • Custom trigger logic and scripting
  • Performance optimization and throttling
  • Comprehensive logging and monitoring

Trigger Types

Collection Triggers

Collection triggers respond to data changes in specific collections, enabling automatic reactions to record creation, updates, and deletions.

Create Triggers

Activate when new records are added to a collection.

Configuration:

{
"name": "New Customer Welcome",
"type": "collection_create",
"collection": "customers",
"conditions": {
"field_conditions": {
"status": "active",
"email_verified": true
}
},
"actions": [
{
"type": "flow",
"flow_id": "welcome_email_sequence"
},
{
"type": "data_chain",
"chain_id": "customer_profile_creation"
}
]
}

Use cases:

  • Welcome email sequences for new customers
  • Account setup and provisioning
  • Lead qualification and routing
  • Inventory allocation for new products
  • Compliance and audit record creation

Update Triggers

Activate when existing records are modified.

Configuration:

{
"name": "Order Status Change",
"type": "collection_update",
"collection": "orders",
"conditions": {
"field_changes": ["status"],
"new_values": {
"status": "shipped"
}
},
"actions": [
{
"type": "notification",
"template": "order_shipped",
"recipient": "{{ record.customer.email }}"
},
{
"type": "inventory_update",
"operation": "decrement_stock"
}
]
}

Use cases:

  • Status change notifications
  • Approval workflow progression
  • Data validation and enrichment
  • Cascade updates to related records
  • Business rule enforcement

Delete Triggers

Activate when records are removed from collections.

Configuration:

{
"name": "Product Discontinuation",
"type": "collection_delete",
"collection": "products",
"conditions": {
"soft_delete_only": true
},
"actions": [
{
"type": "data_chain",
"chain_id": "discontinue_product_inventory"
},
{
"type": "notification",
"recipient_role": "inventory_managers",
"message": "Product {{ record.name }} has been discontinued"
}
]
}

Use cases:

  • Cleanup of related data
  • Archival processes
  • Notification of data removal
  • Cascade deletions
  • Audit trail creation

Field Triggers

Field triggers respond to changes in specific fields, providing granular control over automation activation.

Field Value Triggers

Activate when field values meet specific criteria.

Configuration:

{
"name": "High Value Order Alert",
"type": "field_value",
"collection": "orders",
"field": "total_amount",
"conditions": {
"operator": "greater_than",
"value": 10000,
"previous_value": {
"operator": "less_than_or_equal",
"value": 10000
}
},
"actions": [
{
"type": "notification",
"recipient_role": "sales_managers",
"priority": "high"
},
{
"type": "approval_workflow",
"workflow_id": "high_value_order_approval"
}
]
}

Field Change Triggers

Activate when specific fields are modified, regardless of the new value.

Configuration:

{
"name": "Price Change Audit",
"type": "field_change",
"collection": "products",
"fields": ["price", "cost"],
"actions": [
{
"type": "audit_log",
"details": {
"old_value": "{{ trigger.old_value }}",
"new_value": "{{ trigger.new_value }}",
"changed_by": "{{ trigger.user.id }}",
"change_reason": "{{ trigger.context.reason }}"
}
}
]
}

Use cases:

  • Price change monitoring
  • Security-sensitive field tracking
  • Compliance auditing
  • Data quality validation
  • Business rule enforcement

Schedule Triggers

Schedule triggers execute automation at predetermined times or intervals.

Cron Triggers

Execute on specific schedules using cron expressions.

Configuration:

{
"name": "Daily Sales Report",
"type": "schedule_cron",
"schedule": "0 9 * * 1-5",
"timezone": "America/New_York",
"actions": [
{
"type": "flow",
"flow_id": "generate_daily_sales_report"
}
],
"conditions": {
"business_days_only": true,
"skip_holidays": true
}
}

Interval Triggers

Execute at regular intervals.

Configuration:

{
"name": "Inventory Sync",
"type": "schedule_interval",
"interval": "15m",
"actions": [
{
"type": "data_chain",
"chain_id": "external_inventory_sync"
}
],
"conditions": {
"active_hours": {
"start": "06:00",
"end": "22:00"
}
}
}

Use cases:

  • Regular data synchronization
  • Periodic reporting
  • Maintenance tasks
  • Backup operations
  • Data cleanup processes

Event Triggers

Event triggers respond to system events and user actions.

System Event Triggers

Activate on platform system events.

Configuration:

{
"name": "User Login Security Check",
"type": "system_event",
"event": "user_login",
"conditions": {
"failed_attempts": {
"operator": "greater_than",
"value": 3,
"time_window": "15m"
}
},
"actions": [
{
"type": "security_alert",
"severity": "medium"
},
{
"type": "temporary_account_lock",
"duration": "30m"
}
]
}

User Action Triggers

Respond to specific user interactions.

Configuration:

{
"name": "Shopping Cart Abandonment",
"type": "user_action",
"action": "cart_idle",
"conditions": {
"idle_duration": "30m",
"cart_value": {
"operator": "greater_than",
"value": 50
}
},
"actions": [
{
"type": "email",
"template": "cart_abandonment_reminder",
"delay": "1h"
}
]
}

Use cases:

  • Security monitoring
  • User behavior analysis
  • Performance optimization
  • Compliance tracking
  • Business intelligence

External Triggers

External triggers respond to events from outside systems.

Webhook Triggers

Activate when external systems send webhook notifications.

Configuration:

{
"name": "Payment Confirmation",
"type": "webhook",
"endpoint": "/webhooks/payment-confirmed",
"authentication": {
"type": "signature",
"secret": "{{ env.PAYMENT_WEBHOOK_SECRET }}"
},
"conditions": {
"payload_validation": {
"status": "completed",
"amount": {
"operator": "greater_than",
"value": 0
}
}
},
"actions": [
{
"type": "flow",
"flow_id": "process_payment_confirmation",
"input": "{{ webhook.payload }}"
}
]
}

API Triggers

Monitor external APIs for specific conditions.

Configuration:

{
"name": "Stock Price Alert",
"type": "api_monitor",
"api_endpoint": "https://api.stockmarket.com/price/AAPL",
"poll_interval": "5m",
"conditions": {
"price_change": {
"operator": "greater_than",
"value": 5,
"unit": "percent"
}
},
"actions": [
{
"type": "notification",
"recipient_group": "traders",
"template": "stock_alert"
}
]
}

Use cases:

  • Payment processing integration
  • External system synchronization
  • Market data monitoring
  • Supply chain updates
  • Third-party service notifications

Trigger Conditions

Simple Conditions

Basic condition types for trigger activation.

Comparison Operators

  • Equal: _eq, _neq
  • Numeric: _gt, _gte, _lt, _lte
  • Text: _contains, _starts_with, _ends_with
  • Array: _in, _nin
  • Null: _null, _nnull
{
"conditions": {
"priority": {"_eq": "high"},
"amount": {"_gte": 1000},
"status": {"_in": ["pending", "approved"]},
"description": {"_contains": "urgent"}
}
}

Date and Time Conditions

{
"conditions": {
"created_at": {
"_gte": "{{ now() - interval('7 days') }}"
},
"due_date": {
"_lte": "{{ now() + interval('24 hours') }}"
}
}
}

Complex Conditions

Advanced condition logic using boolean operators.

AND/OR Logic

{
"conditions": {
"_and": [
{"status": {"_eq": "active"}},
{
"_or": [
{"priority": {"_eq": "high"}},
{"amount": {"_gte": 5000}}
]
}
]
}
}

Nested Conditions

{
"conditions": {
"_or": [
{
"_and": [
{"category": {"_eq": "electronics"}},
{"price": {"_gte": 500}}
]
},
{
"_and": [
{"category": {"_eq": "jewelry"}},
{"price": {"_gte": 100}}
]
}
]
}
}

Custom Conditions

Implement custom logic using JavaScript expressions.

// Custom condition function
function customTriggerCondition(record, context) {
// Business hours check
const now = new Date();
const businessStart = 9; // 9 AM
const businessEnd = 17; // 5 PM
const isBusinessHours = now.getHours() >= businessStart && now.getHours() < businessEnd;

// Weekend check
const isWeekday = now.getDay() >= 1 && now.getDay() <= 5;

// Priority check
const isHighPriority = record.priority === 'high' || record.amount > 10000;

// Trigger only during business hours for normal priority,
// or anytime for high priority
return isHighPriority || (isBusinessHours && isWeekday);
}

Conditional Actions

Execute different actions based on trigger conditions.

{
"name": "Order Processing",
"type": "collection_create",
"collection": "orders",
"conditional_actions": [
{
"condition": {"amount": {"_gte": 1000}},
"actions": [
{
"type": "approval_workflow",
"workflow_id": "high_value_approval"
}
]
},
{
"condition": {"amount": {"_lt": 1000}},
"actions": [
{
"type": "auto_approve",
"update_status": "approved"
}
]
}
]
}

Trigger Actions

Flow Actions

Execute automation flows in response to trigger events.

{
"action": {
"type": "flow",
"flow_id": "customer_onboarding",
"input": {
"customer_id": "{{ trigger.record.id }}",
"trigger_source": "new_registration",
"metadata": "{{ trigger.context }}"
},
"execution_mode": "async",
"timeout": 300
}
}

Data Chain Actions

Activate data synchronization chains.

{
"action": {
"type": "data_chain",
"chain_id": "inventory_update",
"source_data": "{{ trigger.record }}",
"execution_priority": "high"
}
}

Notification Actions

Send notifications through various channels.

Email Notifications

{
"action": {
"type": "email",
"template": "order_confirmation",
"recipient": "{{ trigger.record.customer.email }}",
"data": {
"order_number": "{{ trigger.record.id }}",
"total_amount": "{{ trigger.record.total }}",
"items": "{{ trigger.record.items }}"
}
}
}

SMS Notifications

{
"action": {
"type": "sms",
"recipient": "{{ trigger.record.phone }}",
"message": "Your order #{{ trigger.record.id }} has been confirmed. Total: ${{ trigger.record.total }}"
}
}

Webhook Notifications

{
"action": {
"type": "webhook",
"url": "https://external-system.com/webhooks/order-update",
"method": "POST",
"headers": {
"Authorization": "Bearer {{ env.EXTERNAL_API_TOKEN }}",
"Content-Type": "application/json"
},
"payload": {
"event": "order_created",
"data": "{{ trigger.record }}"
}
}
}

Data Actions

Perform direct data operations.

Create Records

{
"action": {
"type": "create_record",
"collection": "audit_logs",
"data": {
"event_type": "price_change",
"record_id": "{{ trigger.record.id }}",
"old_value": "{{ trigger.old_value }}",
"new_value": "{{ trigger.new_value }}",
"user_id": "{{ trigger.user.id }}",
"timestamp": "{{ now() }}"
}
}
}

Update Records

{
"action": {
"type": "update_record",
"collection": "products",
"record_id": "{{ trigger.record.id }}",
"data": {
"last_modified": "{{ now() }}",
"modified_by": "{{ trigger.user.id }}"
}
}
}

Performance and Optimization

Trigger Throttling

Control trigger execution rate to prevent system overload.

Rate Limiting

{
"throttling": {
"rate_limit": {
"max_executions": 100,
"time_window": "1m"
},
"queue_overflow": "drop_oldest"
}
}

Debouncing

{
"throttling": {
"debounce": {
"delay": "5s",
"max_delay": "30s"
}
}
}

Batching

{
"throttling": {
"batching": {
"enabled": true,
"batch_size": 50,
"batch_timeout": "10s"
}
}
}

Conditional Execution

Optimize performance by adding execution conditions.

Business Hours Restriction

{
"execution_conditions": {
"business_hours_only": true,
"timezone": "America/New_York",
"business_days": [1, 2, 3, 4, 5],
"business_hours": {
"start": "09:00",
"end": "17:00"
}
}
}

Resource-based Conditions

{
"execution_conditions": {
"system_load": {
"max_cpu_usage": 80,
"max_memory_usage": 85
},
"queue_depth": {
"max_pending": 1000
}
}
}

Async Processing

Configure asynchronous execution for performance.

{
"execution": {
"mode": "async",
"priority": "normal",
"max_concurrent": 10,
"timeout": 300,
"retry_policy": {
"max_attempts": 3,
"delay": "exponential"
}
}
}

Error Handling

Retry Mechanisms

Configure automatic retry for failed trigger actions.

Simple Retry

{
"error_handling": {
"retry": {
"enabled": true,
"max_attempts": 3,
"delay": 5,
"backoff": "linear"
}
}
}

Exponential Backoff

{
"error_handling": {
"retry": {
"enabled": true,
"max_attempts": 5,
"initial_delay": 1,
"backoff": "exponential",
"max_delay": 300
}
}
}

Fallback Actions

Define alternative actions when primary actions fail.

{
"error_handling": {
"fallback_actions": [
{
"condition": "network_timeout",
"action": {
"type": "queue_for_retry",
"delay": "5m"
}
},
{
"condition": "invalid_data",
"action": {
"type": "log_error",
"notify_admin": true
}
}
]
}
}

Dead Letter Queue

Handle permanently failed trigger executions.

{
"error_handling": {
"dead_letter_queue": {
"enabled": true,
"collection": "failed_triggers",
"retention_days": 30,
"notification": {
"threshold": 10,
"recipients": ["admin@company.com"]
}
}
}
}

Monitoring and Analytics

Trigger Metrics

Track trigger performance and execution statistics.

Key Metrics

  • Execution Count: Number of trigger activations
  • Success Rate: Percentage of successful executions
  • Average Latency: Time between event and action execution
  • Error Rate: Frequency of failed executions
  • Queue Depth: Number of pending trigger executions

Metrics Dashboard

{
"monitoring": {
"metrics": {
"execution_count": {
"aggregation": "count",
"time_window": "1h"
},
"success_rate": {
"aggregation": "percentage",
"condition": "status = 'success'"
},
"average_latency": {
"aggregation": "avg",
"field": "execution_time_ms"
}
}
}
}

Alerting

Set up alerts for trigger issues and anomalies.

Performance Alerts

{
"alerts": [
{
"name": "High Error Rate",
"condition": "error_rate > 5%",
"time_window": "15m",
"notification": {
"email": "ops@company.com",
"severity": "critical"
}
},
{
"name": "Queue Backup",
"condition": "queue_depth > 1000",
"notification": {
"slack": "#ops-alerts",
"severity": "warning"
}
}
]
}

Audit Logging

Maintain comprehensive logs of trigger executions.

{
"audit": {
"enabled": true,
"log_level": "info",
"include_data": true,
"retention_days": 90,
"fields": [
"trigger_id",
"event_type",
"execution_time",
"status",
"input_data",
"output_data",
"error_details"
]
}
}

Best Practices

Trigger Design

Single Responsibility

  1. Focused Purpose: Each trigger should handle one specific event type
  2. Clear Conditions: Use precise, unambiguous trigger conditions
  3. Minimal Side Effects: Avoid complex cascading trigger chains
  4. Idempotent Actions: Ensure trigger actions can be safely repeated
  5. Documentation: Clearly document trigger purpose and behavior

Performance Considerations

  1. Efficient Conditions: Use indexed fields in trigger conditions
  2. Batch Operations: Group related actions for efficiency
  3. Async Execution: Use asynchronous processing for non-critical triggers
  4. Resource Limits: Set appropriate timeouts and resource limits
  5. Throttling: Implement rate limiting for high-frequency triggers

Error Handling

Robust Error Management

  1. Comprehensive Retry Logic: Implement appropriate retry strategies
  2. Graceful Degradation: Handle failures without breaking workflows
  3. Error Classification: Categorize errors for appropriate handling
  4. Monitoring and Alerting: Set up monitoring for trigger failures
  5. Recovery Procedures: Plan for manual intervention when needed

Data Integrity

  1. Transaction Boundaries: Define appropriate transaction scope
  2. Consistency Checks: Validate data before and after trigger execution
  3. Rollback Procedures: Plan for undoing trigger actions when necessary
  4. Audit Trails: Maintain comprehensive logs of all trigger actions
  5. Testing: Thoroughly test trigger logic with various scenarios

Security

Access Control

  1. Permission Validation: Verify user permissions for trigger actions
  2. Secure Configuration: Protect sensitive trigger configuration data
  3. Input Validation: Validate all input data and conditions
  4. Output Sanitization: Clean data before sending to external systems
  5. Audit Logging: Log all trigger executions for security monitoring

External Integration Security

  1. Authentication: Use secure authentication for external system calls
  2. Encryption: Encrypt data in transit to external systems
  3. Rate Limiting: Protect against abuse and DoS attacks
  4. Token Management: Securely manage API tokens and credentials
  5. Network Security: Use secure connections and VPNs where appropriate

Maintenance

Regular Review

  1. Performance Analysis: Regularly review trigger performance metrics
  2. Condition Updates: Update trigger conditions as business rules change
  3. Error Analysis: Analyze and address recurring trigger failures
  4. Resource Optimization: Optimize resource usage and costs
  5. Documentation Updates: Keep trigger documentation current

Change Management

  1. Version Control: Maintain versions of trigger configurations
  2. Testing Procedures: Test trigger changes in development environments
  3. Gradual Rollout: Deploy trigger changes incrementally
  4. Rollback Plans: Plan for reverting problematic trigger changes
  5. Impact Assessment: Assess the impact of trigger modifications