PHP code example of njoguamos / laravel-plausible

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

    

njoguamos / laravel-plausible example snippets


use NjoguAmos\Plausible\Facades\Plausible;

$visitors = Plausible::realtime();

use NjoguAmos\Plausible\Facades\Plausible;

$all = Plausible::aggregates();

use NjoguAmos\Plausible\Facades\Plausible;

// Simple with default
$aggregates = Plausible::aggregates();

// Or with optional custom parameters
$aggregates = Plausible::aggregates(
    period: 'custom',
    metrics: ['visitors', 'visits', 'pageviews'],
    filters: ['event:page==/blog**'],
    date: '2023-01-01,2023-01-31',
    withImported: true
);

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::aggregates(period: '7d')

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::aggregates(metrics: ['visitors', 'visits'])

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::aggregates(compare: false )

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::aggregates(filters: ['event:page==/blog**', 'visit:country==KE|DE'])

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::aggregates(period: 'custom', date: '2023-01-01,2023-01-31')

use NjoguAmos\Plausible\Facades\Plausible;

// Simple with default
$aggregates = Plausible::timeSeries();

// Or with optional custom parameters
$aggregates = Plausible::timeSeries(
        period: 'custom',
        metrics: ['visitors', 'visits', 'pageviews', 'views_per_visit', 'bounce_rate', 'visit_duration'],
        filters: ['event:page==/blog**'],
        interval: 'month',
        date: '2023-01-01,2023-01-31'
    );

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::timeSeries(period: '6mo')

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::timeSeries(metrics: ['visits', 'pageviews', 'views_per_visit'])

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::timeSeries(filters: ['event:page==/blog**', 'visit:browser==Firefox'])

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::timeSeries(interval: 'month')

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::timeSeries(period: 'custom', date: '2023-01-01,2023-01-31')

use \NjoguAmos\Plausible\Facades\Plausible;

// Simple with defaults
$visitors = Plausible::breakdown();

// With optional parameters
$aggregates = Plausible::breakdown(
        property: 'event:page',
        period: '12mo',
        metrics: ['visitors', 'visits', 'pageviews'],
        filters: 'event:page==/blog**',
        limit: 500
    );

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::breakdown(property: '6mo')

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::breakdown(period: '6mo')

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::breakdown(date: '2023-01-01')

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::breakdown(metrics: ['visits', 'pageviews', 'views_per_visit'])

use NjoguAmos\Plausible\Facades\Plausible;;

$aggregates = Plausible::breakdown(limit: 200)

use NjoguAmos\Plausible\Facades\Plausible;;

$aggregates = Plausible::breakdown(page: 2)

use NjoguAmos\Plausible\Facades\Plausible;

$aggregates = Plausible::breakdown(filters: 'event:page==/blog**')
bash
php artisan plausible:install
json
[
    {
        "bounce_rate": 17,
        "date": "2023-01-01",
        "pageviews": 60,
        "views_per_visit": 19,
        "visit_duration": 525,
        "visitors": 6,
        "visits": 6
    },
    {
        "bounce_rate": 12,
        "date": "2023-01-02",
        "pageviews": 22,
        "views_per_visit": 4,
        "visit_duration": 149,
        "visitors": 6,
        "visits": 8
    },
    {
        "bounce_rate": 57,
        "date": "2023-01-03",
        "pageviews": 9,
        "views_per_visit": 2.57,
        "visit_duration": 48,
        "visitors": 7,
        "visits": 7
    },
    {
        "bounce_rate": 71,
        "date": "2023-01-04",
        "pageviews": 48,
        "views_per_visit": 8.43,
        "visit_duration": 301,
        "visitors": 7,
        "visits": 7
    }
]
json
[
    {
        "bounce_rate": 71,
        "page": "/",
        "pageviews": 146,
        "visit_duration": 126,
        "visitors": 87,
        "visits": 77
    },
    {
        "bounce_rate": 54,
        "page": "/articles",
        "pageviews": 179,
        "visit_duration": 206,
        "visitors": 71,
        "visits": 50
    },
    {
        "bounce_rate": 81,
        "page": "/blog/about-laravel-plausible",
        "pageviews": 42,
        "visit_duration": 27,
        "visitors": 35,
        "visits": 37
    },
    {
        "bounce_rate": 52,
        "page": "/pricing",
        "pageviews": 72,
        "visit_duration": 147,
        "visitors": 31,
        "visits": 27
    },
    {
        "bounce_rate": 76,
        "page": "/aquatadas",
        "pageviews": 22,
        "visit_duration": 82,
        "visitors": 21,
        "visits": 21
    }
]