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.
composer require th3mouk/reactive-klaviyo
use Clue\React\Buzz\Browser as ClueBrowser;
use Rxnet\HttpClient\Browser as RxBrowser;
$clue = new ClueBrowser(EventLoop::getLoop());
$httpClient = new RxBrowser($clue);
$client = new Client('klaviyo-api-token', $httpClient);
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)
;
Two methods are available, the same that in documentation.
$client->track(Payload $payload)
$client->trackOnce(Payload $payload)
Feel free to improve this library.