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)
+ (void)setDelegate:(SNRTrackerDelegate *)delegate

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
+ (void)getEventsWithApiQuery:(nonnull SNRClientEventsApiQuery *)apiQuery success:(nonnull void (^)(NSArray<SNRClientEventData *> *events))success failure:(nonnull void (^)(NSError *error))failure

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
+ (void)setCustomIdentifier:(nullable NSString *)customIdentifier;

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
+ (void)setCustomEmail:(nullable NSString *)customEmail;

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.

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

  • 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
    
    + (void)send:(SNREvent *)event
    

    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)
    
    SNRProductAddedToCartEvent *event = [[SNRProductAddedToCartEvent alloc] initWithLabel:@"Product added!" sku:@"12345" finalPrice:[[SNRUnitPrice alloc] initWithAmount:100.0f] quantity:1];
    [event setCategory:@"Smartphones"];
    [event setName:@"iPhone"];
    [event setProducer:@"Apple"];
    [SNRTracker 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)
    
    SNRTrackerParams *params = [SNRTrackerParams makeWithBuilder:^(SNRTrackerParamsBuilder *builder) {
        [builder setString:@"12345" forKey:@"snr_sku"];
        [builder setInt:1 forKey:@"snr_quantity"];
        [builder setDouble:100.0f forKey:@"snr_finalPrice"];
    }];
    SNRProductAddedToCartEvent *event = [[SNRProductAddedToCartEvent alloc] initWithLabel:@"Product added!" sku:@"12345" finalPrice:[[SNRUnitPrice alloc] initWithAmount:100.0f] quantity:1 andParams:params];
    [event setCategory:@"Smartphones"];
    [event setName:@"iPhone"];
    [event setProducer:@"Apple"];
    [SNRTracker 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)
    
    SNRTrackerParams *params = [SNRTrackerParams makeWithBuilder:^(SNRTrackerParamsBuilder *builder) {
        [builder setString:@"string" forKey:@"key_string"];
        [builder setInt:1 forKey:@"key_integer"];
        [builder setDouble:1.0f forKey:@"key_double"];
        [builder setFloat:1.0f forKey:@"key_float"];
        [builder setBool:YES forKey:@"key_bool"];
        [builder setObject:@{ @"key" : @"value" } forKey:@"key_object"];
    }];
    SNRCustomEvent *event = [[SNRCustomEvent alloc] initWithLabel:"custom event" action:@"custom event action" andParams:params];
    [SNRTracker send:event];
    

    Flush events from Tracker


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

    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
    
    + (void)flushEventsWithCompletionHandler:(nullable void (^)(void))completion
    

    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.

    Canonical URL: https://hub.synerise.com/developers/mobile-sdk/method-reference/ios/tracking