Analytics/GettingStarted/TechnicalQuickStart
Quick Links
Technical Quick Start
1. Introduction
The Flurry iOS Analytics Agent allows you to track the usage and behavior of your iOS application
on users' devices for viewing in the Flurry Analytics system. It is designed to be as easy as possible
with a basic setup complete in under 5 minutes.
Please note that this SDK will only work with Xcode 3.2.5 or above. If you need an SDK for an older Xcode version please email us at support@flurry.com.
You will need to Download the Flurry iOS SDK to integrate Analytics into your app. The archive should contain these files for use with Flurry Analytics:
- ProjectApiKey.txt : This file contains the name of your project and your project's API key.
- Analytics-README.pdf : This file containing instructions on how to use Flurry Analytics.
- FlurryAnalytics/FlurryAnalytics.h : The required header file header file containing methods for Flurry Analytics.
- FlurryAnalytics/libFlurryAnalytics.a : The required library containing Flurry's collection and reporting code.
There are additional folders for use with Flurry Ads. This optional library provides alternate streams of revenue for your apps. For more information, please see Flurry Ads (Getting Started). Flurry Agent does not require CoreLocation framework and will not collect GPS location by default. Developers who use their own CLLocationManager can set GPS location information in the Flurry Agent (see the Optional Features section below for more information). We also recommend calling Flurry Analytics from the main thread. Flurry Analytics is not supported when called from other threads.
2. Integration
- In the finder, drag Flurry/ into project's file folder. (NOTE: If you are upgrading the Flurry iOS SDK, be sure to remove any existing Flurry library folders from your project's file folder before proceeding.)
- Now add it to your project: File > Add Files to "YOUR PROJECT"
- Add SystemConfiguration.framework to your app. This is required for Reachability to manage network operations efficiently.
- In your Application Delegate: Import Flurry and inside "applicationDidFinishLaunching:" add: [Flurry startSession:@"YOUR_API_KEY"];
#import "Flurry.h"
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[Flurry startSession:@"YOUR_API_KEY"];
//your code
}
#import "Flurry.h" - (void)applicationDidFinishLaunching:(UIApplication *)application { [Flurry startSession:@"YOUR_API_KEY"]; //your code }
You're done! That's all you need to do to begin receiving basic metric data. This includes all of the items in the Usage, Audience, and Technical sections of the Flurry portal.
3. Optional / Advanced Features
You can use the following methods to report additional data.
Tracking User Behavior
As mentioned in the prior section, you are able to track user activity in your application via custom Events.
[Flurry logEvent:@"EVENT_NAME"];
[Flurry logEvent:@"EVENT_NAME"];
Use logEvent to count the number of times certain Events happen during a session of your application. This can be useful for measuring how often users perform various actions, for example. Your application is currently limited to counting occurrences for 300 different Event ids (maximum length 255 characters).
[Flurry logEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary];
[Flurry logEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary];
Use this version of logEvent to count the number of times certain Events happen during a session of your application and to pass dynamic parameters to be recorded with that Event. Event parameters can be passed in as a NSDictionary object where the key and value objects must be NSString objects. For example, you could record that a user used your search box tool and also dynamically record which search terms the user entered. Your application is currently limited to counting occurrences for 300 different Event ids (maximum length 255 characters). A maximum of 10 Event parameters per Event is supported.
An example NSDictionary to use with this method could be:
NSDictionary *dictionary =
[NSDictionary dictionaryWithObjectsAndKeys:@"your dynamic parameter value",
@"your dynamic parameter name",
nil];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"your dynamic parameter value", @"your dynamic parameter name", nil];
[Flurry logEvent:@"EVENT_NAME" timed:YES];
[Flurry logEvent:@"EVENT_NAME" timed:YES];
Use this version of logEvent to time the duration of an Event.
[Flurry logEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary timed:YES];
[Flurry logEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary timed:YES];
Use this version of logEvent to start a timed Event with Event parameters.
[Flurry endTimedEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary];
[Flurry endTimedEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary];
Use endTimedEvent to end a timed Event before app exists, otherwise timed Events will automatically end when the app exits. When ending the timed Event, a new Event parameters NSDictionary object can be used to update Event parameters. To keep Event parameters the same, pass in nil for the Event parameters NSDictionary object.
To enable Flurry agent to automatically detect and log page view, pass in an instance of UINavigationController or UITabBarController to countPageViews. Flurry agent will create a delegate on your object to detect user interactions. Each detected user interaction will automatically be logged as a page view. Each instance needs to only be passed to Flurry agent once. Multiple UINavigationController or UITabBarController instances can be passed to Flurry agent.
[Flurry logPageView];
[Flurry logPageView];
In the absence of UINavigationController and UITabBarController, you can manually detect user interactions. For each user interaction you want to manually log, you can use logPageView to log the page view.
Tracking Application Errors
[Flurry logError:@"ERROR_NAME" message:@"ERROR_MESSAGE" exception:e];
[Flurry logError:@"ERROR_NAME" message:@"ERROR_MESSAGE" exception:e];
Use this to log exceptions and/or errors that occur in your app. Flurry will report the first 10 errors that occur in each session.
Tracking User ID and Demographics
[Flurry setUserID:@"USER_ID"];
[Flurry setUserID:@"USER_ID"];
Use this to log the user's assigned ID or username in your system after identifying the user. Note that per our Terms of Service, you are not allowed to pass along unique device identifiers such as UDID in this field.
[Flurry setAge:21];
[Flurry setAge:21];
Use this to log the user's age after identifying the user. Valid inputs are 0 or greater.
[Flurry setGender:@"m"];
[Flurry setGender:@"m"];
Use this to log the user's gender after identifying the user. Valid inputs are m (male) or f (female)
Tracking Location
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
CLLocationManager *locationManager = [[CLLocationManager alloc] init]; [locationManager startUpdatingLocation];
After starting the location manager, you can set the location with Flurry. You can implement CLLocationManagerDelegate to be aware of when the location is updated. Below is an example of how to use this method, after you have recieved a location update from the locationManager.
CLLocation *location = locationManager.location;
[Flurry setLatitude:location.coordinate.latitude
longitude:location.coordinate.longitude
horizontalAccuracy:location.horizontalAccuracy
verticalAccuracy:location.verticalAccuracy];
CLLocation *location = locationManager.location; [Flurry setLatitude:location.coordinate.latitude longitude:location.coordinate.longitude horizontalAccuracy:location.horizontalAccuracy verticalAccuracy:location.verticalAccuracy];
This allows you to set the current GPS location of the user. Flurry will keep only the last location information. If your app does not use location services in a meaningful way, using CLLocationManager can result in Apple rejecting the app submission.
Controlling Data Reporting
[Flurry setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose];
[Flurry setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose];
This option is on by default. When enabled, Flurry will attempt to send session data when the app is exited as well as it normally does when the app is started. This will improve the speed at which your application analytics are updated but can prolong the app termination process due to network latency. This option mostly applies for devices running < iOS 3.2 that do not enable multi-tasking.
[Flurry setSessionReportsOnPauseEnabled:(BOOL)sendSessionReportsOnPause];
[Flurry setSessionReportsOnPauseEnabled:(BOOL)sendSessionReportsOnPause];
This option is on by default. When enabled, Flurry will attempt to send session data when the app is paused as well as it normally does when the app is started. This will improve the speed at which your application analytics are updated but can prolong the app pause process due to network latency.
[Flurry setSecureTransportEnabled:(BOOL)secureTransport];
[Flurry setSecureTransportEnabled:(BOOL)secureTransport];
This option is off by default. When enabled, Flurry will send session data over SSL when the app is paused as well as it normally does when the app is started. This has the potential to prolong the app pause process due to added network latency from secure handshaking and encryption.
4. Recommendations
We recommend adding an uncaught exception listener to your application (if you don't already have one) and use logError to record any application crashes.
Adding an uncaught exception listener is easy; you just need to create a function that looks like the following:
void uncaughtExceptionHandler(NSException *exception) {
[Flurry logError:@"Uncaught" message:@"Crash!" exception:exception];
}
void uncaughtExceptionHandler(NSException *exception) { [Flurry logError:@"Uncaught" message:@"Crash!" exception:exception]; }
You then need to register this function as an uncaught exception listener as follows:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
[Flurry startSession:@"YOUR_API_KEY"];
....
}
- (void)applicationDidFinishLaunching:(UIApplication *)application { NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); [Flurry startSession:@"YOUR_API_KEY"]; .... }
Note that you can name the function whatever you'd like and record whatever error information you'd like in the error name and event field.
