Skip to main content
Triggers let you automate actions based on user behavior — like opening the chat when someone scrolls down, showing a form after time on page, or displaying a message on exit intent.

Endpoints

MethodEndpointDescription
GET/triggersList triggers for an agent
GET/triggers/:idGet a specific trigger
GET/triggers/statsGet trigger statistics
GET/triggers/templatesList trigger templates
POST/triggersCreate a new trigger
PUT/triggers/:idUpdate a trigger
DELETE/triggers/:idDelete a trigger
POST/triggers/:id/toggleToggle enabled state

Widget Endpoints (Public)

MethodEndpointDescription
GET/triggers/widget/:agentIdGet active triggers for widget
POST/triggers/eventRecord a trigger event
GET/triggers/form/:toolIdOrNameGet form schema for trigger

List Triggers

GET /triggers?agentId={agentId}

Query Parameters

ParameterTypeRequiredDescription
agentIdstringYesThe agent ID

Response

[
  {
    "id": "trig_abc123",
    "agentId": "agent_xyz789",
    "name": "Welcome Message",
    "description": "Show welcome after 10 seconds",
    "triggerType": "time_on_page",
    "conditions": {
      "timeOnPage": 10
    },
    "actionType": "show_bubble",
    "actionConfig": {
      "message": "👋 Need help finding something?"
    },
    "triggerOnce": true,
    "isEnabled": true,
    "priority": 0,
    "createdAt": "2024-12-20T10:00:00.000Z",
    "updatedAt": "2024-12-20T10:00:00.000Z"
  }
]

Get Trigger

GET /triggers/{id}
Returns a single trigger object.

Get Trigger Stats

GET /triggers/stats?agentId={agentId}
Get performance statistics for all triggers.

Response

{
  "trig_abc123": {
    "firedCount": 1250,
    "convertedCount": 87
  },
  "trig_def456": {
    "firedCount": 430,
    "convertedCount": 23
  }
}
FieldDescription
firedCountNumber of times trigger was activated
convertedCountNumber of times user engaged after trigger

List Templates

GET /triggers/templates
Get pre-built trigger templates from the marketplace.

Response

[
  {
    "id": "template_welcome",
    "name": "Welcome Message",
    "description": "Greet visitors after 10 seconds",
    "triggerType": "time_on_page",
    "conditions": { "timeOnPage": 10 },
    "actionType": "show_bubble",
    "actionConfig": { "message": "👋 Hi! How can I help?" }
  }
]

Create Trigger

POST /triggers?agentId={agentId}

Request Body

{
  "name": "Exit Intent Popup",
  "description": "Show offer when user tries to leave",
  "triggerType": "exit_intent",
  "conditions": {},
  "actionType": "show_form",
  "actionConfig": {
    "toolId": "tool_abc123"
  },
  "triggerOnce": true,
  "isEnabled": true,
  "priority": 10
}

Parameters

FieldTypeRequiredDescription
namestringYesDisplay name for the trigger
descriptionstringNoDescription of what the trigger does
triggerTypestringYesType of trigger (see below)
conditionsobjectYesConditions for activation
actionTypestringYesAction to perform
actionConfigobjectYesAction configuration
triggerOncebooleanNoOnly fire once per session (default: true)
isEnabledbooleanNoWhether trigger is active (default: true)
prioritynumberNoExecution order (lower = first)

Trigger Types

TypeDescriptionConditions
time_on_pageAfter user spends X secondstimeOnPage: number
scroll_depthAfter scrolling X% of pagescrollDepth: number (0-100)
exit_intentWhen mouse leaves viewportNone
page_viewWhen visiting specific pagepage: string (glob pattern)
custom_eventWhen custom event firesevent: string, eventData?: object

Action Types

TypeDescriptionConfig
open_chatOpens the chat widgetmessage?: string (pre-filled)
show_formDisplays a formtoolId: string
show_bubbleShows notification bubblemessage: string, duration?: number

Response

{
  "id": "trig_abc123",
  "agentId": "agent_xyz789",
  "name": "Exit Intent Popup",
  "triggerType": "exit_intent",
  "conditions": {},
  "actionType": "show_form",
  "actionConfig": { "toolId": "tool_abc123" },
  "triggerOnce": true,
  "isEnabled": true,
  "priority": 10,
  "createdAt": "2024-12-20T10:00:00.000Z",
  "updatedAt": "2024-12-20T10:00:00.000Z"
}

Update Trigger

PUT /triggers/{id}

Request Body

Only include fields you want to update:
{
  "conditions": {
    "timeOnPage": 15
  },
  "isEnabled": false
}

Response

Returns the updated trigger object.

Delete Trigger

DELETE /triggers/{id}

Response

{
  "success": true
}

Toggle Trigger

POST /triggers/{id}/toggle
Quickly enable or disable a trigger.

Response

Returns the updated trigger with isEnabled toggled.

Widget Endpoints

These public endpoints are used by the widget to fetch and record triggers.

Get Widget Triggers

GET /triggers/widget/{agentId}
Returns only enabled triggers with minimal fields for the widget:
[
  {
    "id": "trig_abc123",
    "name": "Welcome Message",
    "triggerType": "time_on_page",
    "conditions": { "timeOnPage": 10 },
    "actionType": "show_bubble",
    "actionConfig": { "message": "👋 Need help?" },
    "triggerOnce": true,
    "priority": 0
  }
]

Record Trigger Event

POST /triggers/event
Record when a trigger fires or converts.

Request Body

{
  "agentId": "agent_xyz789",
  "triggerId": "trig_abc123",
  "triggerName": "Welcome Message",
  "triggerType": "time_on_page",
  "actionType": "show_bubble",
  "eventType": "fired",
  "sessionId": "sess_123",
  "pagePath": "/pricing"
}
FieldTypeRequiredDescription
agentIdstringYesAgent ID
triggerIdstringNoTrigger ID (if known)
triggerNamestringYesTrigger name
triggerTypestringYesTrigger type
actionTypestringYesAction type
eventTypestringYesfired or converted
sessionIdstringNoSession identifier
pagePathstringNoCurrent page path

Rate Limits

  • 100 events per minute per session/IP
  • Returns 429 when exceeded

Get Form for Trigger

GET /triggers/form/{toolIdOrName}
Fetch form schema when a show_form trigger fires.
{
  "toolId": "tool_abc123",
  "toolName": "contact_form",
  "formSchema": {
    "fields": [
      { "name": "email", "label": "Email", "type": "email" }
    ]
  },
  "executionMode": "webhook",
  "clientHandler": null
}

Examples

Time-Based Welcome

Show a message after 10 seconds:
curl -X POST "https://api.ansa.so/triggers?agentId=agent_xyz789" \
  -H "Authorization: Bearer $ANSA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome Message",
    "triggerType": "time_on_page",
    "conditions": { "timeOnPage": 10 },
    "actionType": "show_bubble",
    "actionConfig": {
      "message": "👋 Hi! Looking for something specific?",
      "duration": 10
    }
  }'

Scroll-Triggered Form

Show lead form after 50% scroll:
curl -X POST "https://api.ansa.so/triggers?agentId=agent_xyz789" \
  -H "Authorization: Bearer $ANSA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Scroll Lead Capture",
    "triggerType": "scroll_depth",
    "conditions": { "scrollDepth": 50 },
    "actionType": "show_form",
    "actionConfig": { "toolId": "tool_lead_form" }
  }'

Exit Intent Offer

Open chat when user tries to leave:
curl -X POST "https://api.ansa.so/triggers?agentId=agent_xyz789" \
  -H "Authorization: Bearer $ANSA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Exit Intent",
    "triggerType": "exit_intent",
    "conditions": {},
    "actionType": "open_chat",
    "actionConfig": {
      "message": "Wait! Can I help you find what you are looking for?"
    }
  }'

Page-Specific Trigger

Show help on pricing page:
curl -X POST "https://api.ansa.so/triggers?agentId=agent_xyz789" \
  -H "Authorization: Bearer $ANSA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pricing Help",
    "triggerType": "page_view",
    "conditions": { "page": "/pricing/*" },
    "actionType": "show_bubble",
    "actionConfig": {
      "message": "Questions about pricing? I can help!"
    }
  }'

Custom Event Trigger

React to custom events from your code:
curl -X POST "https://api.ansa.so/triggers?agentId=agent_xyz789" \
  -H "Authorization: Bearer $ANSA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Cart Abandonment",
    "triggerType": "custom_event",
    "conditions": {
      "event": "cart_abandoned",
      "eventData": { "cartValue": { "$gt": 100 } }
    },
    "actionType": "open_chat",
    "actionConfig": {
      "message": "Noticed you have items in your cart. Any questions?"
    }
  }'
Then fire from your code:
ansa.trigger("cart_abandoned", { cartValue: 150 });

Condition Patterns

Page Matching

The page condition supports glob patterns:
PatternMatches
/pricingExact match
/pricing/*/pricing/starter, /pricing/pro
/blog/**Any path under /blog/
/docs/**/api/docs/v1/api, /docs/v2/guides/api