PHP code example of inspyrenees / umami-bundle

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

    

inspyrenees / umami-bundle example snippets




return [
    // ...
    Inspyrenees\UmamiBundle\UmamiBundle::class => ['all' => true],
];



namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Inspyrenees\UmamiBundle\Client\UmamiClientInterface;

class AnalyticsController extends AbstractController
{
    public function __construct(
        private readonly UmamiClientInterface $umamiClient
    ) {}

    public function dashboard(): Response
    {
        // Get page metrics for the last 30 days (default)
        $metrics = $this->umamiClient->getPageMetrics();
        
        // Get overall stats
        $stats = $this->umamiClient->getStats();
        
        return $this->render('analytics/dashboard.html.twig', [
            'metrics' => $metrics,
            'stats' => $stats,
        ]);
    }
}

// Get metrics for the last 30 days (default)
$metrics = $this->umamiClient->getPageMetrics();

// Get metrics for the last 7 days
$metrics = $this->umamiClient->getPageMetrics(7);

// Get overall statistics
$stats = $this->umamiClient->getStats(30);

// Get referrer data
$referrers = $this->umamiClient->getReferrers(30);

// Get browser data
$browsers = $this->umamiClient->getBrowsers(30);

// Get operating system data
$os = $this->umamiClient->getOperatingSystems(30);

// Get device data
$devices = $this->umamiClient->getDevices(30);

// Get country data
$countries = $this->umamiClient->getCountries(30);

// Get event data
$events = $this->umamiClient->getEvents(30);

// Get daily page views for the last 30 days
$pageViews = $this->umamiClient->getPageViews('day', 'Europe/Paris', 30);

// Get hourly views for the last 7 days
$hourlyViews = $this->umamiClient->getPageViews('hour', 'UTC', 7);

// Get currently active users on your site
$activeUsers = $this->umamiClient->getActiveUsers();

// Available types: url, referrer, browser, os, device, country, event
$customMetrics = $this->umamiClient->getMetricsByType('url', 15);

$this->umamiClient->clearToken();