Giter Site home page Giter Site logo

laravel-klaviyo's Introduction

laravel-klaviyo

A library for interacting with the Klaviyo API in Laravel.

This library is in early release and is pending unit tests.

Installation

composer require balfour/laravel-klaviyo

Configuration

The package makes use of the following env vars:

  • KLAVIYO_ENABLED [default = false]
  • KLAVIYO_API_KEY [default = null]
  • KLAVIYO_QUEUE [default = klaviyo]

If you would like to publish the config, you can do so using:

php artisan vendor:publish --provider="Balfour\LaravelKlaviyo\ServiceProvider"

If you plan to process events and identities on a queue, you'll need to make sure you have a queue worker running and handling the KLAVIYO_QUEUE jobs.

Usage

use App\Models\User;
use Balfour\LaravelKlaviyo\Event;
use Balfour\LaravelKlaviyo\Jobs\PushIdentity;
use Balfour\LaravelKlaviyo\Jobs\TrackEvent;
use Balfour\LaravelKlaviyo\Klaviyo;

$klaviyo = app(Klaviyo::class);

// pushing an identity
// in a real world, this may be a `user` model implementing the `IdentityInterface`
$user = User::find(1);
$klaviyo->pushIdentity($user);

// pushing an identity (using a queue)
$user = User::find(1);
PushIdentity::enqueue($user);

// tracking an event
$user = User::find(1);
$event = new Event(
    'Complete Checkout Step 2',
    [
        'product' => 'Chicken Soup',
        'price' => 'R100.00',
    ]
);
$event->fire($user);
// or
$klaviyo->trackEvent($user, $event);

// tracking an event (using a queue)
$event->enqueue($user);
// or
TrackEvent::enqueue($user, $event);

// in the case that you don't have an identity object, but just an email identifier
$event = new Event('Subscribed To Mailing List');
$event->fire('[email protected]');

// create a mailing list
$klaviyo->createMailingList('My List Name');

// add email to mailing list
$klaviyo->addToMailingList('12345', '[email protected]');

// remove email from mailing list
$klaviyo->removeFromMailingList('12345', '[email protected]');

laravel-klaviyo's People

Contributors

matthewgoslett avatar nicja avatar gcobani avatar

Stargazers

Martin Alexander avatar Augustus avatar François Lévesque avatar trungpv avatar Morten Bak avatar Mantontolwane Katulo Hlabisa avatar Jack Wire avatar John Gillespie avatar

Watchers

James Cloos avatar  avatar Stuart O'Brien avatar  avatar  avatar Gert avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.