th3mouk/reactive-klaviyo

PHP client to send Klaviyo events with Reactive Programming paradigm

1.1.0 2019-12-03 09:59 UTC

This package is auto-updated.

Last update: 2024-10-29 05:11:08 UTC


README

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', 'polo@klaviyo.com'))
    ->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.