How to send events through the API

You can send events to our system from server side.

To implement this and identify the user doing the event there are 2 options:

  1. pass the email address
  2. pass userId and sessionId found on the client-side.

We don’t currently support other type of user identification/reconciliation.

Note that sending user email address does not subscribe users and it’s only required to manage user activity, events and sessions.

userId and sessionId

UserId and sessionId are found in a cookie called _vt_user.

The value of the cookie has the format below. You need to split the string by _ (underscore) and then you will have:

  • first value as user ID (8139618027113397 in the example)
  • second value as session ID (253412802711339765 in the example)
8139618027113397_253412802711339765_false_false

Event Request

Request type: GET

BASE URL: https://app.vtcdn.net/event/<account_id>/

Params: 

  • data -> json encoded list of events (see below)
  • callback -> any custom string (optional)
  • ts -> random integer

Example code below, please change the values in red.

Event type is the same as type within the data. First example is confirmation.

<?php
$server_base = "https://app.vtcdn.net/event/<account_id>/<event_type>";
// list of items in the order
$items = array(array("id" => "123123-M", "quantity" => 2), array("id" => "23423-XL", "quantity" => 1));
// confirmation object
$confirmation = array("userId"=>"0111", "sessionId" => "013123", "type" => 'confirmation', "items" => $items, "generic" => array("orderId"=>"order_id_example", "total" => 234.12, "email" => "[email protected]"));
$params = array (
"data" => json_encode(array($confirmation)),
"callback" => 'vt',
"ts" => rand(0,1000)
);

$server_base = $server_base . '?' . http_build_query($params);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server_base);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);

?>

Example 2 login event. Here event_type is login

<?php
$server_base = "https://app.vtcdn.net/event/<account_id>/<event_type>";
$event = array("type" => 'login', "email" => "[email protected]", "source" => "source_type");
$params = array (
"data" => json_encode(array($event)),
"callback" => 'vt',
"ts" => rand(0,1000)
);

$server_base = $server_base . '?' . http_build_query($params);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server_base);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);

?>

Server Side User Identification

There are 3 ways of user identification (who did the event) on our backend systems:

  1. User ID and Session ID: the ones set by our Web Pixel
  2. User email address of an existing user. send email address instead of user ID and session ID. Email must already exist in the system.
  3. Unique identifier (_vtsid): it works in conjunction with Web Pixel and must be sent prior to Server Side request
    • set _vtsid in the event set along with userId and sessionId
    • send the same _vtsid along with the event from server side, without userId and sessionId

Related Articles