> For the complete documentation index, see [llms.txt](https://teamleader-sdk.mcore-services.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://teamleader-sdk.mcore-services.dev/api-reference/general/email-tracking.md).

# Email Tracking

Manage email tracking in Teamleader Focus - track emails sent to various entities.

```php
Teamleader::emailTracking()
```

|                          |                                                                       |
| ------------------------ | --------------------------------------------------------------------- |
| Class                    | `McoreServices\TeamleaderSDK\Resources\General\EmailTracking`         |
| Create / update / delete | ✓ / — / —                                                             |
| Pagination               | `page_size` / `page_number`; no totals — a short page is the last one |

## Endpoints

* `emailTracking.create`
* `emailTracking.list`

## Filters

Passed as the first argument to `list()`. Any other key throws.

| Filter         | Description                                           |
| -------------- | ----------------------------------------------------- |
| `subject.id`   | UUID of the subject entity                            |
| `subject.type` | Type of subject entity (contact, company, deal, etc.) |

## Accepted values

Public constants on the class. Body fields and enum values outside these lists throw before the request is sent.

| Constant        | Values                                                                                                          |
| --------------- | --------------------------------------------------------------------------------------------------------------- |
| `CREATE_FIELDS` | `subject`, `title`, `content`, `attachments`                                                                    |
| `SUBJECT_TYPES` | `contact`, `company`, `deal`, `invoice`, `creditNote`, `subscription`, `product`, `quotation`, `nextgenProject` |

## Methods

### `forSubject()`

```php
forSubject(string $subjectType, string $subjectId, array $options = []): array
```

Get email tracking for a specific subject

* `$subjectType` — Type of subject (contact, company, deal, etc.)
* `$subjectId` — UUID of the subject
* `$options` — Additional options (pagination)

### `list()`

```php
list(array $filters = [], array $options = []): array
```

List email tracking entries with filtering

* `$filters` — Filters to apply
* `$options` — Additional options (pagination)

### `createForContact()`

```php
createForContact(string $contactId, string $title, string $content, array $attachments = []): array
```

Create email tracking for a contact

* `$contactId` — Contact UUID
* `$title` — Email subject
* `$content` — Email content
* `$attachments` — Array of attachment file UUIDs

### `create()`

```php
create(array $data): array
```

Create new email tracking entry

* `$data` — Email tracking data

### `createForCompany()`

```php
createForCompany(string $companyId, string $title, string $content, array $attachments = []): array
```

Create email tracking for a company

* `$companyId` — Company UUID
* `$title` — Email subject
* `$content` — Email content
* `$attachments` — Array of attachment file UUIDs

### `createForDeal()`

```php
createForDeal(string $dealId, string $title, string $content, array $attachments = []): array
```

Create email tracking for a deal

* `$dealId` — Deal UUID
* `$title` — Email subject
* `$content` — Email content
* `$attachments` — Array of attachment file UUIDs

### `getAvailableSubjectTypes()`

```php
getAvailableSubjectTypes(): array
```

Get available subject types

## Examples

Get all email tracking for a specific contact:

```php
$emails = Teamleader::emailTracking()->forSubject("contact", "contact-uuid");
```

Get all email tracking for a specific company:

```php
$emails = Teamleader::emailTracking()->forSubject("company", "company-uuid");
```

Create email tracking for a contact:

```php
$email = Teamleader::emailTracking()->createForContact("contact-uuid", "Subject", "Email content");
```

Create email tracking with attachments:

```php
$email = Teamleader::emailTracking()->create(["subject" => ["type" => "contact", "id" => "uuid"], "title" => "Subject", "content" => "Content", "attachments" => ["file-uuid"]]);
```
