vidovo / pixel-php
Send conversions, refunds and cancellations from your server to the Vidovo pixel.
Requires
- php: >=8.2
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Send conversions, refunds and cancellations from your server to the Vidovo pixel. A sale your server sends is confirmed, and it still counts when the buyer's browser blocks the pixel or closes too soon.
Install
composer require vidovo/pixel-php
PHP 8.2 or newer, with the curl extension. No dependencies.
Usage
use Vidovo\Pixel\Pixel; $pixel = new Pixel(getenv('VIDOVO_PIXEL_SECRET_KEY')); $pixel->conversion([ 'event_name' => 'purchase', 'order_id' => '5001', 'value' => 80.00, 'currency' => 'USD', 'vidovo' => $order->vidovo, // who the buyer was, saved at checkout ]);
Refunds and cancellations
refunded_total is everything refunded on the order so far.
$pixel->refund(['order_id' => '5001', 'refunded_total' => 30.00, 'currency' => 'USD']); $pixel->cancellation(['order_id' => '5002']);
send takes several events and sends them in one request. Vidovo takes all of them or none.
$pixel->send([ ['type' => 'conversion', 'event_name' => 'sign_up', 'event_id' => 'signup-7', 'customer_id' => '7', 'vidovo' => $vidovo], ['type' => 'cancellation', 'order_id' => '5002'], ]);
The buyer
A sale is credited to the Vidovo link that brought its buyer. The pixel keeps the buyer in cookies on your site, so read them off a request the buyer's browser makes, like your checkout, and save the result with the order:
$order->vidovo = Pixel::vidovoFromCookies($_COOKIE);
It is null when the buyer is not tracked. A payment webhook or a background job has no cookies, so read it while the buyer is there.
If you get the pixel's cookie some other way, pass the _vdv_visitor value in vidovo as it is, and the SDK turns it into what Vidovo reads:
$pixel->conversion(['event_name' => 'purchase', 'order_id' => '5001', 'vidovo' => $order->vdv_visitor_cookie]);
vidovo also takes the text vidovo('checkout') gives your page.
Laravel encrypts cookies and empties the ones it did not write. Pass $_COOKIE, or add _vdv_visitor, _vdv_kept and _vdv_off to the cookies it leaves alone and pass $request->cookies->all().
Errors
An answer other than success throws a PixelException, with the message Vidovo sent. When no answer came, status is 0.
use Vidovo\Pixel\PixelException; try { $pixel->conversion($conversion); } catch (PixelException $e) { if ($e->retryAfter) { // 429 or 503: send the same request again after $e->retryAfter seconds } }
Options
$pixel = new Pixel($secretKey, baseUrl: 'https://px.vidovo.com', timeout: 10);