PHPackages                             petercoles/laravel-google-analytics-tracking - 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. petercoles/laravel-google-analytics-tracking

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

petercoles/laravel-google-analytics-tracking
============================================

Inject your Google Analytics tracking ID into a Laravel project

1.0.1(9y ago)2532MITPHPPHP &gt;=5.6.0

Since Apr 19Pushed 9y ago1 watchersCompare

[ Source](https://github.com/petercoles/laravel-google-analytics-tracking)[ Packagist](https://packagist.org/packages/petercoles/laravel-google-analytics-tracking)[ Docs](https://github.com/petercoles/laravel-google-analytics-tracking)[ RSS](/packages/petercoles-laravel-google-analytics-tracking/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Google Analytics Tracking for Laravel
=====================================

[](#google-analytics-tracking-for-laravel)

Introduction
------------

[](#introduction)

Other Google Analytics packages for Laravel are designed to consume analytics data via the Google API and allow you to process it on your Laravel site. Not this one.

Instead this does the ridiculously straightforward task of extracting your Google Analytics tracking ID from your Laravel .env file and injecting it into the a Blade view intended for inclusion in your base layout.

The only wrinkle is that if you don't set the tracking ID in your .env file the Google script won't be included in your site. This is deliberate as it can be marginally useful for development and staging environments.

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

[](#installation)

Add the package to your project

```
composer require petercoles/laravel-google-analytics-tracking

```

Add the service provider to the providers list in your config/app.php file

```
'providers' => [
    // ...
    PeterColes\LaravelGoogleAnalyticsTracking\GoogleAnalyticsTrackingServiceProvider::class,
    // ...
],

```

Include the Blade view in your base layout

```
@include('google-analytics::script')

```

Traditionally this was placed near the closing body tag. However as the script is now loaded asynchronously, it can be added anywhere where a script tag is legitimate.

On your production server, set your tracking code in the .env file

```
GOOGLE_ANALYTICS_TRACKING_ID=UA-XXXXXXXX-X

```

License
-------

[](#license)

This package is licensed under the [MIT license](http://opensource.org/licenses/MIT).

Final Note
----------

[](#final-note)

If you've got this far, you're probably thinking "Couldn't I just cut and paste the Google script into my base layout?", to which the answer is "Absolutely!". I built this package only because I was doing this so often that it had begun to feel like a code smell and I wanted to [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) up this piece of my applications. I also wanted the additional benefit of separating the tracking ID from the script to reduce the risk of accidentally reusing another site's tracking ID.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

3351d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2947594?v=4)[Peter Coles](/maintainers/petercoles)[@petercoles](https://github.com/petercoles)

---

Top Contributors

[![petercoles](https://avatars.githubusercontent.com/u/2947594?v=4)](https://github.com/petercoles "petercoles (3 commits)")

---

Tags

laravelgoogle-analyticsTracking ID

### Embed Badge

![Health badge](/badges/petercoles-laravel-google-analytics-tracking/health.svg)

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

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17818.7k](/packages/markwalet-nova-modal-response)[firefly-iii/data-importer

Firefly III Data Import Tool.

8005.8k](/packages/firefly-iii-data-importer)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

98145.2k3](/packages/nickurt-laravel-akismet)[creasi/laravel-nusa

A Laravel package that aim to provide Indonesia' Administrative Data

997.7k2](/packages/creasi-laravel-nusa)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1319.7k3](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.2k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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