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.

Integration Outline

To summarize, the steps to perform for accomplishing an API integration are as follows:

  1. 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.

  2. In the code snippet, insert account-unique and platform obtainable values.

  3. Add the prepared code to every client platform page that must be monitored.

  4. 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.

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

A URL path of a resource requested on a client platform.

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-10-03 17:05:08”).

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.

send-event.php
 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);