Send Analytics Events Data
This guide assumes you have installed the latest version of klevu/php-sdk , either via composer or from source, and autoloading is functioning as expected.
Examples in this guide are for vanilla PHP and, as such, will use new to instantiate objects. If you are using a modern framework such as Magento or Symfony, you should utilise your object manager for dependency injection and preferencing of interfaces where possible.
To send analytics event data to Klevu, you will need your Klevu API key (see Quickstart for details). Note that, unlike other services, the analytics endpoint belongs to the Klevu Storefront API and, as such, does not require a private key (REST AUTH Key).
Next, extract the order and customer information to be sent from your application, including all applicable line items. As each system differs in storage and retrieval of data, the examples below simply contain hardcoded data.
Instantiate a new EventIterator object and populate with Event items. Note, while you can create these using new Event, it is recommended to use the EventFactory class for ease of development and future compatibility. Events can be added to the iterator's constructor, or after instantiation using addItem()
Finally, create an Analytics\CollectService object and call the send method with the Event collection, catching and handling any exception thrown during execution.
At this point, you will have an ApiResponseInterface which can be checked for success status, as well as any errors returned by the Klevu API.