Event tracking

Set Custom Identifier for events


You can pass a custom identifier to match your customers in our CRM. The custom identifier is sent in the parameters of every event.

Declared In

SNRTracker.h

Method Name

Tracker.setCustomIdentifier(customIdentifier:)

Declaration

func setCustomIdentifier(customIdentifier: String) -> Void

Parameters

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

Return Value

There is no return value.

Set Custom Email for events


You can pass a custom email to match your customers in our CRM. The custom email is sent in the parameters of every event.

Declared In

SNRTracker.h

Method Name

Tracker.setCustomEmail(customEmail:)

Declaration

func setCustomEmail(customEmail: String) -> Void

Parameters

Parameter Type Mandatory Default Description
customEmail String yes - Client’s custom email

Return Value

There is no return value.

Send event


Use this method to send an event.

The tracker caches and enqueues all your events locally, so they all will be sent eventually.

Declared In

SNRTracker.h

  • SNRTrackerParams.h
  • SNRTrackerParamsBuilder
  • SNREvent.h
  • SNRCustomEvent.h

Method Name

Tracker.send(_: Event)

Declaration

func send(_: Event) -> Void

Parameters

Parameter Type Mandatory Default Description
event SNREvent yes - SNREvent object

Return Value

There is no return value.

Examples

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

let event: AddedProductToCartEvent = AddedProductToCartEvent(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 SNRAddedProductToCartEvent 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: AddedProductToCartEvent = AddedProductToCartEvent(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 SNRCustomEvent:

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


Forces sending the events from the queue to the server. This method is a global operation and does not require authorization.

Declared In

SNRTracker.h

Method Name

Tracker.flushEvents(completionHandler:)

Declaration

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

Parameters

Parameter Type Mandatory Default Description
completionHandler Block/Closure no - Block/closure to be executed when the operation finishes

Return Value

There is no return value.

😕

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.