Skip to content

PHP client to send Klaviyo events with Reactive Programming paradigm

License

Notifications You must be signed in to change notification settings

Th3Mouk/reactive-klaviyo

Repository files navigation

Klaviyo HttpClient

This PHP library provide a simple way to send events to Klaviyo API. This implementation is based on an asynch HttpClient that use Reactive Programming paradigm.

Latest Stable Version Latest Unstable Version Total Downloads License

Build Status Scrutinizer Code Quality

Installation

composer require th3mouk/reactive-klaviyo

Basic usage

Create an instance of HttpClient

use Clue\React\Buzz\Browser as ClueBrowser;
use Rxnet\HttpClient\Browser as RxBrowser;

$clue = new ClueBrowser(EventLoop::getLoop());
$httpClient = new RxBrowser($clue);

Instantiate Klaviyo Client

$client = new Client('klaviyo-api-token', $httpClient);

Create a payload

According to Klaviyo documentation, the payload must be base64 encoded. This library use fluent setters to ease its creation and enforce typing with a Property class.

$payload = Payload::create('event-name')
    ->addCustomerProperty(Property::create('$email', '[email protected]'))
    ->addCustomerProperty(Property::create('$id', 'uuid-or-whatever'))
    ->addProperty(Property::create('lang', 'fr'))
    ->addProperty(Property::create('amount', 56))
    ->definePastEventDate(1559722012)
;

Send

Two methods are available, the same that in documentation.

$client->track(Payload $payload)
$client->trackOnce(Payload $payload)

Please

Feel free to improve this library.

About

PHP client to send Klaviyo events with Reactive Programming paradigm

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published