# Analytics App

Event tracking and analytics for Dexxy.

## Purpose

This app provides a flexible event logging system for tracking user actions and system events. Events are stored with JSON properties for extensible data capture without schema changes.

## Models

### Event

Represents a tracked event in the system.

| Field | Type | Description |
|-------|------|-------------|
| `workspace` | ForeignKey | Workspace scope |
| `name` | CharField | Event type identifier |
| `occurred_at` | DateTimeField | When the event happened |
| `member` | ForeignKey | Optional member reference |
| `properties` | JSONField | Flexible event data |

## GraphQL API

### Queries

- `events(workspace_id, name?, member_id?, limit?)` - Query events with filters
- `event(id)` - Get a specific event

### Mutations

None - Events are created via backend services, not directly by clients.

## Key Patterns

1. **Schemaless Properties**: JSON field allows any event data structure
2. **Member Attribution**: Events can optionally link to community members
3. **Workspace Scoping**: All analytics isolated by workspace

## Usage Examples

```python
from analytics.models import Event

# Track a member action
Event.objects.create(
    workspace=workspace,
    name="thread.viewed",
    member=member,
    properties={"thread_id": 123, "source": "feed"}
)

# Track a system event
Event.objects.create(
    workspace=workspace,
    name="sync.completed",
    properties={"repository": "owner/repo", "items_synced": 42}
)
```

## Dependencies

- `accounts.Workspace`
- `members.Member` (optional)

## File Structure

```
analytics/
├── models.py      # Event model
├── graphql.py     # GraphQL types and queries
├── apps.py        # Django app config
└── migrations/    # Database migrations
```
