PHPackages                             artisanpack-ui/analytics-google - 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. artisanpack-ui/analytics-google

ActiveLibrary

artisanpack-ui/analytics-google
===============================

Google Analytics (GA4) provider for the ArtisanPack UI analytics package, with server-side Data API reporting via the google base package.

1.1.0(3w ago)0164[4 issues](https://github.com/ArtisanPack-UI/analytics-google/issues)MITPHPPHP ^8.2CI passing

Since Jul 11Pushed 3w agoCompare

[ Source](https://github.com/ArtisanPack-UI/analytics-google)[ Packagist](https://packagist.org/packages/artisanpack-ui/analytics-google)[ RSS](/packages/artisanpack-ui-analytics-google/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (29)Versions (4)Used By (0)

ArtisanPack UI Analytics Google
===============================

[](#artisanpack-ui-analytics-google)

Google Analytics 4 (GA4) integration for Laravel applications.

The package ships **two independent surfaces** that you can adopt separately:

SurfaceWhat it doesRequires the `artisanpack-ui/google` base package?**Client-side tracking**Emits the standard `gtag.js` snippet on your pages.No**Server-side reporting**Queries the GA4 Data API for sessions, users, top pages, top events.Yes (for the OAuth token)If you only need tracking, install this package alone. If you need dashboards, add the base too. The package boots either way — the reporting classes gracefully throw a well-typed [`BaseNotInstalledException`](src/Exceptions/BaseNotInstalledException.php) when the base is missing, and reporting components render an "install the base" prompt instead of blowing up.

When installed alongside the [`artisanpack-ui/analytics`](https://github.com/ArtisanPack-UI/analytics) parent, this package registers itself as the `google-ga4` provider so client-side tracking runs through the parent's consent gate rather than firing unconditionally.

Install matrix
--------------

[](#install-matrix)

Pick the row that matches what you want to do:

Goal`artisanpack-ui/analytics-google``artisanpack-ui/google``artisanpack-ui/analytics`Livewire / React / VueEmit the gtag snippet from Blade✅———Emit the gtag snippet from React or Vue✅——React or VueRoute gtag through the analytics parent's consent gate✅—✅—Query the GA4 Data API from your own code✅✅——Render the GA overview component✅✅—Livewire, React, or VueRender the Top pages + top events component✅✅—Livewire, React, or VueDrop the two components into the CMS framework admin dashboard✅✅—`artisanpack-ui/cms-framework` + LivewireInstallation
------------

[](#installation)

```
composer require artisanpack-ui/analytics-google
```

For server-side reporting, also install the base package:

```
composer require artisanpack-ui/google
```

The service provider and `AnalyticsGoogle` facade are auto-discovered.

Publish the config:

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

Set the environment variables you need — measurement ID for tracking, property ID for reporting:

```
GA4_MEASUREMENT_ID=G-XXXXXXX
GA4_PROPERTY_ID=123456789
```

To forward the analytics parent's page views and events to GA4 from the server (since 1.1.0), add a Measurement Protocol API secret:

VariableDescription`GA4_API_SECRET`Measurement Protocol API secret (GA4 → Admin → Data Streams → Measurement Protocol API secrets). Forwarding stays off until this and `GA4_MEASUREMENT_ID` are both set.`GA4_SERVER_SIDE_TRACKING`Turns server-side forwarding off independently of the secret. Defaults to `true`.`GA4_PAGE_LOCATION_BASE`Base URL used to build the absolute `page_location` GA4 expects. Defaults to `app.url`.`GA4_MEASUREMENT_PROTOCOL_DEBUG`Sends hits to GA4's validation endpoint and logs the validation messages it returns. Defaults to `false`.Read [`docs/analytics-parent-integration.md`](docs/analytics-parent-integration.md) before enabling this — it covers the caveats around double-counting against client-side `gtag.js`, attribution, and session boundaries.

Client-side tracking
--------------------

[](#client-side-tracking)

### Blade

[](#blade)

Drop the `@ga4Snippet` directive into your layout ``:

```

    …
    @ga4Snippet

```

The directive emits nothing when `analytics-google.tracking.measurement_id` is empty, so it is safe to leave in a shared layout across environments.

### React

[](#react)

```
import { Ga4Snippet } from '@artisanpack-ui/analytics-google-js/react'

```

### Vue

[](#vue)

```

import { Ga4Snippet } from '@artisanpack-ui/analytics-google-js/vue'

```

By default the snippet defers `page_view` events until the analytics parent's consent banner grants the `analytics` category — configurable via `analytics-google.tracking.respect_consent`. When the parent is not installed, tracking fires immediately since there is no consent gate to defer to.

Server-side reporting
---------------------

[](#server-side-reporting)

Reporting requires the base package and a connected Google account for the current user. Under the hood the [`Ga4DataClient`](src/Reporting/Ga4DataClient.php) pulls an OAuth token from the base's `TokenManager` and POSTs against the GA4 Data API's `runReport` endpoint.

### Ga4DataClient — raw queries

[](#ga4dataclient--raw-queries)

```
use ArtisanPackUI\AnalyticsGoogle\Reporting\DateRange;
use ArtisanPackUI\AnalyticsGoogle\Reporting\Ga4DataClient;
use ArtisanPackUI\AnalyticsGoogle\Reporting\ReportRequest;

$client = app( Ga4DataClient::class );

$response = $client->runReport(
    ReportRequest::make(
        range: DateRange::lastDays( 30 ),
        metrics: [ 'sessions', 'totalUsers' ],
        dimensions: [ 'date' ],
    ),
    $googleConnection,
);

foreach ( $response->rows() as $row ) {
    echo $row['date'] . ': ' . $row['sessions'] . PHP_EOL;
}
```

### GA overview component

[](#ga-overview-component)

Four headline metrics — sessions, users, page views, average engagement time — plus a daily trend chart for a configurable date range.

**Livewire:**

```

```

**React and Vue** — publish the component sources, then point them at the built-in HTTP endpoint at `/analytics-google/overview`:

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

```
import { GaOverview } from './vendor/analytics-google/react'

```

```

import { GaOverview } from './vendor/analytics-google/vue'

```

### Top pages and events component

[](#top-pages-and-events-component)

Top pages (by views) and top events (by count) for a configurable date range.

**Livewire:**

```

```

**React and Vue** — the endpoint lives at `/analytics-google/top-content`:

```
import { GaTopContent } from './vendor/analytics-google/react'

```

```

import { GaTopContent } from './vendor/analytics-google/vue'

```

### CMS framework admin widgets

[](#cms-framework-admin-widgets)

When `artisanpack-ui/cms-framework` is installed, this package automatically registers both components as dashboard widgets:

- `analytics-google-overview` → the overview widget
- `analytics-google-top-content` → the top pages + events widget

Both are guarded behind the `view_analytics` capability. See the CMS framework's admin widgets documentation for how end users add them to their dashboard.

Configuration reference
-----------------------

[](#configuration-reference)

See [`config/analytics-google.php`](config/analytics-google.php). Highlights:

- `tracking.measurement_id` — GA4 measurement ID (`G-XXXXXXX`). Leave empty to disable the client-side snippet.
- `tracking.respect_consent` — whether to defer `page_view` until the analytics parent's consent gate grants the `analytics` category. Defaults to `true`.
- `tracking.api_secret` / `tracking.server_side` — Measurement Protocol API secret and the switch for server-side forwarding of the analytics parent's page views and events.
- `tracking.page_location_base` / `tracking.timeout` / `tracking.debug` — absolute-URL base, HTTP timeout, and validation-endpoint toggle for Measurement Protocol calls.
- `reporting.property_id` — GA4 numeric property ID for Data API queries.
- `reporting.cache_ttl` — how long (seconds) to cache Data API responses. Set to `0` to disable.
- `provider_name` — the name this package registers under with the `artisanpack-ui/analytics` parent. Defaults to `google-ga4`.
- `routes.enabled` / `routes.prefix` / `routes.middleware` — controls the HTTP endpoints that back the React and Vue components. Set `routes.enabled` to `false` for headless / API-only apps.

Graceful degradation
--------------------

[](#graceful-degradation)

The package is deliberately safe to install without the base:

- The service provider registers Blade directives, Livewire components, and the config regardless of whether the base is present.
- `Ga4DataClient::isAvailable()` returns `false` when the base is missing, so callers can hide reporting UI cleanly.
- Calling `Ga4DataClient::runReport()` without the base throws [`BaseNotInstalledException`](src/Exceptions/BaseNotInstalledException.php) rather than a class-not-found fatal.
- The Livewire and React/Vue reporting components render an "install the base" prompt instead of blowing up.
- The reporting HTTP endpoints return `501 base_not_installed` responses that the React/Vue components render via their error-code branch.

Contributing
------------

[](#contributing)

Please [read through the contributing guidelines](CONTRIBUTING.md) to learn more about how you can contribute to this project.

License
-------

[](#license)

ArtisanPack UI Analytics Google is open-source software licensed under the [MIT license](LICENSE).

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance95

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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 ~29 days

Total

2

Last Release

21d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ba2a2c40c9a93470595cd10701d2291434f3a7db61862d9700a9e69e31608c6c?d=identicon)[JacobMartellaWebDesign](/maintainers/JacobMartellaWebDesign)

---

Top Contributors

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

---

Tags

laravelgoogleanalyticsgoogle-analyticsga4artisanpack-ui

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/artisanpack-ui-analytics-google/health.svg)

```
[![Health](https://phpackages.com/badges/artisanpack-ui-analytics-google/health.svg)](https://phpackages.com/packages/artisanpack-ui-analytics-google)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.1k6.4M360](/packages/laravel-ai)[psalm/plugin-laravel

Psalm plugin for Laravel

3365.5M359](/packages/psalm-plugin-laravel)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React/Svelte) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

6036.2k](/packages/erag-laravel-lang-sync-inertia)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)[ublabs/blade-simple-icons

A package to easily make use of Simple Icons in your Laravel Blade views.

1868.9k](/packages/ublabs-blade-simple-icons)

PHPackages © 2026

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