PHPackages                             mrugeshtatvasoft/laravel-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. [API Development](/categories/api)
4. /
5. mrugeshtatvasoft/laravel-analytics

ActiveLibrary[API Development](/categories/api)

mrugeshtatvasoft/laravel-analytics
==================================

GA4 integration for laravel

v2.0(2y ago)0225MITPHPPHP ^8.1

Since Jul 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mrugeshtatvasoft/laravel-analytics)[ Packagist](https://packagist.org/packages/mrugeshtatvasoft/laravel-analytics)[ Docs](https://github.com/mrugeshtatvasoft/laravel-analytics)[ RSS](/packages/mrugeshtatvasoft-laravel-analytics/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (8)Dependencies (14)Versions (9)Used By (0)

GA4 integration for laravel
===========================

[](#ga4-integration-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/22564786f68f43279611f4d87722db163dd6d0441d09455f429497ac959ba9c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d7275676573687461747661736f66742f6c61726176656c2d616e616c79746963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mrugeshtatvasoft/laravel-analytics)[![GitHub Tests Action Status](https://camo.githubusercontent.com/734417deb856874492ef966e3f24e55a98b992c0b3a405ee3228ff3c6047a186/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d7275676573687461747661736f66742f6c61726176656c2d616e616c79746963732f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/mrugeshtatvasoft/laravel-analytics/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/8afa46f496a1c5332120b836797fb7527d3715de3613df1017aa040d637d50df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d7275676573687461747661736f66742f6c61726176656c2d616e616c79746963732f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d636f64652532307374796c65)](https://github.com/mrugeshtatvasoft/laravel-analytics/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/bdd420f43253ab5946de787094c5ef45ff6fd60dceca577d25e3286633f4f86a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d7275676573687461747661736f66742f6c61726176656c2d616e616c79746963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mrugeshtatvasoft/laravel-analytics)

This package offers integration to GA4 properties with some out of the box methods. Inspired by [Spatie integration](https://github.com/spatie/laravel-analytics) for GA3. Requires Laravel 9+.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require mrugeshtatvasoft/laravel-analytics
```

You can publish the config file with:

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

This is the contents of the published config file:

```
return [
    'property_id' => env('ANALYTICS_PROPERTY_ID', 'XXXXXXXXX'),
    'service_account_credentials_json' => storage_path('app/analytics/service-account-credentials.json'),
    // This data is passed into the built-in cache mechanism for google's CredentialWrapper
    'cache' => [
        'enableCaching' => env('ANALYTICS_CACHE',false),
        'authCache' => null,
        'authCacheOptions' => [
            'lifetime' => env('ANALYTICS_CACHE_LIFETIME', 60), // you may want to set this higher
            'prefix' => env('ANALYTICS_CACHE_PREFIX', 'analytics_'),
        ]
    ]
];
```

Usage
-----

[](#usage)

Inside Laravel:

```
use mrugeshtatvasoft\LaravelAnalytics\Period;
use mrugeshtatvasoft\LaravelAnalytics\PrebuiltRunConfigurations;

$client = App::make('analytics-v4');
$lastMonth = Period::months(1);
$results = $client->runReport(PrebuiltRunConfigurations::getMostVisitedPages($lastMonth));
```

You may configure your own report configuration, or use a pre-built report:

```
// Use this on the laravel side to get it from the container
$analytics = App::make('analytics-v4');

// Prepare a filter
$filter = new StringFilter();
$filter->setDimension('country')->exactlyMatches('United States');

// Prepare a report
$reportConfig = (new RunReportConfiguration())
                ->setStartDate('2022-09-01')
                ->setEndDate('2022-09-30')
                ->addDimensions(['country', 'landingPage', 'date'])
                ->addMetric('sessions')
                ->addFilter($filter);

$analytics->convertResponseToArray()->runReport($reportConfig);
```

Yay, results:

```
  [
    "dimensions" => [
      "country" => "United States",
      "landingPage" => "/",
      "date" => "20220903",
    ],
    "metrics" => [
      "sessions" => "113",
    ],
  ],
  [
    "dimensions" => [
      "country" => "United States",
      "landingPage" => "/services/",
      "date" => "20220902",
    ],
    "metrics" => [
      "sessions" => "110",
    ],
  ],

```

Or Using Prebuilt Report Configurations:

```
$lastMonth = Period::months(1);
$analytics->runReport(PrebuiltRunConfigurations::getMostVisitedPages($lastMonth));
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

New Feature Includes
--------------------

[](#new-feature-includes)

Set Not expression

```
// Prepare a filter
$filter = new StringFilter();
$filter->setDimension('eventName')->exactlyMatches('Brand Viewer')->setNotExpression();
```

Run batch reports at a time

```
$array = [] // add all run report request
$this->batchReport($array);
```

Please note: You can run Max 5 request at a time

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Recently: every ~86 days

Total

8

Last Release

730d ago

Major Versions

v1.7 → v2.02024-06-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/393eb85871b607f2faf70252a35b0eb60117bcee6e76446f98bac32b0d44755e?d=identicon)[mktatva](/maintainers/mktatva)

---

Top Contributors

[![mrugeshtatvasoft](https://avatars.githubusercontent.com/u/50828994?v=4)](https://github.com/mrugeshtatvasoft "mrugeshtatvasoft (19 commits)")

---

Tags

laravelMrugeshTatvasoftanalytics-v4

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mrugeshtatvasoft-laravel-analytics/health.svg)

```
[![Health](https://phpackages.com/badges/mrugeshtatvasoft-laravel-analytics/health.svg)](https://phpackages.com/packages/mrugeshtatvasoft-laravel-analytics)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k9.9M90](/packages/dedoc-scramble)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M42](/packages/spatie-laravel-pdf)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[simplestats-io/laravel-client

Analytics for Laravel. Track visitors, registrations, and payments. Discover which channels actually drive revenue, not just traffic. Server-side, GDPR compliant, ad-blocker proof.

5019.3k](/packages/simplestats-io-laravel-client)[spatie/laravel-github-webhooks

Handle GitHub webhooks in a Laravel application

93157.3k5](/packages/spatie-laravel-github-webhooks)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
