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

ActiveLibrary[API Development](/categories/api)

marshmallow/google-analytics
============================

Sending request to you Google Analytics has never been easier. With support for e-commerce tracking.

v1.1.2(5y ago)05.5k[1 PRs](https://github.com/marshmallow-packages/google-analytics/pulls)MITPHPPHP ^7.0|^8.0CI passing

Since Aug 7Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/marshmallow-packages/google-analytics)[ Packagist](https://packagist.org/packages/marshmallow/google-analytics)[ Docs](https://github.com/Marshmallow-Development/)[ RSS](/packages/marshmallow-google-analytics/feed)WikiDiscussions master Synced 3w ago

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

[![alt text](https://camo.githubusercontent.com/f5450f299f5713ce2f04dd5a1ba7ce9960ed4568b3574e4c4ee3cddc75477253/68747470733a2f2f6d617273686d616c6c6f772e6465762f63646e2f6d656469612f6c6f676f2d7265642d3233377834362e706e67 "marshmallow.")](https://camo.githubusercontent.com/f5450f299f5713ce2f04dd5a1ba7ce9960ed4568b3574e4c4ee3cddc75477253/68747470733a2f2f6d617273686d616c6c6f772e6465762f63646e2f6d656469612f6c6f676f2d7265642d3233377834362e706e67)

Laravel Google Analytics Package
================================

[](#laravel-google-analytics-package)

[![Version](https://camo.githubusercontent.com/786c38cdeafd980a59c513913283fbd3bb82a44c365db963c4b4316f69c9faee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617273686d616c6c6f772f676f6f676c652d616e616c7974696373)](https://github.com/marshmallow-packages/google-analytics)[![Issues](https://camo.githubusercontent.com/3ecd7827612ffc01f3ac115d0fed042c07c516b7e9ae0c7e9d607eff71533266/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6d617273686d616c6c6f772d7061636b616765732f676f6f676c652d616e616c7974696373)](https://github.com/marshmallow-packages/google-analytics)[![Licence](https://camo.githubusercontent.com/491ee4cecdd79a78e2c0424d641eed8a13529c8e51e76011647390a14ef76f33/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d617273686d616c6c6f772d7061636b616765732f676f6f676c652d616e616c7974696373)](https://github.com/marshmallow-packages/google-analytics)[![PHP Syntax Checker](https://github.com/marshmallow-packages/google-analytics/workflows/PHP%20Syntax%20Checker/badge.svg)](https://github.com/marshmallow-packages/google-analytics/workflows/PHP%20Syntax%20Checker/badge.svg)

Send request to you Google Analytics has never been easier.

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

[](#installation)

You can install the package via composer:

```
composer require marshmallow/google-analytics
```

Usage
-----

[](#usage)

Use with an event listener
--------------------------

[](#use-with-an-event-listener)

The easiest way to use this package is to use Events and Listners. For instance. If you want to use the ecommerce tracking your should create an event like `OrderCreated`. This event should implement `GoogleAnalyticsEvent`. This will require you to implement the `withAnalytics` method.

```
namespace App\Events;

use Marshmallow\GoogleAnalytics\GoogleAnalytics;
use Marshmallow\GoogleAnalytics\Contracts\GoogleAnalyticsEvent;

class OrderCreated implements GoogleAnalyticsEvent
{
    //...

    public function withAnalytics(GoogleAnalytics $analytics): GoogleAnalytics
    {
        //
    }
}
```

### The withAnalytics method

[](#the-withanalytics-method)

`withAnalytics` will provide you with an instance of `GoogleAnalytics` where you can add the `Google Types` you wish to send to Google Analytics. Below is an example of how this could look.

```
class OrderCreated implements GoogleAnalyticsEvent
{
    protected $order;

    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    public function withAnalytics(GoogleAnalytics $analytics): GoogleAnalytics
    {
        $ecommerce = (new EcommerceTracking)
                        ->id($this->order->id)
                        ->affiliation(env('APP_NAME'))
                        ->revenue($this->order->revenue())
                        ->shipping($this->order->shippingCost())
                        ->tax($this->order->tax())
                        ->currency('EUR');

        return $analytics->ecommerceTracking($ecommerce);
    }
}
```

### Register the Listener

[](#register-the-listener)

Add the `GoogleEcommerceTrigger` listner to your `EventServiceProvider.php`.

```
OrderCreated::class => [
    GoogleEcommerceTrigger::class
]
```

### Concatunate types

[](#concatunate-types)

You can add as many types as you want. To stay with the example above, lets say you want to let Google Analytics now which products where sold with this order.

```
class OrderCreated implements GoogleAnalyticsEvent
{
    protected $order;

    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    public function withAnalytics(GoogleAnalytics $analytics): GoogleAnalytics
    {
        $analytics->ecommerceTracking($ecommerce);

        foreach ($this->order->products as $product) {

            $hitItem = (new ItemHit)
                        ->id($this->order->id)
                        ->name($product->name())
                        ->price($product->price())
                        ->quantity($product->quantity())
                        ->code($product->sku())
                        ->variation($product->category->name)
                        ->currency('EUR');

            $analytics->itemHit($hitItem);
        }
    }
}
```

Google Event Types
------------------

[](#google-event-types)

Below you find an overview of the different Google Types we currently support and how you can use them.

### Event

[](#event)

```
$pageview = (new Pageview)
            ->hostname('marshmallow.dev')
            ->page('/home')
            ->title('homepage');

$analytics->pageview($pageview);
```

### Event

[](#event-1)

```
$event = (new Event)
            ->category('video')
            ->action('play')
            ->label('holiday')
            ->value(300);

$analytics->event($event);
```

### Ecommerce Tracking

[](#ecommerce-tracking)

```
$ecommerce = (new EcommerceTracking)
                ->id(123456)
                ->affiliation('westernWear')
                ->revenue(50.00)
                ->shipping(32.00)
                ->tax(12.00)
                ->currency('EUR');

$analytics->ecommerceTracking($ecommerce);
```

### Ecommerce item (Item Hit)

[](#ecommerce-item-item-hit)

```
$item1 = (new ItemHit)
                ->id(12345)
                ->name('sofa')
                ->price(300)
                ->quantity(2)
                ->code('u3eqds43')
                ->variation('furniture')
                ->currency('EUR');

$analytics->itemHit($item1);
```

Stand alone example
-------------------

[](#stand-alone-example)

If you don't want to use this with an event and listner, you can use it stand alone as well.

```
$pageview = (new Pageview)
            ->hostname('marshmallow.dev')
            ->page('/home')
            ->title('homepage');

(new GoogleAnalytics())
        ->version(1)
        ->trackingId(env('SEO_GA'))
        ->anonymousClientId()
        ->pageview($pageview)

        /**
         * Call the sendToGoogle method at the end
         */
        sendToGoogle();
```

Changelog
---------

[](#changelog)

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

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance45

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90.5% 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 ~81 days

Total

4

Last Release

1903d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.0.0

v1.1.2PHP ^7.0|^8.0

### Community

Maintainers

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

---

Top Contributors

[![stefvanesch](https://avatars.githubusercontent.com/u/46725619?v=4)](https://github.com/stefvanesch "stefvanesch (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

marshmallow

### Embed Badge

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

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

###  Alternatives

[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)[marshmallow/laravel-facebook-webhook

A package to retrieve Facebook Leads with webhooks &amp; Graph API in Laravel.

133.4k](/packages/marshmallow-laravel-facebook-webhook)

PHPackages © 2026

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