API integration
In this chapter, we review how to enable monitoring of a client platform. We assume that the Installation instructions have been completed at this stage.
Good news!
tirreno can be used by practically any digital system. Enabling integration with tirreno requires minimal client platform resources.
To start gathering user activity information (events), add an integration script to each monitored page of a client platform.
We have prepared a set of code examples in various programming languages, along with accompanying instructions, to help you get started with the script. The examples can be found in two places:
In the section Code examples below.
At the top of the Send event code example, insert the tracking code and sensor URL values required for API communication. The tracking code authorizes access to the API, while the sensor URL is the API endpoint that accepts HTTP POST requests containing event data. Both values are available on the API page of the console.
Then, fill in event details with the values obtainable in the client platform. For a practical example of the parameters and values to send, see the Event data subsection.
In general, event details include basic user information for building their identity profiles (such as email address, IP address, phone number, etc.) and request data (such as time of the event, URL requested, user agent, etc.). The complete list of mandatory and optional parameters accepted by the API is given in the Parameters section below.
Now, add the finalized integration script to the pages visited by identifiable (i.e., logged-in) users.
To verify that API communication is established, check the account’s Console. The event processing time is expected to fall in the range of a minute, resulting in close to real-time reporting. In case troubleshooting is needed, open the Logbook page, which exposes the processing status of the recent API requests.
Integration outline
To summarize, the steps to perform for accomplishing an API integration are as follows:
Choose a code snippet matching the backend environment of a client platform in the Send event subsection. Or use one of them as a prototype.
In the code snippet, insert account-unique and platform obtainable values.
Add the prepared code to every client platform page that must be monitored.
Verify established API communication at the tirreno console.
Parameters
The sensor accepts six mandatory and ten optional parameters. Each parameter value should be a string. The data must be URL-encoded and sent in a POST request.
Note
We recommend passing as many parameters as possible. Sending more data leads to more detailed reports and thorough analysis.
The sensor always responds with the code 204, even when
receiving non-valid data. Therefore, this only enables monitoring the
sensor’s availability.
To confirm the processing status of requests, refer to the Logbook page.
Attention
The maximum length of all request parameter values is 100 characters, except the following:
urlandhttpReferer: 2047 characters.userAgent: 511 characters.pageTitleandbrowserLanguage: 255 characters.phoneNumber: 19 characters.
Required parameters
userNameA user identifier. It must be a unique value assigned to a user by a client platform. It serves to distinguish one user from another and is employed by tirreno to recognize individual users.
emailAddressAn email address associated with a user.
ipAddressAn IP address associated with an event. It can be retrieved from HTTP request headers.
urluserAgentA user agent string value. It can be retrieved from the HTTP request’s User-Agent header.
eventTimeA timestamp of an event. It must be passed in the format
Y-m-d H:i:s.v(for example, “2024-12-08 18:32:17.397”).
Optional parameters
firstNameA user’s first name.
lastNameA user’s last name.
fullNameA user’s whole name.
pageTitleA title of a visited resource.
phoneNumberA user’s phone number.
httpRefererA value of the Referer HTTP header field.
httpMethodThe type of HTTP request:
GET,POST,HEAD,PUT,DELETE,PATCH,TRACE,CONNECT,OPTIONS,LINKorUNLINK.httpCodeAn HTTP response status code the request ended with.
browserLanguageA detected language of the browser.
eventTypeOne of the event types listed below.
payloadAssociative array of event details, applicable only for
account_email_changeandpage_searchevent types.fieldHistoryArray of event details, applicable only for
field_editevent type.
Event type
Even though the parameter eventType is optional, consider sending it
with the rest of the data. It has proven to be very effective for
user behaviour analytics.
The value must be one of the following:
page_viewpage_editpage_deleteaccount_loginaccount_logoutaccount_login_failaccount_registrationaccount_email_changeaccount_password_changeaccount_editpage_searchpage_errorfield_edit
Payload
For page_search event type payload is defined as single
associative array with required fields field_id and value and one optional
field field_name.
{
"eventType": "page_search",
"payload": {
"value": "Great Br",
"field_id": 179280,
"field_name": "Country"
}
}
For account_email_change event type payload is defined as
single associative array with one required field new_value and one optional
old_value.
{
"eventType": "account_email_change",
"payload": {
"new_value": "team@tirreno.com",
"old_value": "ping@tirreno.com"
}
}
Field history
Filling fieldHistory parameter is required for events with
field_edit event type.
Value should be defined as an array of associative arrays, where each
associative array represents single field edit. Single field edit requires
two fields field_id and new_value, while fields field_name,
old_value, parent_id, parent_name are optional.
{
"eventType": "field_edit",
"payload": [
{
"new_value": "Paris",
"old_value": "London",
"field_id": 179283,
"field_name": "User city"
},
{
"new_value": "France",
"old_value": "Great Britain",
"field_id": 943577,
"field_name": "User country"
}
]
}
Code examples
Event data
This subsection demonstrates how to build an associative array with event details.
The full code examples of API requests for sending event data in different programmer languages are presented in the Send event subsection.
1<?php
2
3$data = array(
4
5 /////////// Required fields ///////////
6
7 // Unique value that allows identification of a user. Ex: alice54 (string)
8 'userName' => 'tirreno42',
9
10 // User email (string)
11 'emailAddress' => 'team@tirreno.com',
12
13 // User IP address (string)
14 'ipAddress' => '217.70.184.38',
15
16 // URL path of visited page (string)
17 'url' => '/home/account?ref=1',
18
19 // User-agent of user request (string)
20 'userAgent' => 'Mozilla/5.0 (Windows NT 6.1; rv:109.0) Gecko/20100101 Firefox/115.0',
21
22 // Event UTC timestamp ('Y-m-d H:i:s.v' string)
23 'eventTime' => '2024-06-06 14:20:01.283',
24
25 /////////// Optional fields ///////////
26
27 // User first name (string)
28 'firstName' => 'John',
29
30 // User last name (string)
31 'lastName' => 'Fox',
32
33 // User full name (string)
34 'fullName' => '',
35
36 // Title of visited page (string)
37 'pageTitle' => 'Home page',
38
39 // User phone number (string)
40 'phoneNumber' => '+41000000000',
41
42 // Referer of visited page (string)
43 'httpReferer' => 'https://tirreno.com/signup',
44
45 // Status code for page visit (string)
46 'httpCode' => '200',
47
48 // User browser language (string)
49 'browserLanguage' => 'en-GB,en;q=0.9',
50
51 // Type of user action from event types list (string)
52 'eventType' => 'account_registration',
53
54 // Type of HTTP request from list (string)
55 'httpMethod' => 'POST',
56
57 // User created UTC timestamp ('Y-m-d H:i:s' string)
58 'userCreated' => ''
59);
1data = {
2 ########### Required fields ###########
3 # Unique value that allows identification of a user. Ex: alice54 (string)
4 'userName': 'tirreno42',
5
6 # User email (string)
7 'emailAddress': 'team@tirreno.com',
8
9 # User IP address (string)
10 'ipAddress': '217.70.184.38',
11
12 # URL path of visited page (string)
13 'url': '/home/account?ref=1',
14
15 # User-agent of user request (string)
16 'userAgent': 'Mozilla/5.0 (Windows NT 6.1; rv:109.0) Gecko/20100101 Firefox/115.0 ',
17
18 # Event UTC timestamp ('Y-m-d H:i:s.v' string)
19 'eventTime': '2024-06-06 14:20:01.283',
20
21 ########### Optional fields ###########
22 # User first name (string)
23 'firstName': 'John',
24
25 # User last name (string)
26 'lastName': 'Fox',
27
28 # User full name (string)
29 'fullName': '',
30
31 # Title of visited page (string)
32 'pageTitle': 'Home page',
33
34 # User phone number (string)
35 'phoneNumber': '+41000000000',
36
37 # Referer of visited page (string)
38 'httpReferer': 'https://tirreno.com/signup',
39
40 # Status code for page visit (string)
41 'httpCode': '200',
42
43 # User browser language (string)
44 'browserLanguage': 'en-GB,en;q=0.9',
45
46 # Type of user action from event types list (string)
47 'eventType': 'account_registration',
48
49 # Type of HTTP request from list (string)
50 'httpMethod': 'POST',
51
52 # User created UTC timestamp ('Y-m-d H:i:s' string)
53 'userCreated': ''
54}
1const data = {
2
3 /////////// Required fields ///////////
4
5 // Unique value that allows identification of a user. Ex: alice54 (string)
6 userName: 'tirreno42',
7
8 // User email (string)
9 emailAddress: 'team@tirreno.com',
10
11 // User IP address (string)
12 ipAddress: '217.70.184.38',
13
14 // URL path of visited page (string)
15 url: '/home/account?ref=1',
16
17 // User-agent of user request (string)
18 userAgent: 'Mozilla/5.0 (Windows NT 6.1; rv:109.0) Gecko/20100101 Firefox/115.0 ',
19
20 // Event UTC timestamp ('Y-m-d H:i:s.v' string)
21 eventTime: '2024-06-06 14:20:01.283',
22
23 /////////// Optional fields ///////////
24
25 // User first name (string)
26 firstName: 'John',
27
28 // User last name (string)
29 lastName: 'Fox',
30
31 // User full name (string)
32 fullName: '',
33
34 // Title of visited page (string)
35 pageTitle: 'Home page',
36
37 // User phone number (string)
38 phoneNumber: '+41000000000',
39
40 // Referer of visited page (string)
41 httpReferer: 'https://tirreno.com/signup',
42
43 // Status code for page visit (string)
44 httpCode: '200',
45
46 // User browser language (string)
47 browserLanguage: 'en-GB,en;q=0.9',
48
49 // Type of user action from event types list (string)
50 eventType: 'account_registration',
51
52 // Type of HTTP request from list (string)
53 httpMethod: 'POST',
54
55 // User created UTC timestamp ('Y-m-d H:i:s' string)
56 userCreated: ''
57};
1data = {
2
3 ########### Required fields ###########
4
5 # Unique value that allows identification of a user. Ex: alice54 (string)
6 'userName': 'tirreno42',
7
8 # User email (string)
9 'emailAddress': 'team@tirreno.com',
10
11 # User IP address (string)
12 'ipAddress': '217.70.184.38',
13
14 # URL path of visited page (string)
15 'url': '/home/account?ref=1',
16
17 # User-agent of user request (string)
18 'userAgent': 'Mozilla/5.0 (Windows NT 6.1; rv:109.0) Gecko/20100101 Firefox/115.0 ',
19
20 # Event UTC timestamp ('Y-m-d H:i:s.v' string)
21 'eventTime': '2024-06-06 14:20:01.283',
22
23 ########### Optional fields ###########
24
25 # User first name (string)
26 'firstName': 'John',
27
28 # User last name (string)
29 'lastName': 'Fox',
30
31 # User full name (string)
32 'fullName': '',
33
34 # Title of visited page (string)
35 'pageTitle': 'Home page',
36
37 # User phone number (string)
38 'phoneNumber': '+41000000000',
39
40 # Referer of visited page (string)
41 'httpReferer': 'https://tirreno.com/signup',
42
43 # Status code for page visit (string)
44 'httpCode': '200',
45
46 # User browser language (string)
47 'browserLanguage': 'en-GB,en;q=0.9',
48
49 # Type of user action from event types list (string)
50 'eventType': 'account_registration',
51
52 # Type of HTTP request from list (string)
53 'httpMethod': 'POST',
54
55 # User created UTC timestamp ('Y-m-d H:i:s' string)
56 'userCreated': ''
57}
Send event
In the following code snippet, replace <Tracking ID> with
the corresponding tirreno tracking code value. It can be obtained
on the API page of the console.
1<?php
2
3// Set the API key for sending events
4$apiKey = '<Tracking ID>';
5
6// Replace each key value with actual info
7$data = array(
8
9 /////////// Required fields ///////////
10
11 // Unique value that allows identification of a user. Ex: alice54 (string)
12 'userName' => '',
13
14 // User email (string)
15 'emailAddress' => '',
16
17 // User IP address (string)
18 'ipAddress' => '',
19
20 // URL path of visited page (string)
21 'url' => '',
22
23 // User-agent of user request (string)
24 'userAgent' => '',
25
26 // Event UTC timestamp ('Y-m-d H:i:s.v' string)
27 'eventTime' => '',
28
29 /////////// Optional fields ///////////
30
31 // User first name (string)
32 'firstName' => '',
33
34 // User last name (string)
35 'lastName' => '',
36
37 // User full name (string)
38 'fullName' => '',
39
40 // Title of visited page (string)
41 'pageTitle' => '',
42
43 // User phone number (string)
44 'phoneNumber' => '',
45
46 // Referer of visited page (string)
47 'httpReferer' => '',
48
49 // Status code for page visit (string)
50 'httpCode' => '',
51
52 // User browser language (string)
53 'browserLanguage' => '',
54
55 // Type of user action from event types list (string)
56 'eventType' => '',
57
58 // Type of HTTP request from list (string)
59 'httpMethod' => '',
60
61 // User created UTC timestamp ('Y-m-d H:i:s' string)
62 'userCreated' => '',
63
64 // Payload, must have `page_search` or `account_email_change` event type (array)
65 'payload' => [],
66
67 // Field history, must have `field_edit` event type (array)
68 'fieldHistory' => [
69 [
70 'field_name' => '', // Name of the field
71 'field_id' => '', // ID of the field
72 'new_value' => '', // Field new value
73 'old_value' => '', // Field old value
74 'parent_id' => '' // ID of the field parent
75 ]
76 ],
77);
78
79// Convert the event data to a query string
80$dataString = http_build_query($data);
81
82// Set up apiKey
83$headers = [
84 'Api-Key: ' . $apiKey,
85 'Content-Type: application/x-www-form-urlencoded',
86];
87
88// Create a curl request to send the event data to the API
89
90$ch = curl_init();
91// CURLOPT_URL value is sensor URL
92curl_setopt_array($ch, array(
93 CURLOPT_URL => 'http://localhost/tirreno/sensor/',
94 CURLOPT_POST => true,
95 CURLOPT_POSTFIELDS => $dataString,
96 CURLOPT_RETURNTRANSFER => true,
97 CURLOPT_SSL_VERIFYPEER => false,
98 CURLOPT_TIMEOUT_MS => 1000,
99 CURLOPT_HTTPHEADER => $headers
100));
101
102// Send the curl request and capture the response
103$response = curl_exec($ch);
104
105// Close the curl request
106curl_close($ch);
1import requests
2from urllib.parse import urlencode
3
4
5url = '//localhost/tirreno/sensor/'
6headers = {
7 'Content-Type': 'application/x-www-form-urlencoded',
8 'Api-Key': '<Tracking ID>',
9}
10
11# Replace each key value with actual info
12data = {
13
14 ########### Required fields ###########
15
16 # Unique value that allows identification of a user. Ex: alice54 (string)
17 'userName': '',
18
19 # User email (string)
20 'emailAddress': '',
21
22 # User IP address (string)
23 'ipAddress': '',
24
25 # URL path of visited page (string)
26 'url': '',
27
28 # User-agent of user request (string)
29 'userAgent': '',
30
31 # Event UTC timestamp ('Y-m-d H:i:s.v' string)
32 'eventTime': '',
33
34 ########### Optional fields ###########
35
36 # User first name (string)
37 'firstName': '',
38
39 # User last name (string)
40 'lastName': '',
41
42 # User full name (string)
43 'fullName': '',
44
45 # Title of visited page (string)
46 'pageTitle': '',
47
48 # User phone number (string)
49 'phoneNumber': '',
50
51 # Referer of visited page (string)
52 'httpReferer': '',
53
54 # Status code for page visit (string)
55 'httpCode': '',
56
57 # User browser language (string)
58 'browserLanguage': '',
59
60 # Type of user action from event types list (string)
61 'eventType': '',
62
63 # Type of HTTP request from list (string)
64 'httpMethod': '',
65
66 # User created UTC timestamp ('Y-m-d H:i:s' string)
67 'userCreated': '',
68
69 # Payload, must have `page_search` or `account_email_change` event type (array)
70 'payload': [],
71
72 # Field history, must have `field_edit` event type (array)
73 'fieldHistory': [
74 {
75 'field_name': '', # Name of the field
76 'field_id': '', # ID of the field
77 'new_value': '', # Field new value
78 'old_value': '', # Field old value
79 'parent_id': '' # ID of the field parent
80 }
81 ]
82}
83
84data = {k: v for k, v in data if v is not None}
85response = requests.post(url, data=data, headers=headers)
This code snippet is intended to work starting Node.js version 10.0. Earlier versions require another approach.
1const axios = require('axios');
2const qs = require('qs'); // You might need to install 'qs'
3
4const url = '//localhost/tirreno/sensor';
5const headers = {
6 'Content-Type': 'application/x-www-form-urlencoded',
7 'Api-Key': '<Tracking ID>',
8};
9
10// Replace each key value with actual info
11const data = {
12
13 /////////// Required fields ///////////
14
15 // Unique value that allows identification of a user. Ex: alice54 (string)
16 userName: '',
17
18 // User email (string)
19 emailAddress: '',
20
21 // User IP address (string)
22 ipAddress: '',
23
24 // URL path of visited page (string)
25 url: '',
26
27 // User-agent of user request (string)
28 userAgent: '',
29
30 // Event UTC timestamp ('Y-m-d H:i:s.v' string)
31 eventTime: '',
32
33 /////////// Optional fields ///////////
34
35 // User first name (string)
36 firstName: '',
37
38 // User last name (string)
39 lastName: '',
40
41 // User full name (string)
42 fullName: '',
43
44 // Title of visited page (string)
45 pageTitle: '',
46
47 // User phone number (string)
48 phoneNumber: '',
49
50 // Referer of visited page (string)
51 httpReferer: '',
52
53 // Status code for page visit (string)
54 httpCode: '',
55
56 // User browser language (string)
57 browserLanguage: '',
58
59 // Type of user action from event types list (string)
60 eventType: '',
61
62 // Type of HTTP request from list (string)
63 httpMethod: '',
64
65 // User created UTC timestamp ('Y-m-d H:i:s' string)
66 userCreated: '',
67
68 // Payload, must have `page_search` or `account_email_change` event type (array)
69 payload: [],
70
71 // Field history, must have `field_edit` event type (array)
72 fieldHistory: [
73 {
74 field_name: '', // Name of the field
75 field_id: '', // ID of the field
76 new_value: '', // Field new value
77 old_value: '', // Field old value
78 parent_id: '' // ID of the field parent
79 }
80 ],
81};
82
83axios.post(url, qs.stringify(data), { headers: headers });
1require 'net/http'
2require 'uri'
3require 'cgi'
4
5url = URI.parse('//localhost/tirreno/sensor')
6headers = {
7 'Content-Type' => 'application/x-www-form-urlencoded',
8 'Api-Key' => '<Tracking ID>',
9}
10# Replace each key value with actual info
11data = {
12
13 ########### Required fields ###########
14
15 # Unique value that allows identification of a user. Ex: alice54 (string)
16 'userName': '',
17
18 # User email (string)
19 'emailAddress': '',
20
21 # User IP address (string)
22 'ipAddress': '',
23
24 # URL path of visited page (string)
25 'url': '',
26
27 # User-agent of user request (string)
28 'userAgent': '',
29
30 # Event UTC timestamp ('Y-m-d H:i:s.v' string)
31 'eventTime': '',
32
33 ########### Optional fields ###########
34
35 # User first name (string)
36 'firstName': '',
37
38 # User last name (string)
39 'lastName': '',
40
41 # User full name (string)
42 'fullName': '',
43
44 # Title of visited page (string)
45 'pageTitle': '',
46
47 # User phone number (string)
48 'phoneNumber': '',
49
50 # Referer of visited page (string)
51 'httpReferer': '',
52
53 # Status code for page visit (string)
54 'httpCode': '',
55
56 # User browser language (string)
57 'browserLanguage': '',
58
59 # Type of user action from event types list (string)
60 'eventType': '',
61
62 # Type of HTTP request from list (string)
63 'httpMethod': '',
64
65 # User created UTC timestamp ('Y-m-d H:i:s' string)
66 'userCreated': '',
67
68 # Payload, must have `page_search` or `account_email_change` event type (array)
69 'payload': [],
70
71 # Field history, must have `field_edit` event type (array)
72 'fieldHistory': [
73 {
74 'field_name': '', # Name of the field
75 'field_id': '', # ID of the field
76 'new_value': '', # Field new value
77 'old_value': '', # Field old value
78 'parent_id': '' # ID of the field parent
79 }
80 ]
81}
82
83http = Net::HTTP.new(url.host, url.port)
84http.use_ssl = true if url.scheme == 'https'
85request = Net::HTTP::Post.new(url, headers)
86request.body = URI.encode_www_form(data)
87response = http.request(request)
Blacklist API
After setting up your personalized rules engine
and manual or automated user blacklisting you can retrieve
information about user status by requesting /api/v1/blacklist/search
endpoint wherever your app needs to.