Skip to content

Latest commit

 

History

History
197 lines (136 loc) · 8.58 KB

README.md

File metadata and controls

197 lines (136 loc) · 8.58 KB

Build Status Gitter chat

AnalyticsKit

The goal of AnalyticsKit is to provide a consistent API for analytics regardless of the provider. With AnalyticsKit, you just call one logging method and AnalyticsKit relays that logging message to each registered provider. AnalyticsKit works in both Swift and Objective-C projects.

***Please Note -- AnalyticsKit is being migrated from Objective-C to Swift. If you want the super stable Objective-C version get the 1.2.9 version. If you're willing to deal with some Swift and Objective-C interop then grab the latest master branch. We love pull requests (and integrate them quickly) so if you find a provider that hasn't been migrated to Swift and are willing to port it go for it!

Supported Providers

Unsupported Providers

The following providers are included but not supported. YMMV.

  • New Relic (needs migration to Swift)

    We've had a number of problems integrating the New Relic framework into the test app, so we can't verify that events are logged correctly.

If you would like to add support for a new provider or to update the code for an existing one, simply fork the master repo, make your changes, and submit a pull request.

How to Use

CocoaPods

***Please Note -- Two Bit Labs does not officially support CocoaPods for AnalyticsKit. If you run into problems integrating AnalyticsKit using CocoaPods, please send a pull request with a fix. Due to challenges with Cocoapods we are not able to deploy the latest version to CocoaPods, if you would like the latest version you can point the pod to this repo eg.

pod 'AnalyticsKit', :git => 'https://github.com/twobitlabs/AnalyticsKit.git'

If your project uses CocoaPods, you can simply include AnalyticsKit for full provider support, or you can specify your provider using CocoaPods subspecs.

  • AdjustIO - pod 'AnalyticsKit/AdjustIO'
  • Crashlytics - pod 'AnalyticsKit/Crashlytics'
  • Flurry - pod 'AnalyticsKit/Flurry'
  • Google Analytics - pod 'AnalyticsKit/GoogleAnalytics'
  • Localytics - pod 'AnalyticsKit/Localytics'
  • Mixpanel - pod 'AnalyticsKit/Mixpanel'
  • New Relic - pod 'AnalyticsKit/NewRelic'
  • TestFlight - pod 'AnalyticsKit/TestFlight'

***Please Note -- The Parse subspec has been removed, as it won't integrate correctly using CocoaPods.

Installation

  1. Download the provider's SDK and add it to your project, or install via cocoapods.
  2. Add AnalyticsKit to your project either as a git submodule or copying the source into your project. In Xcode, only include AnalyticsKit.h/.m/.swift and any providers you plan to use.
  3. In your AppDelegate's applicationDidFinishLaunchingWithOptions: method, create an array with your provider instance(s) and call initializeProviders:.

Swift:

Initialize AnalyticsKit in application:didFinishLaunchingWithOptions:

AnalyticsKit.initializeProviders([AnalyticsKitFlurryProvider(withAPIKey: flurryKey)])

Depending on which analytics providers you use you may need to include the following method calls in your app delegate (or just go ahead and include them to be safe):

AnalyticsKit.applicationWillEnterForeground()
AnalyticsKit.applicationDidEnterBackground()
AnalyticsKit.applicationWillTerminate]()

If you're using a legacy Objective-C AnalyticsKitProvider you will need to import that in your bridging header to make it available to Swift. You can find the name of the generated header name under Build Settings, Swift Compiler - Code Generation, Objective-C Bridging Header. Often named something like YourProject-Bridging-Header.h.

#import "AnalyticsKitNewRelicProvider.h"

Objective-C:

Make AnalyticsKit Swift classes available to your Objective-C classes by importing your Objective-C generated header. You can find the name of the generated header name under Build Settings, Swift Compiler - Code Generation, Objective-C Generated Interface Header Name:

#import "YourProject-Swift.h"

Initialize AnalyticsKit in applicationDidFinishLaunchingWithOptions

[AnalyticsKit initializeProviders:@[[[AnalyticsKitFlurryProvider alloc] initWithAPIKey:@"[YOUR KEY]"]]];

To log an event, simply call the logEvent: method.

[AnalyticsKit logEvent:@"Log In" withProperties:infoDict];

Depending on which analytics providers you use you may need to include the following method calls in your app delegate (or just go ahead and include them to be safe):

[AnalyticsKit applicationWillEnterForeground];
[AnalyticsKit applicationDidEnterBackground];  
[AnalyticsKit applicationWillTerminate];  

See AnalyticsKit.h for an exhaustive list of the logging methods available.

Channels

AnalyticsKit supports grouping analytics providers together into separate channels. If your primary providers is Flurry but you also want to log certain separate events to Google Analytics you can setup AnalyticsKit to log events following the instructions above and then setup a separate channel for Google Analytics as follows:

Swift:

// In didFinishLaunchingWithOptions you could configure a separate channel of providers
AnalyticsKit.channel("google").initializeProviders([AnalyticsKitGoogleAnalyticsProvider(withTrackingID: trackingId)])

// Then later in your code log an event to that channel only
AnalyticsKit.channel("google").logEvent("some event")

Objective-C:

// In didFinishLaunchingWithOptions you could configure a separate channel of providers
[[AnalyticsKit channel:@"google"] initializeProviders:@[[[AnalyticsKitGoogleAnalyticsProvider alloc] initWithTrackingID:trackingId]]];

// Then later in your code log an event to that channel only
[[AnalyticsKit channel:@"google"] logEvent:@"some event"];

Apple Watch Analytics

AnalyticsKit now provides support for logging from your Apple Watch Extension.

Supported Providers

Installation

  1. If you haven't already done so, follow the installation steps above to add your provider's SDK and AnalyticsKit to your project.
  2. Adding Provider's API Key.

Objective-C:

Initialize AnalyticsKit in awakeWithContext

AnalyticsKitWatchExtensionFlurryProvider *flurry = [AnalyticsKitWatchExtensionFlurryProvider new];
[AnalyticsKit initializeProviders:@[flurry]];

To log an event, simply call the logEvent: method.

[AnalyticsKit logEvent:@"Launching Watch App"];

Swift:

Import AnalyticsKit and any providers in your bridging header:

#import "AnalyticsKit.h"
#import "AnalyticsKitWatchExtensionFlurryProvider.h"

Initialize AnalyticsKit in awakeWithContext

let flurryProvider = AnalyticsKitWatchExtensionFlurryProvider()
AnalyticsKit.initializeProviders([flurryProvider])

To log an event, simply call the logEvent method.

AnalyticsKit.logEvent("Launching Watch App");

Contributors