Event tracking

Set Tracker Delegate


This method sets an object for Tracker module delegate methods.

Declared In:
Headers/SNRTracker.h

Related To:
TrackerDelegate

Class:
Tracker

Declaration:

static func setDelegate(_ delegate: TrackerDelegate)

Discussion:
Learn more about the methods and the purpose of this listener here.

Get customer’s events


This method retrieves events for an authenticated customer.

This method requires customer authentication.

Declared In:
Headers/SNRClient.h

Related To:
ClientEventsApiQuery

Class:
Client

Declaration:

static func getEvents(apiQuery: ClientEventsApiQuery, success: (([ClientEventData]) -> Void), failure: ((ApiError) -> Void)) -> Void

Parameters:

Parameter Type Mandatory Default Description
apiQuery ClientEventsApiQuery yes - Object responsible for storing all query parameters
success (([ClientEventData]) -> Void) yes - Closure/Block to be executed when the operation is completed successfully
failure ((ApiError) -> Void) yes - Closure/Block to be executed when the operation is completed with an error

Return Value:
No value is returned.

Set custom identifier for events


This method sets a custom identifier in the parameters of every event.

You can pass a custom identifier to match your customers in our database.

Declared In:
Headers/SNRTracker.h

Class:
Tracker

Declaration:

static func setCustomIdentifier(customIdentifier: String?) -> Void

Parameters:

Parameter Type Mandatory Default Description
customIdentifier String no - Customer’s custom identifier

Return Value:
No value is returned.

Set custom email for events


This method sets a custom email in the parameters of every event.

You can pass a custom email to match your customers in our database.

Declared In:
Headers/SNRTracker.h

Class:
Tracker

Declaration:

static func setCustomEmail(customEmail: String?) -> Void

Parameters:

Parameter Type Mandatory Default Description
customEmail String no - Customer’s custom email

Return Value:
No value is returned.

Send event


This method sends an event.

WARNING:

DO NOT send transaction.charge events as custom events.
Transactions must be tracked with these endpoints:

Note:
  • The tracker caches and enqueues all your events locally, so they all will be sent eventually.
  • The API key must have the API_BATCH_EVENTS_CREATE permission from the Events group.

Declared In:
Headers/SNRTracker.h

Related To:
Event
TrackerParams
TrackerParamsBuilder

Class:
Tracker

Declaration:

static func send(_: Event) -> Void

Parameters:

Parameter Type Mandatory Default Description
event Event yes - Event object

Return Value:
No value is returned.

Example: You may use standard objects in SDK, for example ProductAddedToCartEvent that represents a ‘customer added a product to cart’ event:

let event: ProductAddedToCartEvent = ProductAddedToCartEvent(label: "Product added!", sku: "12345", finalPrice: UnitPrice(amount: 100.0), quantity: 1)
event.setCategory("Smartphones")
event.setName("iPhone")
event.setProducer("Apple")
Tracker.send(event)

You can also pass additional parameters along with ProductAddedToCartEvent and other events, like in the example below:

let params: TrackerParams = TrackerParams.make { (builder) in
	builder.setString("12345", forKey: "snr_sku")
	builder.setInt(1, forKey: "snr_quantity")
	builder.setDouble(100.0, forKey: "snr_finalPrice")
}
let event: ProductAddedToCartEvent = ProductAddedToCartEvent(label: "Product added!", sku: "12345", finalPrice: UnitPrice(amount: 100.0), quantity: 1, params: params)
event.setCategory("Smartphones")
event.setName("iPhone")
event.setProducer("Apple")
Tracker.send(event)

If you want to track a fully customizable event, you should use CustomEvent:

let params: TrackerParams = TrackerParams.make { (builder) in
	builder.setString("12345", forKey:"key_string");
	builder.setInt(1, forKey:"key_integer");
	builder.setDouble(1.0, forKey:"key_double");
	builder.setFloat(1.0, forKey:"key_float");
	builder.setBool(true, forKey:"key_bool");
	builder.setObject(["key": "value"], forKey:"key_object");
}
let event: CustomEvent = CustomEvent(label: "custom event", action: "custom event action", params: params)
Tracker.send(event)

Flush events from Tracker


This method forces sending the events from the queue to the server.

Note: The API key must have the API_BATCH_EVENTS_CREATE permission from the Events group.

Declared In:
Headers/SNRTracker.h

Related To:
Event
TrackerParams
TrackerParamsBuilder

Class:
Tracker

Declaration:

static func flushEvents(completionHandler: (() -> Void)?) -> Void

Parameters:

Parameter Type Mandatory Default Description
completionHandler (() -> Void) no - Block/Closure to be executed when the tracker has finished flushing events to Synerise backend, no matter the result

Return Value:
No value is returned.

😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

Close modal icon Placeholder alt for modal to satisfy link checker