Coder Social home page Coder Social logo

bezhansalleh / filament-google-analytics Goto Github PK

View Code? Open in Web Editor NEW
162.0 6.0 28.0 318 KB

Google Analytics integration with Filamentphp (FilamentAdmin)

License: MIT License

PHP 77.29% Blade 19.75% JavaScript 2.89% CSS 0.07%
filamentadmin analytics google-analytics filament-analytics filamentphp laravel livewire

filament-google-analytics's Introduction

filament-google-analytics-art

FILAMENT 8.x Packagist Tests Passing Code Style Passing Downloads

Filament Google Analytics (GA4)

Google Analytics integration for Filament (FilamentAdmin)

Installation

You can install the package in to a Laravel app that uses Filament via composer:

composer require bezhansalleh/filament-google-analytics

For now, follow the directions on Spatie's Laravel Google Analytics package 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=

Usage

All the widgets are enabled by default in a dedicated Google Analytics Dashboard. You can enable or disable a specific widget or the dedicated dashboard all together or show and hide some from the main Filament Dashboard from the config filament-google-analytics.

Publish the config files and set your settings:

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

Available Widgets

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

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():

<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;
use BezhanSalleh\FilamentGoogleAnalytics\Widgets;

class MyCustomDashboardPage extends Page
{
    protected static ?string $navigationIcon = 'heroicon-o-document-text';

    protected static string $view = 'filament.pages.my-custom-dashboard-page';

    protected function getHeaderWidgets(): array
    {
        return [
            Widgets\PageViewsWidget::class,
            Widgets\VisitorsWidget::class,
            Widgets\ActiveUsersOneDayWidget::class,
            Widgets\ActiveUsersSevenDayWidget::class,
            Widgets\ActiveUsersTwentyEightDayWidget::class,
            Widgets\SessionsWidget::class,
            Widgets\SessionsDurationWidget::class,
            Widgets\SessionsByCountryWidget::class,
            Widgets\SessionsByDeviceWidget::class,
            Widgets\MostVisitedPagesWidget::class,
            Widgets\TopReferrersListWidget::class,
        ];
    }
}

Features

View the Visitors and Pageview Metrics

Screen Shot 2022-02-26 at 12 35 41 PM

View the Active Users Metrics

Screen Shot 2022-02-26 at 12 48 57 PM

View the Sessions and Avg. Session Duration Metrics

Screen Shot 2022-02-26 at 12 37 42 PM

View the Devices and Country Metrics by Session (WIP)

Screen Shot 2022-02-26 at 12 44 00 PM

View the lists of Most Visited Pages and Referrers

Screen Shot 2022-02-26 at 12 44 34 PM

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

If you want to contribute to this packages, you may want to test it in a real Filament project:

  • Fork this repository to your GitHub account.
  • Create a Filament app locally.
  • Clone your fork in your Filament app's root directory.
  • In the /filament-google-analytics directory, create a branch for your fix, e.g. fix/error-message.

Install the packages in your app's composer.json:

"require": {
    "bezhansalleh/filament-google-analytics": "dev-fix/error-message as main-dev",
},
"repositories": [
    {
        "type": "path",
        "url": "filament-google-analytics"
    }
]

Now, run composer update.

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-google-analytics's People

Contributors

bezhansalleh avatar dependabot[bot] avatar django23 avatar github-actions[bot] avatar macscr avatar mrfade avatar rafayrty avatar saifallak avatar timsinakiran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

filament-google-analytics's Issues

Cannot see analytics dashboard after installation

Hi,

I'm installing this package as per the explanation. I have the Laravel Spatie package installed and working.
Essentially I'm doing these two steps:

$ composer require bezhansalleh/filament-google-analytics
...
...
119 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].

No security vulnerability advisories found
Using version ^2.0 for bezhansalleh/filament-google-analytics

and

$ php artisan vendor:publish --tag=filament-google-analytics-config

   INFO  Publishing [filament-google-analytics-config] assets.

  Copying file [...\vendor\bezhansalleh\filament-google-analytics\config\filament-google-analytics.php] to [...\config\filament-google-analytics.php]  DONE

However I don't see the Google Analytics dashboard in Filament. I can see the benzhansalleh\filament-google-analytics folder under the vendor directory.

Anyone can help me to ensure I see the dashboad when logging into Filemant admin panel?

widgets are not displaying on a custom dashboard despite following the README.md instructions

Screenshot 2024-06-23 at 14 10 12

Dashboard.php

<?php

namespace App\Filament\Admin\Pages;

use Filament\Pages\Page;
use Illuminate\Contracts\Support\Htmlable;
use BezhanSalleh\FilamentGoogleAnalytics\Widgets;

class Dashboard extends Page
{
    protected static ?string $slug = 'dashboard';

    protected static string $view = 'filament.admin.pages.dashboard';

    protected function getHeaderWidgets(): array
    {
        return [
            Widgets\PageViewsWidget::class,
            Widgets\VisitorsWidget::class,
            Widgets\ActiveUsersOneDayWidget::class,
            Widgets\ActiveUsersSevenDayWidget::class,
            Widgets\ActiveUsersTwentyEightDayWidget::class,
            Widgets\SessionsWidget::class,
            Widgets\SessionsDurationWidget::class,
            Widgets\SessionsByCountryWidget::class,
            Widgets\SessionsByDeviceWidget::class,
            Widgets\MostVisitedPagesWidget::class,
            Widgets\TopReferrersListWidget::class,
        ];
    }
}

For some reason the widgets do not render anything

Filament 3. Installed package added json credential and published the config file and set the property id. Added the widgets to the filament dashboard page but there is absolutely nothing rendered on the page and no errors either. So not sure what is going on.
Inside the panel I try to use the widgets like so:
->widgets([ Widgets\AccountWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\PageViewsWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\VisitorsWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\ActiveUsersOneDayWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\ActiveUsersSevenDayWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\ActiveUsersTwentyEightDayWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\SessionsWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\SessionsDurationWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\SessionsByCountryWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\SessionsByDeviceWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\MostVisitedPagesWidget::class, \BezhanSalleh\FilamentGoogleAnalytics\Widgets\TopReferrersListWidget::class, // Widgets\FilamentInfoWidget::class, ])
But I get an empty page:

Screenshot 2024-04-26 at 3 40 30 PM

Permanent 7 in the Avg. Sessions Duration widget

Hello,

I'm currently facing a problem with the Avg. Sessions Duration widget, where it consistently shows a value of 7. I have tried reinstalling the package, but the problem is still there. I have tried this package in another project and its working fine.

Additionally the loading circle in the dropdown is always there, even in my other project.

image

Thank you for your time.

always getting Quota Error: User Rate Limit Exceeded

Google
 \ 
Service
 \ 
Exception
PHP 8.0.13
9.8.1
{ "error": { "code": 403, "message": "Quota Error: User Rate Limit Exceeded.", "errors": [ { "message": "Quota Error: User Rate Limit Exceeded.", "domain": "usageLimits", "reason": "userRateLimitExceeded" } ] } }

Undefined array key 1 - Traits/Visitors.php

Hello,
while implementing this future to my website I have spotted an error: Undefined array key 1
I did some debugging and found In Traits/Visitors.php

private function visitorsToday(): array
    {
        $analyticsData = Analytics::fetchTotalVisitorsAndPageViews(Period::days(1));

        return [
            'result' => $analyticsData[0]['activeUsers'],
            'previous' => $analyticsData[1]['activeUsers'],
        ];
    }

For small websites with minimal traffic, key $analyticsData[1] will not exists and this is rising a error.
Just wondering if creators have better idea than simple

'previous' => isset($analyticsData[1]) ? $analyticsData[1]['activeUsers'] : $analyticsData[0]['activeUsers'],

Question about default time display

Is there a way to override the defaults time values?

public ?string $filter = 'LTD';

Note I tried GitHub Q&A link which is more appropriate but I don't think the link works.

Fix for error with empty "Unique users" for today/yesterday on Filament v.2

I've same problem (#38) with your package on ver. 2.0.0, with Filament v.2, with about to empty GA data, on test environment. We're unable to use package without pass all tests on Test environment (b/c some time it's possible to have 0 as "today unique users" for example at 0:01AM for current day.

We're unable to update to Filament v.3 for some reasons.
Can u please add same fix for your package (2.0.0 ver) b/c 2.0.0 ver last supported version for Filament v.2, or add support for Filament v.2 to 2.0.1 package version if 2.0.1 works with Filament v.2.

vendor/bezhansalleh/filament-google-analytics/src/Traits/Visitors.php

Undefined array key 1 {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined array key 1 at .../vendor/laravel/framework/src/Illuminate/Collections/Collection.php:1781)

It's require to modify this function

private function visitorsToday(): array
    {
        $analyticsData = Analytics::fetchTotalVisitorsAndPageViews(Period::days(1));

        return [
            'result' => $analyticsData[0]['activeUsers'],
            'previous' => $analyticsData[1]['activeUsers'],
        ];
    }

and here too, to be sure that we are never get 500 if data empty...

    private function visitorsYesterday(): array
    {
        $analyticsData = Analytics::fetchTotalVisitorsAndPageViews(Period::create(Carbon::yesterday()->clone()->subDay(), Carbon::yesterday()));

        return [
            'result' => $analyticsData[0]['activeUsers'],
            'previous' => $analyticsData[1]['activeUsers'],
        ];
    }

Originally posted by @RChutchev in #38 (comment)

Does not support Google Analytics 4 (GA4)

This package relies on Spatie's Laravel Google Analytics package which does not support GA4 and has no plans to support it. Instead it supports the old Universal Analytics which will stop processing data on July 1, 2023:

https://support.google.com/analytics/answer/10089681?hl=en

I hope the creator of this package can update the description with this info so that people don't spent time installing and configuring something that will stop working soon.

Add ar translation

Hello,
How could I publish files to add ar translation please ?
Thanks

Installation error

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires bezhansalleh/filament-google-analytics ^1.0 -> satisfiable by bezhansalleh/filament-google-analytics[1.0.0].
- bezhansalleh/filament-google-analytics 1.0.0 requires illuminate/contracts ^9.0 -> found illuminate/contracts[v9.0.0-beta.1, ..., 9.x-dev] but these were not loaded, likely because it conflicts with another require.

gmp extension not recognized when using laravel octane

I am getting an error with gmp_sign function on production website. I managed to solve it locally on laravel sail by installing the gmp extension. However, installing the extension on the production server (tested it exists and work by php -m) did not help. I get the same error #54 . I restarted the octane server, nginx and even rebooted ubuntu still didn't help.

Tested the extension and it works

$number = '123456789';

if (extension_loaded('gmp')) {
    $result = gmp_sign($number);
    echo "Result: $result\n";
} else {
    echo "GMP extension is not loaded.\n";
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.