---
title: Analytics
slug: php-sdk/6iva-analytics
docTags: 
createdAt: 2024-05-13T16:02:18.453Z
---

Events can be sent to the analytics endpoint ([https://stats.ksearchnet.com/analytics/collect](https://stats.ksearchnet.com/analytics/collect)) in order to record analytics data for use in conversion tracking using the Analytics\CollectService.

Data is sent as a collection of Event objects (within an EventIterator).&#x20;
While multiple Events can be sent in a single request, each individual event must be associated with a single event action (such as order purchase), Klevu account, and user profile (eg, customer details).

:::hint{type="info"}
Note: only purchase events are currently available to send via the php-sdk
:::

Data contained within an event includes

| Field          | Description                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `event`        | The type of event / action to be tracked<br />Example: `"order_purchase"`                                                                                                                                                                                                                                                                                                                |
| `apikey`       | The JS API (public) key for the Klevu account receiving the data<br />Example: `"klevu-1234567890`                                                                                                                                                                                                                                                                                       |
| `version`      | Which version of the Event format the transmitted data adheres to. Where backwards-compatibility breaking changes (such as new mandatory fields) are introduced to this object, an incremented version will be available.<br />Example: `1.0.0`                                                                                                                                          |
| `user_profile` | Object containing identifying information about the visitor performing the tracked action. Includes<br />- `ipAddress`<br />- `email`<br />*Note: this informational is optional, but without it conversion information may not be attributed correctly.*<br />*Please ensure GDPR and other privacy concerns are accounted for before transmitting personally identifiable information* |
| `data`         | JSON object containing event data for recording. Content of this data will vary based on the `event` and/or `version` values of the object. <br />Example: *see below*                                                                                                                                                                                                                   |

### Event Data for Order Purchase

The data for events of type `order_purchase` is an object with a single `items` key. The `data.items` property comprises an array of objects for each line item, with the following information.

| Field             | Description                                                                                                                                                                                                                                              |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `order_id`        | String identifying the order to which this item belongs within the source system<br />Example: `"KLEVU12345"`                                                                                                                                            |
| `order_line_id`   | String identifying the order line item within the source system<br />Example: `"12345"`                                                                                                                                                                  |
| `item_name`       | The name of the product purchased                                                                                                                                                                                                                        |
| `item_id`         | Where a variant of a complex product has been purchased, this should be a combination of the group and variant ids; for simple products, use the product id<br />Examples: `"SKU_12345"`; `"PROD_42-VAR_001"`                                            |
| `item_group_id`   | String identifying the parent product within the source system, where the purchased item is a variant of a complex product.<br />Leave empty or use the variant id where purchased product is not configurable<br />Examples: `"SKU_12345"`; `"PROD_42"` |
| `item_variant_id` | String identifying the purchased product variant within the source system<br />Example: `"SKU_12345"`; `"VAR_001"`                                                                                                                                       |
| `unit_price`      | Decimal representation of the purchased price for the order line (ie, item price × quantity) without a currency code<br />Example: `3.14`                                                                                                                |
| `currency`        | Three character code for the currency in which the order was placed<br />Example: `"EUR"`                                                                                                                                                                |
| `units`           | Integer representation of the quantity purchased for this order line<br />Example: `42`                                                                                                                                                                  |

*For more information, please see the [Storefront APIs documentation](https://docs.klevu.com/apis/smart-search-analytics-events)*

:::hint{type="warning"}
Sending data to older productTracking endpoints (eg [https://stats.ksearchnet.com/analytics/productTracking](https://stats.ksearchnet.com/analytics/productTracking)) is not supported in the php-sdk
:::

### Validation and Exception Handling

- Prior to transmitting data, each individual event is validated; any invalid records will throw a `ValidationException` , preventing transmission of *all* events
  - Validation is performed on both the event properties, and the event data. Event data validation will differ depending on the event type and version.
- Request exceptions, or responses identifying an invalid request throw a`BadRequestException`
- Client or Network exceptions, responses with unexpected status codes, or responses with a missing or invalid body content throw a `BadResponseException`

### Logging

- Request headers and body are logged prior to send at `DEBUG` level
- Response headers, body, and execution time are logged on successful request send at `DEBUG` level

*More information and code samples can be found under&#x20;*[Examples / How To > Analytics > Send Analytics Events Data](docId\:rdq1zpjutlXhP4yH9xsWm)

