# Event-Based Targeting

Target messages based on user behavior - what actions they've taken (or haven't taken) in your product.

## Why Event Targeting?

Event-based targeting lets you:

* **React to behavior** - Show messages based on what users do
* **Fill gaps** - Prompt users who haven't taken key actions
* **Celebrate milestones** - Recognize achievements
* **Drive adoption** - Guide users to valuable features

## Tracking Events

Before using event targeting, you need to track events:

```javascript
// Track when user creates a project
Cueflow.track('project_created');

// Track with properties
Cueflow.track('file_exported', { format: 'csv' });
```

See [Tracking Events](/data/understanding-events/tracking-events.md) for details.

## Event Operators

### Has Done / Has Not Done

**Has Done** - User has triggered this event at least once:

```
Event → project_created → Has Done
```

**Has Not Done** - User has never triggered this event:

```
Event → onboarding_completed → Has Not Done
```

### Count Operators

**Count Equals** - Triggered exactly X times:

```
Event → file_exported → Count Equals → 5
```

**Count Greater Than** - Triggered more than X times:

```
Event → project_created → Count Greater Than → 10
```

**Count Less Than** - Triggered fewer than X times:

```
Event → invite_sent → Count Less Than → 3
```

### Recency Operators

**First Done Within** - First occurrence was recent:

```
Event → signup_completed → First Done Within → 7 days
```

**Last Done Within** - Most recent occurrence was recent:

```
Event → login → Last Done Within → 1 day
```

**First Done Before** - First occurrence was a while ago:

```
Event → signup_completed → First Done Before → 30 days
```

**Last Done Before** - Haven't done it recently:

```
Event → feature_used → Last Done Before → 14 days
```

## Common Patterns

### Feature Adoption

Prompt users who haven't tried a feature:

```
Event → advanced_search_used → Has Not Done
```

### Onboarding Progress

Target users stuck in onboarding:

```
Event → signup_completed → Has Done
AND
Event → first_project_created → Has Not Done
AND
Signed Up At → Is Before → 3 days
```

### Power Users

Recognize highly engaged users:

```
Event → project_created → Count Greater Than → 20
```

### Re-engagement

Target users who used to be active:

```
Event → login → Has Done
AND
Event → login → Last Done Before → 7 days
```

### Milestone Celebration

Celebrate when users reach milestones:

```
Event → task_completed → Count Equals → 100
```

### Feature Discovery

Introduce features to users ready for them:

```
Event → basic_report_viewed → Count Greater Than → 5
AND
Event → advanced_report_viewed → Has Not Done
```

## Combining with Other Rules

### Event + Contact

Target free users who are power users:

```
Plan → Equals → "free"
AND
Event → project_created → Count Greater Than → 5
```

### Event + Page

Show feature tip on relevant page:

```
Page Path → Equals → "/analytics"
AND
Event → custom_dashboard_created → Has Not Done
```

### Event + Time

Target new users who took specific actions:

```
Signed Up At → Is Within → 7 days
AND
Event → first_project_created → Has Done
AND
Event → team_member_invited → Has Not Done
```

### Multiple Events

Target users with specific behavior patterns:

```
Event → project_created → Has Done
AND
Event → file_uploaded → Has Done
AND
Event → shared_project → Has Not Done
```

## Examples by Goal

### Welcome Flow

Show welcome after signup:

```
Event → signup_completed → Has Done
AND
Event → welcome_dismissed → Has Not Done
AND
Signed Up At → Is Within → 1 day
```

### Upgrade Prompt

Target engaged free users:

```
Plan → Equals → "free"
AND
Event → export_completed → Count Greater Than → 3
```

### Feature Announcement

Announce to users who'd benefit:

```
Event → report_generated → Has Done
AND
Event → scheduled_report_used → Has Not Done
```

### Churn Prevention

Re-engage users showing churn signals:

```
Event → login → Last Done Before → 7 days
AND
Plan → Not Equals → "free"
```

### Success Celebration

Celebrate first milestone:

```
Event → first_sale_completed → Has Done
AND
Event → first_sale_celebrated → Has Not Done
```

### Feedback Request

Ask for feedback from engaged users:

```
Event → feature_x_used → Count Greater Than → 10
AND
Signed Up At → Is Before → 30 days
```

## Checklist Auto-Completion

Events can automatically complete checklist items:

1. Set completion type to "Automatic"
2. Add rule: Event → `event_key` → Has Done

When the event fires, the checklist item completes.

**Example:**

* Checklist item: "Create your first project"
* Rule: Event → project\_created → Has Done

## Best Practices

### Choose Meaningful Events

Track events that represent real value:

* `project_published` (valuable) vs `button_clicked` (not useful)
* `export_completed` (action) vs `export_started` (partial)

### Test Your Rules

1. Track the event yourself
2. Verify it triggers the message
3. Check it doesn't trigger unexpectedly

### Combine for Precision

Layer multiple rules for better targeting:

* Event + Time = Right moment
* Event + Plan = Right user
* Event + Page = Right context

### Monitor Performance

* Check which events trigger messages
* Review targeting effectiveness
* Iterate based on results

## Troubleshooting

### Message not showing

1. Verify the event was tracked (check [**Events**](https://app.cueflow.so/events) page)
2. Confirm event key matches exactly
3. Check other targeting rules aren't blocking
4. Ensure message is Published

### Wrong timing

1. Check recency operators (within vs before)
2. Verify count thresholds
3. Test with fresh user data

### Events not tracking

1. Confirm Cueflow\.init() was called first
2. Check browser console for errors
3. Verify event key format


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cueflow.so/targeting/event-targeting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
