Skip to main content

PHP SDK

The PHP SDK can be found on GitHub or composer package.

Installation

You can install the SDK using Composer or by copying the src/Client.php directly.

composer require vantevo-analytics/sdk

Usage

To start tracking page views, events, and getting statistics, you need to initialize the client first:

OptionTypeDescription
accessTokenstring (required)To create an api key read our guide.
domainstring (required)Enter the domain you want to use to collect statistics.The domain must not include http, https, or www. Example: example.com
timeoutint (optional)You can change the request timeout, you need to enter a number in seconds. Default 30.
devboolean (optional)Tracker will not send data to server, the client execute print the data. Default false.
require __DIR__ . '/vendor/autoload.php'; // or require_once 'src/Client.php';

$client = new Vantevo\Client('accessToken', 'domain', 'timeout' 'dev');

Tracking page views and events

Parameters

OptionTypeDescription
eventarray (required)See event parameters.

Event parameters

OptionTypeDescription
eventstring (required)Event name, remember that the name pageview will send a pageview event.
urlstring (optional)Enter url you want to save in the statistics. Default is where the client is installed.
titlestring (optional)You can insert a title of the page, if this field is not used vantevo will insert the pathname of the url used.
referrerstring (optional)In this field you can enter a referrer for your request. Default $_SERVER[HTTP_REFERER] or the client checks query parameters: ref, referrer, source, utm_source.
widthstring (optional)This field is used to save the screen size. Default: 0.
heightstring (optional)This field is used to save the screen size. Default: 0.
metaarray (optional)Enter the event values meta_key and meta_value, read more how to create an event Default: array.

Example pageview

try {
$data = array("event" => "pageview", "title" => "Eaxmple Page view");
$client->event($data);
} catch (Exception $e) {
// something went wrong...
}

Example event

try {
$data = array("event" => "Download", "meta" => array("pdf": "Recipes"));
$client->event($data);
} catch (Exception $e) {
// something went wrong...
}

How to get the statistics

Parameters

OptionTypeDescription
filtersarray (required)Check out our guide to see all the filters you can use like, click here.

Example Statistics

try {
$data = array("source" => "pages", "period" => "1m");
$stats = $client->stats($data);
} catch (Exception $e) {
// something went wrong...
}

Example Events

try {
$data = array("source" => "events", "period" => "1m");
$events = $client->events($data);
} catch (Exception $e) {
// something went wrong...
}