> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hacktionbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Events

> How event tracking works in Hacktionbase.

## Overview

Events represent actions your users take in your application. They are the foundation for building segments, triggering campaigns, and understanding user behavior.

## Sending events

You can send events from two places:

| Source                | How                                  | Best for                                         |
| --------------------- | ------------------------------------ | ------------------------------------------------ |
| **SDK** (client-side) | `Hacktionbase.track('event', props)` | Page views, clicks, UI interactions              |
| **API** (server-side) | `POST /v1/events`                    | Purchases, subscription changes, backend actions |

### From the SDK

```javascript theme={null}
Hacktionbase.track('checkout_completed', {
  total: 99.99,
  currency: 'EUR',
  items: 3
});
```

### From your backend

```bash theme={null}
curl -X POST https://api.hacktionbase.com/v1/events \
  -H "Authorization: Bearer hb_key_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "subscription_upgraded",
    "userExternalId": "user_123",
    "properties": { "plan": "growth" }
  }'
```

## Automatic events

The SDK tracks these events automatically — no code needed:

| Event       | Trigger                                                  |
| ----------- | -------------------------------------------------------- |
| `page_view` | Every page navigation (initial load + SPA route changes) |
| `js_error`  | Unhandled JavaScript errors                              |

## Naming conventions

Use `snake_case` for event names:

```javascript theme={null}
// ✅ Recommended
Hacktionbase.track('feature_activated', { feature: 'dark_mode' });

// ❌ Avoid
Hacktionbase.track('Feature Activated');   // Spaces
Hacktionbase.track('featureActivated');    // camelCase
```

## How events power the platform

Once events are tracked, they feed into several features:

* **Segments** — define user groups based on event history (e.g., "users who completed checkout in the last 7 days")
* **Campaigns** — trigger in-app messages or emails when specific events occur
* **User timeline** — view a chronological feed of events on each user's profile
* **Session context** — events are linked to sessions, so you can see exactly what happened during a replay
