Analytics and Reporting

The Airship SDK provides analytics and reporting for your iOS apps.

Our iOS SDK ships with analytics support out of the box, and by default, there are no explicit preferences you need to set in order to enable reporting.

Analytics Events and Uploading

Our SDK stores events in a local database and uploads them periodically in a background thread. We’ve taken great care to make sure that the database won’t grow beyond a small fixed size, so extended periods of lost connectivity are nothing to worry about. The event upload thread is woken up when new events are triggered and goes to sleep when there are no more events to process, so the impact on battery life is negligible.

Custom Events

Custom events let you track user activities and key conversions in your application, and tie them back to corresponding push messaging campaigns. Custom events requires analytics to be enabled. If disabled, any event that is added to analytics will be ignored. For a more detailed explanation on custom events and possible use cases, see the Custom Events topic guide.

let event = CustomEvent(name: "event_name", value: 123.12)

// Set custom event properties
event.properties = [
    "boolean_property": true,
    "string_property": "string value",
    "number_property": 11
]

// Record the event in analytics
event.track()
UACustomEvent *event = [UACustomEvent eventWithName:@"event_name" value:@123.12];

// Set custom event properties
event.properties = @{
    @"boolean_property": @YES,
    @"string_property": @"string_value",
    @"number_property": @11
};

// Record the event in analytics
[event track];

Convenient templates are provided to create custom events for common account, media or retail related events. For more details see the Custom Event Templates topic guide.

Custom Identifiers

In addition to Named Users, tags, and Tag Groups, you can assign up to 20 custom identifiers to users. Identifiers that define additional ways of looking at a user – for example, iOS Vendor ID, iOS Advertising ID, Google Analytics CID, or any other identifier you deem significant – can be added to your users.

Setting identifiers
// Get the current identifiers
let identifiers = Airship.analytics.currentAssociatedDeviceIdentifiers()

// Add any custom identifier
identifiers.set(identifier: "customIdentifier", key:"customkey")

// Optionally include advertising ID
identifiers.advertisingID = ASIdentifierManager.sharedManager().advertisingIdentifier.UUIDString;
identifiers.advertisingTrackingEnabled = ASIdentifierManager.sharedManager().advertisingTrackingEnabled;
identifiers.vendorID = UIDevice.currentDevice.identifierForVendor?.uuidString

// Associate the identifiers
Airship.analytics.associateDeviceIdentifiers(identifiers)
// Get the current identifiers
UAAssociatedIdentifiers *identifiers = [UAirship.analytics currentAssociatedDeviceIdentifiers];

// Add any custom identifier
identifiers.setIdentifier("customIdentifier", forKey:"customkey")

// Optionally include advertising ID
identifiers.advertisingID = [[ASIdentifierManager sharedManager].advertisingIdentifier] UUIDString];
identifiers.advertisingTrackingEnabled = [ASIdentifierManager sharedManager].advertisingTrackingEnabled;
identifiers.vendorID = [[UIDevice currentDevice].identifierForVendor UUIDString];

// Associate the identifiers
[UAirship.analytics associateDeviceIdentifiers:identifiers];

Custom identifiers will be visible in Real-Time Data Streaming. We recommend adding any IDs that you may want to be visible in your event stream, even if Real-Time Data Streaming does not yet support the relevant integration. Unlike the other identifiers (e.g., tags), you cannot use custom identifiers to target your users.

Screen Tracking

The Airship SDK gives you the ability to track what screen a user views within the application, as well as how long the user stayed on that screen and the user’s previous screen. These events then come through Airship Real-Time Data Streaming and allow you to see the path that a user takes through an application, or to trigger actions based on a user visiting a particular area of the application.

Track/register a screen
Airship.analytics.trackScreen("MainScreen")
// Record the event
[UAirship.analytics trackScreen:@"MainScreen"];

When a new screen is tracked or when the application backgrounds, a screen tracking event will be generated. Normally, screen tracking should be called in a view controllers viewDidAppear: method, however it can be called anywhere in the application to start tracking a new screen event.

Disabling Analytics

 Warning

Features that depend on analytics being enabled may not work properly if it is disabled (reports, location segmentation, region triggers, push to local time).

If you do not wish to include analytics and reporting in your application, you can opt out by default by adding an enabledFeatures entry to your AirshpConfig.plist or Config and making sure it does not include analytics. Here is an example defaulting to just push and message center:

AirshipConfig.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  ...
  <key>enabledFeatures</key>
  <array/>
    <string>push</string>
    <string>messageCenter</string>
  </array>
  ...
</dict>
</plist>

To disable analytics at runtime, make the following call:

Disable analytics at runtime
Airship.shared.privacyManager.disableFeatures(.analytics);
[Airship.shared.privacyManager disableFeatures:UAFeaturesAnalytics]

When analytics is disabled at runtime it will delete any locally stored events and prevent any events from uploading.