Event tracking
Set Custom Identifier for events
Sets the custom identifier for the current customer.
The custom identifier will be sent with every event in event params.
Declared In
SNRTracker.h
Class Name
Method Name
setCustomIdentifier(customIdentifier:)
Declaration
static func setCustomIdentifier(customIdentifier: String?) -> Void
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
customIdentifier | String |
no | - | Customer’s custom identifier |
Return Value
There is no return value.
Set Custom Email for events
Sets the custom email for the current customer.
The custom email will be sent with every event in event params.
Declared In
SNRTracker.h
Class Name
Method Name
setCustomEmail(customEmail:)
Declaration
static func setCustomEmail(customEmail: String?) -> Void
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
customEmail | String |
no | - | Client’s custom email |
Return Value
There is no return value.
Send event
Adds a new event to the queue and sends available events to the server if possible.
Declared In
SNRTracker.h
Related To
Event
TrackerParams
TrackerParamsBuilder
Class Name
Method Name
send(_: Event)
Declaration
static func send(_: Event) -> Void
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
event | Event |
yes | - | Event object |
Return Value
There is no return value.
Examples
You may use standard objects in SDK, for example ProductAddedToCartEvent
that represents a ‘customer added 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
Sends events from the queue to the server by force.
Declared In
SNRTracker.h
Related To
Event
TrackerParams
TrackerParamsBuilder
Class Name
Method Name
flushEvents(completionHandler:)
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
There is no return value.