Docs / PHP

Install the PHP SDK

At the end your app sends events and errors to Vinktar on one key, and identify() joins them to a person.

Before you start

vinktarhq/php (Packagist). PHP 8.2 and later. Beta.

You need a Vinktar project. Replace vnk_pk_YOUR_KEY below with its public write key. The app shows the same snippets with your key filled in.

A coding agent connected over MCP can do this install for you. It reads the install guide, fetches the key, wires identify, defines the events it adds and checks what arrived. Connect your agent.

1. Install

composer require vinktarhq/php:^0.2@beta

2. Initialise

$vinktar = new Vinktar\Client([
    'writeKey' => getenv('VINKTAR_KEY'),
    'captureErrors' => true,   // uncaught exceptions, warnings and fatal errors
]);

$vinktar->scopeFromHeaders($_SERVER);   // joins the browser SDK's visitor

// After sign-in, so errors and events join to a person:
$vinktar->identify((string) $user->id, ['email' => $user->email, 'plan' => 'pro']);
$vinktar->track('Order completed', ['total' => 49]);

Check it worked

Load a page. What is queued goes out when the request ends; a queue worker wraps each job in $vinktar->withScope() and calls $vinktar->flush() after it.

Join events and errors to a person

Anonymous activity is kept under the device. The first identify() with a user id binds that device to the person, and everything before it resolves to them retroactively. A device binds once; call reset() on logout so the next person gets a fresh one. The full rules are in api.md.

Next