PHPackages                             eonvisualmedia/laravel-klaviyo - 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. eonvisualmedia/laravel-klaviyo

ActiveLibrary

eonvisualmedia/laravel-klaviyo
==============================

Interact with the Klaviyo API from your Laravel app

2.2.0(2mo ago)1212.7k↓19%5MITPHPPHP ^8.0CI passing

Since Apr 6Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/eonvisualmedia/laravel-klaviyo)[ Packagist](https://packagist.org/packages/eonvisualmedia/laravel-klaviyo)[ RSS](/packages/eonvisualmedia-laravel-klaviyo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (12)Versions (8)Used By (0)

laravel-klaviyo
===============

[](#laravel-klaviyo)

This package assists with interacting with [Klaviyo](https://www.klaviyo.com/) to track client and server-side metrics and the REST api.

Requirements
------------

[](#requirements)

For server-side track, identify or REST api calls this package utilises the Laravel HTTP Client.

It is recommended that server-side events are processed in the background, by default jobs are placed on the `klaviyo` queue.

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

[](#installation)

You can install the package via composer:

```
composer require eonvisualmedia/laravel-klaviyo
```

The package will automatically register itself.

You can optionally publish the config file with:

```
php artisan vendor:publish --provider="EonVisualMedia\LaravelKlaviyo\LaravelKlaviyoServiceProvider" --tag="tags-config"
```

Depending upon your intended usage minimally you'll need to configure your environment with your public and private api keys.

```
// .env

KLAVIYO_PRIVATE_API_KEY=
KLAVIYO_PUBLIC_API_KEY=

```

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

First you'll need to include the Klaviyo JavaScript API for Identification and Tracking by including it at the end of your layout just before the closing body tag.

```
// layout.blade.php

    {{-- ... --}}
    @include('klaviyo::initialize')

```

#### To add identity

[](#to-add-identity)

If the current user is not identified and `Auth::user()` is an instance of `EonVisualMedia\LaravelKlaviyo\Contracts\KlaviyoIdentity` then the `getKlaviyoIdentity` method will be called and an identify event added to the page.

Alternatively the identify method may be called explicitly, for instance after user login.

```
Klaviyo::identify([
    'email' => 'foo@example.com',
    'first_name' => 'Foo',
    'last_name' => 'Bar'
]);
```

#### Track events client-side

[](#track-events-client-side)

```
Klaviyo::push('track', 'Added to Cart', [
    '$value' => 100,
    'AddedTitle' => 'Widget A'
]);
```

#### Track events server-side:

[](#track-events-server-side)

To queue server-side events.

```
Klaviyo::track(TrackEvent::make(
    'Placed Order',
    [
        'unique_id' => '1234_WINNIEPOOH',
        'value' => 9.99,
    ]
));
```

You can optionally also specify the customer properties and timestamp, if not specified the customer will attempt to be identified by their cookie ($exchange\_id) or their user model if `Auth::user()`is an instance of `EonVisualMedia\LaravelKlaviyo\Contracts\KlaviyoIdentity`.

```
Klaviyo::track(TrackEvent::make(
    'Placed Order',
    [
         'unique_id' => '1234_WINNIEPOOH',
         'value' => 9.99,
    ],
    [
        'email' => 'foo@example.com',
        'first_name' => 'Foo',
        'last_name' => 'Bar',
    ],
    now()->addWeeks(-1)
));
```

### Monitoring Login Events

[](#monitoring-login-events)

By default, the package will subscribe to `Illuminate\Auth\Events\Login` events and dispatch an `klaviyo.identify(...)` call.

This behaviour can be disabled using the config option `identify_on_login`.

### Advanced usage

[](#advanced-usage)

#### Macros

[](#macros)

The package allows you to extend its functionality, this can be helpful for creating reusable events.

You may define macros within the `boot` method of a service provider, either your own or within the application's `App\Providers\AppServiceProvider` class.

```
use EonVisualMedia\LaravelKlaviyo\Klaviyo;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Klaviyo::macro(
        'fulfilled_order',
        function (Transaction $transaction) {
            Klaviyo::track(TrackEvent::make(
                'Fulfilled Order',
                $transaction->toKlaviyo(),
                $transaction->user,
                $transaction->created_at
            ));
        }
    );
}
```

With the macro defined you may invoke it anywhere in your application:

```
Klaviyo::fulfilled_order($transaction);
```

#### REST

[](#rest)

You may interact with the Klaviyo REST api using the Laravel HTTP Client, calls forwarded via KlaviyoClient append a `Authorization: Klaviyo-API-Key your-private-api-key` header to requests.

```
Klaviyo::get('lists');

Klaviyo::post("profile-subscription-bulk-create-jobs", [
    'data' => [
        'type'          => 'profile-subscription-bulk-create-job',
        'attributes'    => [
            'profiles' => [
                'data' => [
                    [
                        'type'       => 'profile',
                        'attributes' => [
                            'email'         => 'foo@example.com',
                            'subscriptions' => [
                                'email' => [
                                    'marketing' => [
                                        'consent' => 'SUBSCRIBED'
                                    ]
                                ],
                            ]
                        ]
                    ]
                ]
            ]
        ],
        'relationships' => [
            'list' => [
                'data' => [
                    'type' => 'list',
                    'id'   => $list_id
                ]
            ]
        ]
    ]
]);

Klaviyo::delete("profile-subscription-bulk-delete-jobs", [
    'data' => [
        'type'          => 'profile-subscription-bulk-delete-job',
        'attributes'    => [
            'profiles' => [
                'data' => [
                    [
                        'type'       => 'profile',
                        'attributes' => [
                            'email' => 'foo@example.com',
                        ]
                    ]
                ]
            ]
        ],
        'relationships' => [
            'list' => [
                'data' => [
                    'type' => 'list',
                    'id'   => $list_id
                ]
            ]
        ]
    ]
]);
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance88

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.3% 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 ~288 days

Recently: every ~299 days

Total

6

Last Release

60d ago

Major Versions

1.1.0 → 2.0.02024-06-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/70d66827f20129ee64232d3d860e996841c4bc3d3b8a80d34ea118f34b7177e0?d=identicon)[mnightingale](/maintainers/mnightingale)

---

Top Contributors

[![mnightingale](https://avatars.githubusercontent.com/u/9887246?v=4)](https://github.com/mnightingale "mnightingale (68 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (9 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/eonvisualmedia-laravel-klaviyo/health.svg)

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

###  Alternatives

[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[laravel/cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)[spatie/laravel-export

Create a static site bundle from a Laravel app

646127.9k5](/packages/spatie-laravel-export)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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