PHP code example of rovereto / metrika

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

    

rovereto / metrika example snippets


   'connection' => 'metrika',
   

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

// Find first browser agent (any of these methods are valid and equivalent)
app('metrika.agent')->first();
new \Rovereto\Metrika\Models\Agent::first();
app(\Rovereto\Metrika\Models\Agent::class)->first();

   ...
   'service' => 'maxmind_database',
   ...
   'services' => [
   ...
        'maxmind_database' => [
            'class' => \Torann\GeoIP\Services\MaxMindDatabase::class,
            'database_path' => database_path('geoip/GeoLite2-City.mmdb'),
            'update_url' => sprintf('https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=%s&suffix=tar.gz', env('MAXMIND_LICENSE_KEY')),
            'locales' => ['en'],
        ],
   ...
   

   ...
   'service' => 'ip2location_database',
   ...
   'services' => [
   ...
        'ip2location_database' => [
            'class' => \Rovereto\Metrika\Services\Ip2Location::class,
            'database_path' => database_path('ip2location/IP2LOCATION.BIN'),
        ],
   ...
   

   ...
   'use_proxy' => true,
   ...
   'proxy_path' => database_path('ip2location/IP2PROXY.BIN'),
   ...
   

   ...
   'store_cookie' => true,
   ...
   'cookie_name' => 'my_name_cookie_for_metrika',
   ...
   

   ...
   'domain' => env('SESSION_DOMAIN', '.my-domain.com'),
   ...
   

   ...
   protected $except = [
   ...
       'my_name_cookie_for_metrika'
   ...  
   ];
   ...
   

use Rovereto\Metrika\Support\Facades\Metrika;

use Metrika;

use Rovereto\Metrika\Support\Facades\Metrika;

Metrika::getTopPageViewsForPeriod(DateTime $startDate, DateTime $endDate, int $limit = 10, bool $with_robots = false);
//example Most viewed pages for period 01.01.2020 - 31.12.2020 limit 100 pages without robots
Metrika::getTopPageViewsForPeriod(Carbon::parse('01.01.2020'), Carbon::parse('31.12.2020'), 100);

use Rovereto\Metrika\Support\Facades\Metrika;

Metrika::getHitsForPeriodLine(DateTime $startDate, DateTime $endDate, string $group = 'day', bool $with_robots = false);
//example Hits for period 01.01.2020 - 31.12.2020 by month without robots
Metrika::getHitsForPeriodLine(Carbon::parse('01.01.2020'), Carbon::parse('31.12.2020'), 'month');

Metrika::getSourcesForPeriodPie(DateTime $startDate, DateTime $endDate, bool $with_robots = false);

Metrika::getSearchEngineForPeriodPie(DateTime $startDate, DateTime $endDate, bool $with_robots = false);

Metrika::getBrowsersForPeriodPie(DateTime $startDate, DateTime $endDate, bool $with_robots = false);

Metrika::getOsForPeriodPie(DateTime $startDate, DateTime $endDate, bool $with_robots = false);

Metrika::getDevicesForPeriodPie(DateTime $startDate, DateTime $endDate, bool $with_robots = false);

Metrika::getCountryForPeriodPie(DateTime $startDate, DateTime $endDate, bool $with_robots = false);

$pageViews = app('metrika.path')->where('path', request()->decodedPath())->first()->count;
shell
    php artisan vendor:publish --provider="Rovereto\Metrika\Providers\MetrikaServiceProvider"
    
shell
    php artisan migrate
    

    php artisan vendor:publish --provider="Rovereto\Metrika\Providers\MetrikaServiceProvider"
    
shell
   php artisan vendor:publish --provider="Torann\GeoIP\GeoIPServiceProvider" --tag=config