Code Monkey home page Code Monkey logo

mmtrackingcontroller's Introduction

Shared Tracking Controller

This is the MMTrackingController code which can be used to easily manage multiple iOS analytics packages. Included in this code are configurations for Flurry and Google Analytics. It should be easy to adapt this to most new analytics APIs.

Usage

Include the three files MMTrackingController.h, MMTrackingController.m, and MMTrackingControllerDefs.h to your project. Modify MMTrackingControllerDefs.h to reference your application key, account ID, etc. as needed. Comment out the services you don't want to use. Add the libs & headers for the individual services as needed.

MMTrackingController is a singleton instance. You invoke all methods by first calling +[MMTrackingController sharedTrackingController].

In your application delegate you must do at least the following:

#import "MMTrackingController.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	[[MMTrackingController sharedTrackingController] startTracking];
}

- (void)applicationWillTerminate:(UIApplication*)application {
	[[MMTrackingController sharedTrackingController] stopTracking];
}

If your application supports multitasking on iOS 4.x, you should also add the following calls:

- (void)applicationWillEnterForeground:(UIApplication *)application {
	[[MMTrackingController sharedTrackingController] logEvent:@"EnterForeground"];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
	[[MMTrackingController sharedTrackingController] logEvent:@"EnterBackground"];
}

This will properly trigger suspend/resume handling of the tracking code, if needed.

Any place in your code where you'd like to track an interesting event, simply add a line like this:

[[MMTrackingController sharedTrackingController] logEvent:@"eventOfInterest"];

Google also lets you track screens ÒvisitedÓ by subclassing the GAITrackedViewController. Alternatively you can report screens with calls like like:

[[MMTrackingController sharedTrackingController] screenName:@ÒSettingsScreenÓ];

Note: Flurry has a special "error handler" that you can use to log exceptions to. You need to install the exception handler and invoke -[MMTrackingController logError] like this:

void uncaughtExceptionHandler(NSException *exception) {
	[[MMTrackingController sharedTrackingController] logError:@"Uncaught Exception" message:@"Crash!" exception:exception];
}                                       

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
	[[MMTrackingController sharedTrackingController] startTracking];
}

License

This source code is licensed under The MIT License. Enjoy.

mmtrackingcontroller's People

Stargazers

 avatar Oliver Letterer avatar Matt Martel avatar Jonah Grant avatar Dylan Beadle avatar Tim Ma avatar Skip Koppenhaver avatar Willi Wu avatar Daniel Tull avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.