Skip to content

Latest commit

 

History

History
177 lines (111 loc) · 3.7 KB

analytics-methods-in-ios.md

File metadata and controls

177 lines (111 loc) · 3.7 KB

Analytics Methods in iOS

trackAction

Actions are the events that occur in your Android app that you want to measure. Each action has one or more corresponding metrics that are incremented each time the event occurs. For example, you might send a trackAction call for each new subscription, each time an article is viewed, or each time a level is completed.

You must call trackAction when an event that you want to track occurs. In addition to the action name, you can send additional context data with each track action call. This method sends an Analytics action tracking hit with optional context data.

Syntax

+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;

Example

Here are examples in Objective-C and Swift:

Objective-C

 [ACPCore trackAction:@"action name" data:@{@"key":@"value"}];

Swift

ACPCore.trackAction("action name", data: ["key": "value"])

trackState

States are the different screens or views in your application. Each time a new state is displayed in your application, for example, when a user navigates from the home page to the news feed, a trackState call should be sent. The tracking state name is typically called from a UIViewController in the viewDidLoad method. This method sends an Analytics state tracking hit with optional context data.

Tip: Calling this API will increment page views.

Syntax

+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;

Example

Here are examples in Objective-C and Swift:

Objective-C

 [ACPCore trackState:@"state name" data:@{@"key":@"value"}];

Swift

ACPCore.trackState("state name", data: ["key": "value"])

clearQueue

Clears all hits from the tracking queue and removes the hits from the database.

Warning: Use caution when clearing the queue manually because this process cannot be reversed.

Syntax

+ (void) clearQueue;

Example

Here are examples in Objective-C and Swift:

Objective-C

[ACPAnalytics clearQueue];

Swift

ACPAnalytics.clearQueue()

getQueueSize

Forces the library to send all queued hits regardless of the current batch options.

Syntax

Here are examples in Objective-C and Swift:

+ (void) getQueueSize: (nonnull void (^) (NSUInteger queueSize)) callback;

Example

Here are examples in Objective-C and Swift:

Objective-C

[ACPAnalytics getQueueSize: ^(NSUInteger queueSize) {
    // use queue size
}];

Swift

ACPAnalytics.getQueueSize({queueSize in
    // use queue size   
})

getTrackingIdentifier

Retrieves the analytics tracking identifier.

Syntax

+ (void) getTrackingIdentifier: (nonnull void (^) (NSString* __nullable trackingIdentifier)) callback;

Example

Here are examples in Objective-C and Swift:

Objective-C

[ACPAnalytics getTrackingIdentifier:^(NSString * _Nullable trackingIdentifier) {
    // use returned tracking id
    NSLog(@"Tracking ID : %@", trackingIdentifier);
}];

Swift

ACPAnalytics.getTrackingIdentifier({trackingIdentifier in
    // use returned tracking id
}

sendQueuedHits

Regardless of how many hits are currently queued, this method forces the library to send all hits in the offline queue.

Warning: Use caution when manually clearing the queue. This process cannot be reversed.

Syntax

+ (void) sendQueuedHits;

Example

Here are examples in Objective-C and Swift:

Objective-C

[ACPAnalytics sendQueuedHits];

Swift

ACPAnalytics.sendQueuedHits()