PHPackages                             bezhansalleh/filament-google-analytics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bezhansalleh/filament-google-analytics

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bezhansalleh/filament-google-analytics
======================================

Google Analytics integration for FilamentPHP

3.2.0(2mo ago)205144.8k—0.9%463MITPHPPHP ^8.3CI passing

Since Feb 28Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/bezhanSalleh/filament-google-analytics)[ Packagist](https://packagist.org/packages/bezhansalleh/filament-google-analytics)[ Docs](https://github.com/bezhansalleh/filament-google-analytics)[ GitHub Sponsors](https://github.com/bezhanSalleh)[ RSS](/packages/bezhansalleh-filament-google-analytics/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (40)Versions (27)Used By (3)

[![filament-google-analytics-art](https://repository-images.githubusercontent.com/461983658/983ab0b3-a97f-49ab-91a0-7bfd165217e1)](https://github.com/bezhansalleh/filament-google-analytics) [ ![FILAMENT 4.x](https://camo.githubusercontent.com/13befbe0cffd101b2484ce1cdd985dabcddcbf1176d17a675674d53af99cfdbc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46494c414d454e542d342e782d4542423330343f7374796c653d666f722d7468652d6261646765) ](https://filamentphp.com/docs/4.x/panels/installation) [ ![FILAMENT 5.x](https://camo.githubusercontent.com/3ec960aa304b803da9f1192f01e82da976a3d220ea85931fec930003e0532c77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46494c414d454e542d352e782d4542423330343f7374796c653d666f722d7468652d6261646765) ](https://filamentphp.com/docs/5.x/panels/installation) [ ![Packagist](https://camo.githubusercontent.com/3117f74b24f720698510e51025161cc4da8a417c1332a8d89695962ab7b9a4c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62657a68616e73616c6c65682f66696c616d656e742d676f6f676c652d616e616c79746963732e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374) ](https://packagist.org/packages/bezhansalleh/filament-google-analytics) [ ![Code Style Passing](https://camo.githubusercontent.com/4aac9b46fa7be4a9080d2c507138b6f7365740fa77263045f8e1244f147fe94b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62657a68616e73616c6c65682f66696c616d656e742d676f6f676c652d616e616c79746963732f6c61726176656c2d70696e742e796d6c3f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6162656c3d636f64652532307374796c65) ](https://github.com/bezhansalleh/filament-google-analytics/actions?query=workflow%3A)[ ![Downloads](https://camo.githubusercontent.com/b24e1de43e789e0a9012236f5b952e6cde1bb9e32efce94e77e8683d37eed9d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62657a68616e73616c6c65682f66696c616d656e742d676f6f676c652d616e616c79746963732e7376673f7374796c653d666f722d7468652d6261646765) ](https://packagist.org/packages/bezhansalleh/filament-google-analytics)

Google Analytics (GA4)
======================

[](#google-analytics-ga4)

Google Analytics integration for [Filament Panels](https://filamentphp.com) with a set of widgets to display your analytics data in a beautiful way.

#### Compatibility

[](#compatibility)

Package VersionFilament Version[1.x](https://github.com/bezhanSalleh/filament-google-analytics/tree/1.x)[2.x](https://filamentphp.com/docs/2.x/admin/installation)[2.x](https://github.com/bezhanSalleh/filament-google-analytics/tree/2.x)[3.x](https://filamentphp.com/docs/3.x/panels/installation)3.x[4.x](https://filamentphp.com/docs/4.x/introduction/overview) &amp; [5.x](https://filamentphp.com/docs/4.x/introduction/overview)Upgrading from v2 to v3
-----------------------

[](#upgrading-from-v2-to-v3)

If you are upgrading from version 2 to version 3, you will need to update the namespace anywhere you are using the plugin from `BezhanSalleh\FilamentGoogleAnalytics` to `BezhanSalleh\GoogleAnalytics`.

Installation
============

[](#installation)

You can install the package in to a Laravel app that uses [Filament](https://filamentphp.com) via composer:

```
composer require bezhansalleh/filament-google-analytics
```

For now, follow the directions on [Spatie's Laravel Google Analytics package](https://github.com/spatie/laravel-analytics) for getting your credentials, then put them here:

```
yourapp/storage/app/analytics/service-account-credentials.json

```

Also add this to the `.env` for your Filament PHP app:

```
ANALYTICS_PROPERTY_ID=
```

Important

If you have not set up a custom theme and are using Filament Panels follow the instructions in the [Filament Docs](https://filamentphp.com/docs/4.x/styling/overview#creating-a-custom-theme) first.

After setting up a custom theme add the following to your theme css file.

```
@source '../../../../vendor/bezhansalleh/filament-google-analytics/resources/views/**/*';
@source '../../../../vendor/bezhansalleh/filament-google-analytics/src/{Widgets,Support}/*';
```

```
public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            ...
            \BezhanSalleh\GoogleAnalytics\GoogleAnalyticsPlugin::make()
        ]);
}
```

Usage
=====

[](#usage)

All the widgets are enabled by default for you to use them in your filament pages/resources. In order to enable the widgets for the default filament dashboard, you need to set the `filament_dashboard` option to `true` in the config file `google-analytics.php` for each widget you want to enable.

Publish the config files and set your settings:

```
 php artisan vendor:publish --tag=google-analytics-config
```

#### Available Widgets

[](#available-widgets)

```
use BezhanSalleh\GoogleAnalytics\Widgets;

Widgets\PageViewsWidget::class,
Widgets\VisitorsWidget::class,
Widgets\ActiveUsersOneDayWidget::class,
Widgets\ActiveUsersSevenDayWidget::class,
Widgets\ActiveUsersTwentyEightDayWidget::class,
Widgets\SessionsWidget::class,
Widgets\SessionsByCountryWidget::class,
Widgets\SessionsDurationWidget::class,
Widgets\SessionsByDeviceWidget::class,
Widgets\MostVisitedPagesWidget::class,
Widgets\TopReferrersListWidget::class,
```

#### Custom Dashboard

[](#custom-dashboard)

Though this plugin comes with a default dashboard, but sometimes you might want to change `navigationLabel` or `navigationGroup` or disable some `widgets` or any other options and given that the dashboard is a simple filament `page`; The easiest solution would be to disable the default dashboard and create a new `page`:

```
php artisan filament:page MyCustomDashboardPage
```

then register the widgets you want from the **Available Widgets** list either in the `getHeaderWidgets()` or `getFooterWidgets()`:

```
