Javascript SDK
The JavaScript SDK can be found on GitHub or npm.
Installationβ
npm install vantevo-analytics-sdk
Usageβ
To start tracking page views, events, and getting statistics, you need to initialize the client first:
| Option | Type | Description |
|---|---|---|
| accessToken | string (required) | To create an api key read our guide. |
| domain | string (required) | Enter the domain you want to use to collect statistics.The domain must not include http, https, or www. Example: example.com |
| protocol | string (required) | http or https |
| userAgent | string (optional) | To monitor page views and events, requests must have a user-agent, here you can assign a global ΓΉser-agent`. |
| xForwardedFor | string (optional) | To monitor page views and events requests must have an ip, here you can assign a global ip. |
| dev | boolean (optional) | Tracker will not send data to server, please check console/log file to view request information. |
const { VantevoAnalytics } = require("vantevo-analytics-sdk");
var client = new VantevoAnalytics({
accessToken: "",
domain: "",
protocol: "",
userAgent: "",
xForwardedFor: "",
dev: false,
});
Tracking page views and eventsβ
Parameters
| Option | Type | Description |
|---|---|---|
| event | object (required) | See event parameters. |
| userAgent | string (optional) | To monitor page views and events, requests must have a user-agent, you can use this parameter if you don't have a global user-agent. |
| xForwardedFor | string (optional) | To monitor page views and events requests must have an ip, you can use this parameter if you don't have a global ip. |
Event parameters
| Option | Type | Description |
|---|---|---|
| event | string (required) | Event name, remember that the name pageview will send a pageview event. |
| url | string (required) | Enter url you want to save in the statistics. |
| title | string (optional) | You can insert a title of the page, if this field is not used vantevo will insert the pathname of the url used. |
| referrer | string (optional) | In this field you can enter a referrer for your request. Default: null. |
| width | string (optional) | This field is used to save the screen size. Default: 0. |
| height | string (optional) | This field is used to save the screen size. Default: 0. |
| meta | object (optional) | Enter the event values meta_key and meta_value, read more how to create an event Default: {}. |
const { VantevoAnalytics } = require("vantevo-analytics-sdk");
var client = new VantevoAnalytics({....});
//without global useragent and ip
client.event({event: "pageview"}, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36", "92.16.12.2");
//with global useragent and ip
client.event({event: "pageview"});
Express jsβ
To use express js middleware make sure the script can get useragent and the ip, to get the data the script uses req["useragent"] and req.headers['x-forwarded-for'].
const express = require('express');
const { VantevoAnalytics } = require("vantevo-analytics-sdk");
const app = express();
var client = new VantevoAnalytics({....});
app.use(client.express());
How to get the statisticsβ
Parameters
| Option | Type | Description |
|---|---|---|
| filters | object (required) | Check out our guide to see all the filters you can use like, click here. |
Example Statisticsβ
const { VantevoAnalytics } = require("vantevo-analytics-sdk");
var client = new VantevoAnalytics({....});
client.stats({source: 'pages', period: "1m", limit: 30, offset: 0, city: "Rome", ....}).then(() => {}).catch(() => {});
Example Eventsβ
const { VantevoAnalytics } = require("vantevo-analytics-sdk");
var client = new VantevoAnalytics({....});
client.events({source: 'events', period: "1m", limit: 30, offset: 0, city: "Rome", ....}).then(() => {}).catch(() => {});