PHP code example of effectra / tracker

1. Go to this page and download the library: Download effectra/tracker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

effectra / tracker example snippets


use Effectra\Tracker\Tracker;
use Psr\Http\Message\ServerRequestInterface;

$request = ...; // Your PSR-7 ServerRequestInterface implementation
$tracker = new Tracker($request);

$ipAddress = $tracker->getIp();

$browser = $tracker->getBrowser();
// $browser['name'] contains the browser name
// $browser['version'] contains the browser version

$os = $tracker->getOs();
// $os['name'] contains the OS name
// $os['version'] contains the OS version

$deviceType = $tracker->getDevice();

$userAgent = $tracker->getUserAgent();

$acceptedLanguages = $tracker->getAcceptLangs();

$refererUrl = $tracker->getReferer();

$isPhone = $tracker->isPhone();

$clientInfo = $tracker->getAll();
// $clientInfo is an associative array containing all client information

use Effectra\Tracker\Services\IpGeoLocation;
use GuzzleHttp\Client;

$client = new Client(); // GuzzleHttp client instance
$ip = ...; // IP address to query
$apiKey = ...; // Your API key for ipgeolocation.io

$ipGeoLocation = new IpGeoLocation($client, $ip, $apiKey);
$ipAttributes = $ipGeoLocation->getAll();

use Effectra\Tracker\Services\IpRegistry;
use GuzzleHttp\Client;

$client = new Client(); // GuzzleHttp client instance
$ip = ...; // IP address to query
$apiKey = ...; // Your API key for ipregistry.co

$ipRegistry = new IpRegistry($client, $ip, $apiKey);
$ipAttributes = $ipRegistry->getAll();

use Effectra\Tracker\Services\IpWhoIs;
use GuzzleHttp\Client;

$client = new Client(); // GuzzleHttp client instance
$ip = ...; // IP address to query

$ipWhoIs = new IpWhoIs($client, $ip, null); // No API key