Guide
Features

Analytics

5min

Events can be sent to the analytics endpoint (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). 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).

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

Example: "order_purchase"

apikey

The JS API (public) key for the Klevu account receiving the data

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.

Example: 1.0.0

user_profile

Object containing identifying information about the visitor performing the tracked action. Includes

  • ipAddress
  • email

Note: this informational is optional, but without it conversion information may not be attributed correctly. 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.

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

Example: "KLEVU12345"

order_line_id

String identifying the order line item within the source system

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

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.

Leave empty or use the variant id where purchased product is not configurable

Examples: "SKU_12345"; "PROD_42"

item_variant_id

String identifying the purchased product variant within the source system

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

Example: 3.14

currency

Three character code for the currency in which the order was placed

Example: "EUR"

units

Integer representation of the quantity purchased for this order line

Example: 42

For more information, please see the Storefront APIs documentation

Sending data to older productTracking endpoints (eg 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 aBadRequestException
  • 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 Examples / How To > Analytics > Send Analytics Events Data