PHP code example of netesy / tracker

1. Go to this page and download the library: Download netesy/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/ */

    

netesy / tracker example snippets


$visitor = Tracker::currentSession();

var_dump( $visitor->client_ip );

var_dump( $visitor->device->is_mobile );

var_dump( $visitor->device->platform );

var_dump( $visitor->geoIp->city );

var_dump( $visitor->language->preference );


$sessions = Tracker::sessions(60 * 24); // get sessions (visits) from the past day

foreach ($sessions as $session)
{
    var_dump( $session->user->email );

    var_dump( $session->device->kind . ' - ' . $session->device->platform );

    var_dump( $session->agent->browser . ' - ' . $session->agent->browser_version );

    var_dump( $session->geoIp->country_name );

    foreach ($session->session->log as $log)
    {
    	var_dump( $log->path );
    }
}

$users = Tracker::onlineUsers(); // defaults to 3 minutes

$users = Tracker::users(60 * 24);

$users = Tracker::userDevices(60 * 24, $user->id);

$events = Tracker::events(60 * 24);

$errors = Tracker::errors(60 * 24);

$pageViews = Tracker::pageViews(60 * 24 * 30);

$pageViews = Tracker::pageViewsByCountry(60 * 24);

$range = new Minutes();

$range->setStart(Carbon::now()->subDays(2));

$range->setEnd(Carbon::now()->subDays(1));

Tracker::userDevices($range);

Route::get('user/{id}', ['as' => 'user.profile', 'use' => 'UsersController@profile']);

return Tracker::logByRouteName('user.profile')
        ->where(function($query)
        {
            $query
                ->where('parameter', 'id')
                ->where('value', 1);
        })
        ->count();

return Tracker::logByRouteName('tracker.stats.log')
        ->where(function($query)
        {
            $query
                ->where('parameter', 'uuid')
                ->where('value', '8b6faf82-00f1-4db9-88ad-32e58cfb4f9d');
        })
        ->select('tracker_log.session_id')
        ->groupBy('tracker_log.session_id')
        ->distinct()
        ->count('tracker_log.session_id');

Tracker::trackEvent(['event' => 'cart.add']);
Tracker::trackEvent(['event' => 'cart.add', 'object' => 'App\Cart\Events\Add']);

Tracker::trackVisit(
    [
        'name' => 'my.dynamic.route.name',
        'action' => 'MyDynamic@url'
    ],
    ['path' => 'my/dynamic/url']
);

 Netesy\Tracker\Vendor\Laravel\ServiceProvider::class,

'Tracker' => 'Netesy\Tracker\Vendor\Laravel\Facade',

'use_middleware' => true,

\Netesy\Tracker\Vendor\Laravel\Middlewares\Tracker::class,

'enabled' => true,

'connections' => [
    'mysql' => [
        ...
    ],
    
    'tracker' => [
    	'driver'   => '...',
    	'host'     => '...',
    	'database' => ...,
        'strict' => false,    // to avoid problems on some MySQL installs
    	...
    ],
],

'log_enabled' => true,

'authentication_ioc_binding' => ['auth', 'admin'],

'stats_panel_enabled' => true,

'stats_routes_middleware' => 'web',

public function getIsAdminAttribute()
{
    return true;
}

'connections' => [
    ...

    'tracker' => [
        ...

        'strict'    => false,
    ],
],