PHP code example of bencarr / craft-fathom-analytics

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

    

bencarr / craft-fathom-analytics example snippets




use craft\helpers\App;

return [
    '*' => [
        'apiKey' => App::env('FATHOM_API_KEY'),
        'siteId' => App::env('FATHOM_SITE_ID'),
    ],
];

use bencarr\fathom\events\RegisterWidgetRangesEvent;
use bencarr\fathom\FathomPlugin;
use craft\base\Event;

Event::on(
    FathomPlugin::class, 
    FathomPlugin::EVENT_DEFINE_WIDGET_RANGES, 
    function (RegisterWidgetRangesEvent $event) {
        unset($event->ranges['last_365_days'])
    }
);

use bencarr\fathom\events\RegisterWidgetRangesEvent;
use bencarr\fathom\helpers\WidgetDateRange;
use bencarr\fathom\FathomPlugin;
use craft\base\Event;
use craft\helpers\DateTimeHelper;

Event::on(
    FathomPlugin::class, 
    FathomPlugin::EVENT_DEFINE_WIDGET_RANGES, 
    function (RegisterWidgetRangesEvent $event) {
        $event->ranges['last_2_years'] = new WidgetDateRange(
            label: 'Last 2 Years',
            start: DateTimeHelper::tomorrow()->sub(new DateInterval('P2Y')),
            end: DateTimeHelper::tomorrow(),
        );
    }
);