Download the PHP package eonvisualmedia/laravel-klaviyo without Composer
On this page you can find all versions of the php package eonvisualmedia/laravel-klaviyo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eonvisualmedia/laravel-klaviyo
More information about eonvisualmedia/laravel-klaviyo
Files in eonvisualmedia/laravel-klaviyo
Package laravel-klaviyo
Short Description Interact with the Klaviyo API from your Laravel app
License MIT
Informations about the package laravel-klaviyo
laravel-klaviyo
This package assists with interacting with Klaviyo to track client and server-side metrics and the REST api.
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
You can install the package via composer:
The package will automatically register itself.
You can optionally publish the config file with:
Depending upon your intended usage minimally you'll need to configure your environment with your public and private api keys.
Usage
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.
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.
Track events client-side
Track events server-side:
To queue server-side events.
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
.
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
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.
With the macro defined you may invoke it anywhere in your application:
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.
Upgrading from v1
The Klaviyo legacy v1/v2 APIs are scheduled to retire June 30th, 2024.
I would encourage you to review especially the breaking changes on the Klaviyo: API versioning and deprecation policy
The API changes have therefore necessitated a few breaking changes to this package, specifically the payloads required for identify
and push
.
See the examples below, for example the getKlaviyoIdentity
response replaces $email
with email
.
Also take note that client and server payloads for identify/profile have a few differences klaviyo_client_to_server_profile
may be of assistance help converting client payloads to server profiles.
All versions of laravel-klaviyo with dependencies
guzzlehttp/guzzle Version ^7.0
illuminate/bus Version ^8.0|^9.0|^10.0|^11.0
illuminate/http Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0