Vidovo pixel for Node.js
Send conversions, refunds and cancellations from your server to the Vidovo pixel.
npm install @vidovo/pixel-js
Node.js 20.19 or newer, with import or require. No dependencies.
Usage
import { Pixel } from '@vidovo/pixel-js';
const pixel = new Pixel(process.env.VIDOVO_PIXEL_SECRET_KEY);
await pixel.conversion({
event_name: 'purchase',
order_id: '5001',
value: 80.0,
currency: 'USD',
vidovo: order.vidovo, // the text vidovo('checkout') gave your page
});
// Everything refunded on the order so far
await pixel.refund({ order_id: '5001', refunded_total: 30.0, currency: 'USD' });
await pixel.cancellation({ order_id: '5001' });
The vidovo field can be read on your server instead. The pixel keeps it in cookies on your site, so read it off a request the visitor's browser makes to your site, like your checkout, and save it with the order:
import { vidovoFromCookies } from '@vidovo/pixel-js';
order.vidovo = vidovoFromCookies(req.headers.cookie); // Express
order.vidovo = vidovoFromCookies(request.headers.get('cookie')); // Next.js, Hono, Workers
It is undefined when the visitor is not tracked. A webhook or a background job has no cookies, so read it while the visitor is there.
Several events in one request:
await pixel.send([
{ type: 'conversion', event_name: 'sign_up', event_id: 'signup-7', customer_id: '7', vidovo },
{ type: 'cancellation', order_id: '5002' },
]);
Errors
An answer other than success throws a PixelError, with the message Vidovo sent. A request that gets no answer throws fetch's own error.
import { PixelError } from '@vidovo/pixel-js';
try {
await pixel.conversion(conversion);
} catch (error) {
if (error instanceof PixelError && error.retryAfter) {
// 429 or 503: send it again after error.retryAfter seconds
}
}
Options
new Pixel(secretKey, { baseUrl: 'https://px.vidovo.com', timeout: 10_000 });