PHPackages                             keithbrink/segment-spark - 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. keithbrink/segment-spark

ActiveLibrary[API Development](/categories/api)

keithbrink/segment-spark
========================

This package adds Segment tracking events to Laravel Spark, including eCommerce events.

v1.0.1(6y ago)64481MITPHP

Since Jan 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/keithbrink/segment-spark)[ Packagist](https://packagist.org/packages/keithbrink/segment-spark)[ RSS](/packages/keithbrink-segment-spark/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (1)Versions (21)Used By (0)

SegmentSpark
============

[](#segmentspark)

An automatic [Segment](https://segment.com/) analytics package for [Laravel Spark](https://spark.laravel.com/), which will track all page views and eCommerce events in Segment.

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

[](#installation)

This version requires [PHP](https://php.net) 7, and supports Laravel 5.5+ and Spark 5+.

To get the latest version, simply require the project using [Composer](https://getcomposer.org):

```
$ composer require keithbrink/segment-spark
```

On Laravel 5.5+, the `KeithBrink\SegmentSpark\SegmentSparkServiceProvider` service provider and `KeithBrink\SegmentSpark\SegmentSparkFacade` facade will be automatically discovered so it will not need to be added to your config. On previous versions, you will need to add those manually to your `config/app.php`.

Configuration
-------------

[](#configuration)

First, set your Segment write key in your .env file:

`MIX_SEGMENT_WRITE_KEY=xxx`

Prefixing the property with `MIX_` will allow the value to be accessed in Javascript.

Next, you'll need to publish the resources:

```
$ php artisan vendor:publish --provider="KeithBrink\SegmentSpark\SegmentSparkServiceProvider" --tag=resources
```

You can also optionally publish the `segment-spark.php` config file:

```
$ php artisan vendor:publish --provider="KeithBrink\SegmentSpark\SegmentSparkServiceProvider" --tag=config
```

The first publish command creates a `resources/js/segment-spark.js` file, which is a Vue plugin you will need to include in your `resources/js/app.js` file.

```
var SegmentSpark = require('./segment-spark.js');
Vue.use(SegmentSpark);

var app = new Vue({
    mixins: [require('spark')]
});
```

Remember that you will need to run `npm run dev` to compile your assets.

If you would like to associate server-side analytics requests with the client tracked by Google Analytics, you will need to add an exception for cookie encryption in the EncryptCookies middleware at `app\Http\Middleware\EncryptCookies.php`:

```
protected $except = [
    '_ga',
];
```

It's also a good idea to add [User-ID Tracking](https://segment.com/docs/destinations/google-analytics/#user-id) to Google Analytics.

Usage
-----

[](#usage)

After you have set your write key and added Vue plugin to app.js, the package will automatically track all of your page views (including the various tabs on the settings page) and will send events for eCommerce activity, such as viewing, subscribing, renewing, switching, or cancelling a plan.

Logged in users will be automatically tracked using their user ID (`$user->id`), and their entire user object will be included as traits.

If you are using Google Analytics, the server side events will automatically use the Google Analytics cookie to track events to correct user. Remember to set the server-side tracking ID in Segment's Google Analytics settings.

If you would like to track any custom events, you can use the original [Segment](https://github.com/segmentio/analytics-php) class.

```
Segment::track([
    "event"      => "XXX",
    "properties" => [
        "type" => "Video",
    ]
]);
```

Or, use the original Javascript Segment library.

```
analytics.track(event, [properties], [options], [callback]);
```

Google Analytics Enhanced eCommerce
-----------------------------------

[](#google-analytics-enhanced-ecommerce)

If you would like to use Google Analytics enhanced eCommerce, this package will automatically track two checkout steps: When the user clicks the Select button on one of the plans (Step 1), and when the user clicks the Subscribe button after filling out their billing information (Step 2). You can name those steps whatever you like in your Google Analytics enhanced eCommerce settings.

Remember that you will need to activate Google Analytics enhanced eCommerce on both Google Analytics and Segment.

License
-------

[](#license)

SegmentSpark is licensed under [The MIT License (MIT)](LICENSE).

Thanks To
---------

[](#thanks-to)

This library borrows code and design structure from [AltThree/Segment](https://github.com/AltThree/Segment) and [Ipunkt/LaravelAnalytics](https://github.com/ipunkt/laravel-analytics).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity72

Established project with proven stability

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

Recently: every ~152 days

Total

20

Last Release

2319d ago

Major Versions

v0.3.7 → v1.0.02020-01-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/787337724116dcbbddb7bb34a4bf3625e1ecbb2e0a7d80d045b5cdc52b2b37f1?d=identicon)[KeithBrink](/maintainers/KeithBrink)

---

Top Contributors

[![keithbrink](https://avatars.githubusercontent.com/u/15267205?v=4)](https://github.com/keithbrink "keithbrink (38 commits)")

### Embed Badge

![Health badge](/badges/keithbrink-segment-spark/health.svg)

```
[![Health](https://phpackages.com/badges/keithbrink-segment-spark/health.svg)](https://phpackages.com/packages/keithbrink-segment-spark)
```

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23414.2M16](/packages/hubspot-api-client)

PHPackages © 2026

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