API Integration
Tirreno can be used by practically any digital system. The only requirement is to start sending user activity information (events data) to Tirreno for further processing.
Good news!
This also means enabling integration with Tirreno hardly costs any client platform resources.
This is done by sending an HTTP POST request with event details to the Tirreno’s API.
In general, event details consist of basic user information for building their identity profiles (such as email address, IP address, phone number, etc.) and request data (such as time of event, URL requested, user agent, etc.). For an applied illustration of the fields and values to send, go to the Event Data Example subsection.
The complete list of the mandatory and optional fields accepted by the API is given below, in the Integration Examples section. The section also gives practical examples of API integration scripts in different programming languages with a number of assisting instructions.
A similar set of the ready-made examples can be found on the API Key page of the account’s Console. These examples include an account-unique API key and sensor URL, which are requisites for each API communication. Observe that the API key must be sent in the header of a request.
To accomplish the integration, fill in the mandatory and selected optional fields in the integration script with the values obtainable in the client platform. Then add the script to the pages visited by identifiable (i.e., logged-in) users.
To verify that the API communication is established, proceed to 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 processing statuses 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 Code Examples 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.
Attention
If you need help with the API integration, contact us for support.
Integration Examples
The sensor accepts six mandatory and nine optional parameters. Each parameter is expected to be a string. The parameters must be passed as URL-encoded POST request data.
Note
It is highly recommended to pass as many parameters as possible. Sending more data results in more exhaustive reports and comprehensive 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 affirm requests processing statuses,
refer to the Logbook page.
Required Parameters
userName
A 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.
emailAddress
An email address associated with a user.
ipAddress
An IP address associated with an event. It can be retrieved from HTTP request headers.
url
userAgent
A user agent string value. It can be retrieved from the HTTP request’s User-Agent header.
eventTime
A timestamp of an event. It must be passed in the format
Y-m-d H:i:s
(for example, “2024-11-08 20:08:16”).
Attention
The maximum length of all request parameters is 100 characters, except the following: 2047 characters for url and httpReferer, 511 characters for userAgent, 255 for pageTitle and browserLanguage and 19 characters for phoneNumber.
Optional Parameters
firstName
A user’s first name.
lastName
A user’s last name.
fullName
A user’s whole name.
pageTitle
A title of a visited resource.
phoneNumber
A user’s phone number.
httpReferer
A value of the Referer HTTP header field.
httpCode
An HTTP response status code the request ended with.
browserLanguage
A detected language of the browser.
eventType
One of the event types listed below.
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_view
page_edit
page_delete
account_login
account_logout
account_login_fail
account_registration
account_email_change
account_password_change
account_edit
page_search
Event Data Example
This subsection demonstrates how to build an associative array with event details. The code snippet is written in Python programming language.
The full code examples of API requests for sending event data in different programmer languages (including Python) are presented in the Code Examples subsection.
1data = {
2 ########### Required fields ###########
3 # Unique value that allows identification of a user (string)
4 'userName': 'tirreno42',
5
6 # User email (string)
7 'emailAddress': '[email protected]',
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' string)
19 'eventTime': '2024-06-06 14:20:01',
20
21 ########### Optional fields ###########
22 # User first name (string)
23 'firstName': 'Tirreno',
24
25 # User last name (string)
26 'lastName': '',
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': '+33000000000',
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}
Code Examples
In the following code snippets, replace <Sensor URL>
and <Sensor
API key>
with the corresponding account-unique values. They can be
obtained on the API Key page of the console.
1<?php
2
3$url = '<Sensor URL>';
4$apiKey = '<Sensor API key>';
5
6// Replace each key value with actual info
7$data = array(
8 /////////// Required fields ///////////
9 // Unique value that allows identification of a user. Ex: alice54 (string)
10 'userName' => '',
11
12 // User email (string)
13 'emailAddress' => '',
14
15 // User IP address (string)
16 'ipAddress' => '',
17
18 // URL path of visited page (string)
19 'url' => '',
20
21 // User-agent of user request (string)
22 'userAgent' => '',
23
24 // Event UTC timestamp ('Y-m-d H:i:s' string)
25 'eventTime' => '',
26
27 /////////// Optional fields ///////////
28 // User first name (string)
29 'firstName' => '',
30
31 // User last name (string)
32 'lastName' => '',
33
34 // User full name (string)
35 'fullName' => '',
36
37 // Title of visited page (string)
38 'pageTitle' => '',
39
40 // User phone number (string)
41 'phoneNumber' => '',
42
43 // Referer of visited page (string)
44 'httpReferer' => '',
45
46 // Status code for page visit (string)
47 'httpCode' => '',
48
49 // User browser language (string)
50 'browserLanguage' => '',
51
52 // Type of user action from event types list (string)
53 'eventType' => '',
54);
55
56// Convert the event data to a query string
57$dataString = http_build_query($data);
58
59// Set up apiKey
60$headers = [
61 'Api-Key: ' . $apiKey,
62 'Content-Type: application/x-www-form-urlencoded',
63];
64
65// Create a curl request to send the event data to the API
66$ch = curl_init();
67curl_setopt_array($ch, array(
68 CURLOPT_URL => $url,
69 CURLOPT_POST => true,
70 CURLOPT_POSTFIELDS => $dataString,
71 CURLOPT_RETURNTRANSFER => true,
72 CURLOPT_SSL_VERIFYPEER => false,
73 CURLOPT_TIMEOUT_MS => 1000,
74 CURLOPT_HTTPHEADER => $headers
75));
76
77$response = curl_exec($ch);
78
79curl_close($ch);
1import requests
2from urllib.parse import urlencode
3
4url = '<Sensor URL>'
5key = '<Sensor API key>'
6
7headers = {
8 'Content-Type': 'application/x-www-form-urlencoded',
9 'Api-Key': key,
10}
11
12# Replace each key value with actual info
13data = {
14 ########### Required fields ###########
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' string)
31 'eventTime': '',
32
33 ########### Optional fields ###########
34 # User first name (string)
35 'firstName': '',
36
37 # User last name (string)
38 'lastName': '',
39
40 # User full name (string)
41 'fullName': '',
42
43 # Title of visited page (string)
44 'pageTitle': '',
45
46 # User phone number (string)
47 'phoneNumber': '',
48
49 # Referer of visited page (string)
50 'httpReferer': '',
51
52 # Status code for page visit (string)
53 'httpCode': '',
54
55 # User browser language (string)
56 'browserLanguage': '',
57
58 # Type of user action from event types list (string)
59 'eventType': '',
60}
61
62response = requests.post(url, data=urlencode(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 = '<Sensor URL>';
5const key = '<Sensor API key>';
6const headers = {
7 'Content-Type': 'application/x-www-form-urlencoded',
8 'Api-Key': key,
9};
10
11// Replace each key value with actual info
12const data = {
13 /////////// Required fields ///////////
14 // Unique value that allows identification of a user. Ex: alice54 (string)
15 userName: '',
16
17 // User email (string)
18 emailAddress: '',
19
20 // User IP address (string)
21 ipAddress: '',
22
23 // URL path of visited page (string)
24 url: '',
25
26 // User-agent of user request (string)
27 userAgent: '',
28
29 // Event UTC timestamp ('Y-m-d H:i:s' string)
30 eventTime: '',
31
32 /////////// Optional fields ///////////
33 // User first name (string)
34 firstName: '',
35
36 // User last name (string)
37 lastName: '',
38
39 // User full name (string)
40 fullName: '',
41
42 // Title of visited page (string)
43 pageTitle: '',
44
45 // User phone number (string)
46 phoneNumber: '',
47
48 // Referer of visited page (string)
49 httpReferer: '',
50
51 // Status code for page visit (string)
52 httpCode: '',
53
54 // User browser language (string)
55 browserLanguage: '',
56
57 // Type of user action from event types list (string)
58 eventType: '',
59};
60
61axios.post(url, qs.stringify(data), { headers: headers });
1require 'net/http'
2require 'uri'
3require 'cgi'
4
5url = URI.parse('<Sensor URL>')
6key = '<Sensor API key>'
7headers = {
8 'Content-Type' => 'application/x-www-form-urlencoded',
9 'Api-Key' => key,
10}
11# Replace each key value with actual info
12data = {
13 ########### Required fields ###########
14 # Unique value that allows identification of a user. Ex: alice54 (string)
15 'userName': '',
16
17 # User email (string)
18 'emailAddress': '',
19
20 # User IP address (string)
21 'ipAddress': '',
22
23 # URL path of visited page (string)
24 'url': '',
25
26 # User-agent of user request (string)
27 'userAgent': '',
28
29 # Event UTC timestamp ('Y-m-d H:i:s' string)
30 'eventTime': '',
31
32 ########### Optional fields ###########
33 # User first name (string)
34 'firstName': '',
35
36 # User last name (string)
37 'lastName': '',
38
39 # User full name (string)
40 'fullName': '',
41
42 # Title of visited page (string)
43 'pageTitle': '',
44
45 # User phone number (string)
46 'phoneNumber': '',
47
48 # Referer of visited page (string)
49 'httpReferer': '',
50
51 # Status code for page visit (string)
52 'httpCode': '',
53
54 # User browser language (string)
55 'browserLanguage': '',
56
57 # Type of user action from event types list (string)
58 'eventType': '',
59}
60
61http = Net::HTTP.new(url.host, url.port)
62http.use_ssl = true if url.scheme == 'https'
63request = Net::HTTP::Post.new(url, headers)
64request.body = URI.encode_www_form(data)
65response = http.request(request)