PHP code example of vinktarhq / php

1. Go to this page and download the library: Download vinktarhq/php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vinktarhq / php example snippets


$vinktar = new Vinktar\Client(['writeKey' => getenv('VINKTAR_KEY'), 'captureErrors' => true]);

$vinktar->scopeFromHeaders($_SERVER);          // the browser SDK's device and session
$vinktar->identify($user->id, ['plan' => 'pro']);
$vinktar->track('order_created', ['total' => 42]);

$vinktar->track('checkout_started', ['items' => 3]);
$vinktar->page('Pricing');                                   // $pageview

$vinktar->identify('user_123', ['email' => '[email protected]', 'plan' => 'pro'], ['created' => '2026-01-04']);
$vinktar->setTraits(['plan' => 'team']);                     // for the scope's user
$vinktar->unsetTraits(['trial_ends_at']);

$vinktar->register(['region' => 'eu-west']);                 // on every event from this scope

$vinktar->track('invoice_paid', ['total' => 90], ['userId' => $invoice->ownerId]);

// A job in a long-running worker: everything set inside stays inside.
$vinktar->withScope(function () use ($vinktar, $job) {
    $vinktar->setUser(['id' => $job->userId]);
    $job->handle();
});

// A framework hook that runs before the handler and does not wrap it.
$vinktar->enterScope();

try {
    $gateway->charge($order);
} catch (PaymentFailed $e) {
    $vinktar->captureException($e, ['tags' => ['area' => 'billing'], 'context' => ['order' => $order->id]]);
}

$vinktar->captureMessage('Webhook retried 5 times', ['level' => 'warning']);
$vinktar->addBreadcrumb(['category' => 'queue', 'message' => 'job started', 'data' => ['id' => $job->id]]);

new Vinktar\Client(['writeKey' => $key, 'captureErrors' => true]);   // or $vinktar->registerHandlers()

new Vinktar\Client(['writeKey' => $key, 'captureErrors' => true, 'previousHandlerLevels' => E_ALL]);

$delivered = $vinktar->flush();   // true when the server accepted everything queued
$vinktar->close();                // once, when a worker stops
sh
composer