Analytics for the Apple SDK
Track user engagement and app performance with Airship analytics, including custom events, screen tracking, and associated identifiers.
Analytics allows you to track user engagement and app performance through custom events, screen tracking, and associated identifiers.
For information about controlling what data Airship collects, see Privacy Manager.
Analytics events are batched and uploaded asynchronously in the background to minimize battery impact. The database size is fixed, so events are safely stored even when offline. Events may not upload immediately and may wait until the next app initialization if the app is closed before the upload completes.
Custom Events
Track user activities and key conversions with Custom EventsEvents that indicate that a user performed a predefined action, such as adding an item to a shopping cart, viewing a screen, or clicking an Unsubscribe button. Custom Events can trigger automation, including Sequences and Scenes. You can code them into your app or website, or send them to Airship from an external source using the Custom Event API. Custom Events contain properties that you can use to personalize messages.. They require enabling analytics for your app.
Recording custom events
var event = CustomEvent(name: "event_name", value: 123.12)
try event.setProperties(
[
"my_custom_property": "some custom value",
"is_neat": true,
"any_json": [
"foo": "bar"
]
]
)
event.track()UACustomEvent *event = [[UACustomEvent alloc] initWithName:@"event_name" value:123.12];
[event setProperties: @{
@"my_custom_property": @"some custom value",
@"is_neat": @YES,
@"any_json": @{
@"foo": @"bar"
}
} error:&error];
[event track];Templates
Custom Event Templates are a wrapper for Custom Events and are available for iOS, Android, and Web. See also CustomEvent in the iOS SDK library.
Account
Use this template to create Custom Events for account-related events. The template is written with account registration as the example.
Account registered event
Track a registered account event:
let acctEvent = CustomEvent(accountTemplate: .registered)
acctEvent.track()With optional properties:
var acctEvent = CustomEvent(
accountTemplate: .registered,
properties: CustomEvent.AccountProperties(
category: "Premium",
isLTV: true
)
)
acctEvent.eventValue = 9.99
acctEvent.transactionID = "12345"
acctEvent.track()Media
Use this template to create Custom Events for media-related events, including consuming, browsing, starring, and sharing content.
Consumed content event
Track a consumed content event:
let mediaEvent = CustomEvent(mediaTemplate: .consumed)
mediaEvent.track()With an optional value:
var mediaEvent = CustomEvent(
mediaTemplate: .consumed,
properties: CustomEvent.MediaProperties(isLTV: true)
)
mediaEvent.eventValue = 1.99
mediaEvent.track()With optional properties:
var mediaEvent = CustomEvent(
mediaTemplate: .consumed,
properties: CustomEvent.MediaProperties(
id: "12322",
category: "entertainment",
type: "video",
eventDescription: "Watching latest entertainment news.",
author: "UA Enterprises",
isFeature: true,
isLTV: true
)
)
mediaEvent.eventValue = 2.99
mediaEvent.track()Starred content event
Track a starred content event:
let mediaEvent = CustomEvent(mediaTemplate: .starred)
mediaEvent.track()With optional properties:
var mediaEvent = CustomEvent(
mediaTemplate: .starred,
properties: CustomEvent.MediaProperties(
id: "12322",
category: "entertainment",
type: "video",
eventDescription: "Watching latest entertainment news.",
author: "UA Enterprises",
isFeature: true
)
)
mediaEvent.eventValue = 2.99
mediaEvent.track()Browsed content event
Track a browsed content event:
let mediaEvent = CustomEvent(mediaTemplate: .browsed)
mediaEvent.track()With optional properties:
let mediaEvent = CustomEvent(
mediaTemplate: .browsed,
properties: CustomEvent.MediaProperties(
id: "12322",
category: "entertainment",
type: "video",
eventDescription: "Browsed latest entertainment news.",
author: "UA Enterprises",
isFeature: true
)
)
mediaEvent.track()Shared content event
Track a shared content event:
let mediaEvent = CustomEvent(mediaTemplate: .shared)
mediaEvent.track()With a source and medium:
let mediaEvent = CustomEvent(
mediaTemplate: .shared(source: "facebook", medium: "social")
)
mediaEvent.track()With optional properties:
var mediaEvent = CustomEvent(
mediaTemplate: .shared(source: "facebook", medium: "social"),
properties: CustomEvent.MediaProperties(
id: "1234",
category: "entertainment",
type: "video",
eventDescription: "Watching latest entertainment news.",
author: "UA Enterprises",
isFeature: true
)
)
mediaEvent.track()Retail
Use this template to create Custom Events for retail-related events, including browsing a product, adding an item to a cart, purchasing an item, starring a product, and sharing a product.
Purchased event
Track a purchased event:
let retailEvent = CustomEvent(retailTemplate: .purchased)
retailEvent.track()With optional properties:
var retailEvent = CustomEvent(
retailTemplate: .purchased,
properties: CustomEvent.RetailProperties(
id: "1234",
category: "mens shoe",
eventDescription: "Low top",
isLTV: true,
brand: "SpecialBrand",
isNewItem: true
)
)
retailEvent.eventValue = 99.99
retailEvent.transactionID = "13579"
retailEvent.track()Browsed event
Track a browsed event:
let retailEvent = CustomEvent(retailTemplate: .browsed)
retailEvent.track()With optional properties:
var retailEvent = CustomEvent(
retailTemplate: .browsed,
properties: CustomEvent.RetailProperties(
id: "1234",
category: "mens shoe",
eventDescription: "Low top",
brand: "SpecialBrand",
isNewItem: true
)
)
retailEvent.eventValue = 99.99
retailEvent.transactionID = "13579"
retailEvent.track()Added-to-cart event
Track an added-to-cart event:
let retailEvent = CustomEvent(retailTemplate: .addedToCart)
retailEvent.track()With optional properties:
var retailEvent = CustomEvent(
retailTemplate: .addedToCart,
properties: CustomEvent.RetailProperties(
id: "1234",
category: "mens shoe",
eventDescription: "Low top",
brand: "SpecialBrand",
isNewItem: true
)
)
retailEvent.eventValue = 99.99
retailEvent.transactionID = "13579"
retailEvent.track()Starred product event
Track a starred product event:
let retailEvent = CustomEvent(retailTemplate: .starred)
retailEvent.track()With optional properties:
var retailEvent = CustomEvent(
retailTemplate: .starred,
properties: CustomEvent.RetailProperties(
id: "1234",
category: "mens shoe",
eventDescription: "Low top",
brand: "SpecialBrand",
isNewItem: true
)
)
retailEvent.eventValue = 99.99
retailEvent.transactionID = "13579"
retailEvent.track()Shared product event
Track a shared product event:
let retailEvent = CustomEvent(retailTemplate: .shared())
retailEvent.track()With a source and medium:
let retailEvent = CustomEvent(
retailTemplate: .shared(source: "facebook", medium: "social")
)
retailEvent.track()With optional properties:
var retailEvent = CustomEvent(
retailTemplate: .shared(source: "facebook", medium: "social"),
properties: CustomEvent.RetailProperties(
id: "1234",
category: "mens shoe",
eventDescription: "Low top",
brand: "SpecialBrand",
isNewItem: true
)
)
retailEvent.transactionID = "13579"
retailEvent.track()Associated Identifiers
Associated identifiers (also called custom identifiers) associate an external identifier with a Channel IDAn Airship-specific unique identifier used to address a channel instance, e.g., a smartphone, web browser, email address.. They are visible in Real-Time Data StreamingA service that delivers user-level events in real time to your backend or third-party systems using the Data Streaming API.. We recommend adding any IDs that you may want to be visible in your event stream. You can assign up to 20 associated identifiers to a device. Unlike other identifiers (e.g., tags), you cannot use associated identifiers to target your users.
Setting associated identifiers
let identifiers = Airship.analytics.currentAssociatedDeviceIdentifiers()
identifiers.set(identifier: "value", key:"key")
Airship.analytics.associateDeviceIdentifiers(identifiers)UAAssociatedIdentifiers *identifiers = [UAirship.analytics currentAssociatedDeviceIdentifiers];
[identifiers setIdentifier:@"value" forKey:@"key"];
[UAirship.analytics associateDeviceIdentifiers:identifiers];Screen Tracking
The Airship SDK gives you the ability to track which screens a user views within the application, how long a user stayed on each screen, and also includes the user’s previous screen. These events then come through Real-Time Data StreamingA service that delivers user-level events in real time to your backend or third-party systems using the Data Streaming API., allowing you to see the path a user took through the application, or trigger actions based on a user visiting a particular area of the application.
Track a screen
Airship.analytics.trackScreen("MainScreen")[UAirship.analytics trackScreen:@"MainScreen"];