th3mouk / reactive-klaviyo
PHP client to send Klaviyo events with Reactive Programming paradigm
1.1.0
2019-12-03 09:59 UTC
Requires
- php: ^7.3
- ext-json: *
- rxnet/http-client: ^0.2.0
Requires (Dev)
- kahlan/kahlan: ^4.6
- phpro/grumphp: ^0.15.2
- phpstan/phpstan: ^0.11.5
- youdot/coding-standard: ^1.1
This package is auto-updated.
Last update: 2024-11-29 05:21:26 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.
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.