---
title: "PHP | SDKs | Documentation - Vemetric"
description: "Track your data via the PHP SDK for Vemetric."
url: https://vemetric.com/docs/sdks/php
---

# PHP SDK

Track your data via the PHP SDK for Vemetric.

* * *

Below you can see how to initialize and configure the SDK, as well as all the available functions.

> The PHP SDK doesn’t track your page visitors and is meant as a complement to the [Frontend SDKs](https://vemetric.com/docs/sdks/overview#frontend).

## Installation

### Install with Composer

In your project directory, run:

```bash
composer require vemetric/vemetric-php
```

### Initialize the Vemetric Client

We recommend creating a single instance of the Vemetric client and reusing it throughout your application. For example, create a file called `VemetricClient.php` and initialize the client like this:

```php
$vemetric = new Vemetric([
  'token' => 'YOUR_PROJECT_TOKEN',
]);
```

> Replace `YOUR_PROJECT_TOKEN` with the unique token for your project (found in the project settings).

> If you’re [using a proxy](https://vemetric.com/docs/advanced-guides/using-a-proxy) to track data via your own domain, you can pass the `host` option to the client with e.g. `https://hub.yourdomain.com`.

## Methods

Below you can find all the available methods and their functionality.

### trackEvent

The main method to track any kind of event.

```php
$vemetric->trackEvent('SignupCompleted', [
  'userIdentifier'  => 'user-id',
  'userDisplayName' => 'John Doe',
  'userAvatarUrl'   => 'https://example.com/avatar.jpg',
  'eventData'       => ['key' => 'value'],
]);
```

The first argument is the event name. The second argument is an object with the following properties:

-   `userIdentifier`: **Required:** The identifier of the user to associate the event with.
-   `userDisplayName`: Optional: The display name of the user. (will be shown in the Vemetric UI)
-   `userAvatarUrl`: Optional: The avatar URL of the user. (will be shown in the Vemetric UI)
-   `eventData`: Optional: An object containing the meta data of the event so you can later filter by
-   `userData`: Optional: An object to [update the user data](https://vemetric.com/docs/product-analytics/user-identification#updating-user-data).
    -   `set`: An object containing the user data to set, overriding existing values.
    -   `setOnce`: An object containing the user data to set once, only if the keys do not exist yet.
    -   `unset`: An array of keys to remove from the user data.

Checkout the [tracking custom events](https://vemetric.com/docs/product-analytics/tracking-custom-events) section to learn more.

### updateUser

Updates the data of the user with the given identifier.

```php
$vemetric->updateUser([
  'userIdentifier' => 'user-id',
  'userData'       => [
    'set' => ['key1' => 'value1'],
    'setOnce' => ['key2' => 'value2'],
    'unset' => ['key3'],
  ],
]);
```

In order to change the data of the user you can pass a `userData` object with the following properties:

-   `set`: An object containing the user data to set, overriding existing values.
-   `setOnce`: An object containing the user data to set once, only if the keys do not exist yet.
-   `unset`: An array of keys to remove from the user data.

## Resources

[Packagist](https://packagist.org/packages/vemetric/vemetric-php)

View the Package of the PHP SDK.

[Source code](https://github.com/vemetric/vemetric-php)

View the source code of the PHP SDK on GitHub.
