# Ads Tracking Service Architecture

## Overview

```mermaid
graph TB
    PIX[Pixel] --> EVT[Event Ingestion]
    SDK[SDK] --> EVT
    EVT --> ATTR[Attribution]
    ATTR --> ANAL[ads-analytics]
```

## Domain Aggregates

- **TrackingPixel**: Per-advertiser pixel code
- **PixelEvent**: PageView, Purchase, Lead
- **Conversion**: Attributed conversion
- **Attribution**: Links conversion to ad

## Attribution Models

| Model | Description |
|-------|-------------|
| **Last-click** | Credit to last clicked ad |
| **First-click** | Credit to first clicked ad |
| **Linear** | Equal credit to all touchpoints |

## Windows

| Setting | Click | View |
|---------|-------|------|
| **7/1** | 7 days | 1 day |
| **28/1** | 28 days | 1 day |

## Database (TimescaleDB)

```sql
CREATE TABLE pixel_events (
    event_type VARCHAR(50),
    event_data JSONB,
    user_id VARCHAR(255),
    event_time TIMESTAMPTZ
);
SELECT create_hypertable('pixel_events', 'event_time');
```
