Giter Site home page Giter Site logo

twobitlabs / analyticskit Goto Github PK

View Code? Open in Web Editor NEW
355.0 18.0 58.0 226.79 MB

Analytics framework for iOS

License: MIT License

Objective-C 11.65% Ruby 6.39% Swift 81.81% C 0.14%
swift analytics-providers mparticle google-analytics flurry localytics crashlytics mixpanel objective-c firebase

analyticskit's Introduction

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.

Supported Providers

Unsupported Providers

The following providers are included but not supported. YMMV.

  • New Relic

    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

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:.

NOTE: If you are gettings an error similar to target has transitive dependencies that include static binaries when using Crashlytics/Intercom add the following to the bottom of your Podfile:

pre_install do |installer|
	# workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
    def installer.verify_no_static_framework_transitive_dependencies; end
end

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

analyticskit's People

Contributors

bdbergeron avatar brightredchilli avatar chrispix avatar colinmcardell avatar jeremymedford avatar jjamminjim avatar kdawgwilk avatar netbe avatar oronbz avatar pedroscocco avatar quellish avatar readmecritic avatar thuss avatar twobitlabs avatar yfantbl avatar zacshenker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

analyticskit's Issues

Ability to disable console logging

private func AKLog(_ message: String, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
    #if DEBUG
        print("\(URL(string: file)?.lastPathComponent ?? "") \(function)[\(line)]: \(message)")
    #else
        if message == "" {
            // Workaround for swift compiler optimizer crash
        }
    #endif
}

What about to add ability to disable logging to console? Sometimes it takes too much console space.

Consider removing Pods folder from git repo

The main reason to keep the Pods folder checked in is for easier contributions from the community by not needing them to run any CocoaPods commands to build and run the project. However, this has led to the size of the repo at checkout to be very large (~= 200mb) and depending on internet speed can take ~= 5 minutes to clone. This length of time is also incurred when cloning for CocoaPods in projects that depend on this project. I wanted to bring this up so we can evaluate the pros and cons to both and decide what the right decision is for the project.

Update to ARC

Now that we're ios8+, no reason to continue to support manual reference counting

Podspec not up to date

The latest source of the podspec seem to support Crashlytics, but the most recent cocoapod as indicated via pod search AnalyticsKit does not provide it as a subspec. Is this an oversight, or is this coming in a future update?

Swift use_frameworks and Google Analytics

In order to use pods like SwiftyJSON I need to specify use_frameworks!in my Podfile.
Using that you'll get a failure in Google Analytics.

Ld /Users/htribus/Library/Developer/Xcode/DerivedData/MyCoolApp-aohceyadfctqrdcitohbmkiijnxq/Build/Products/Debug-iphonesimulator/Pods/AnalyticsKit.framework/AnalyticsKit normal x86_64
    cd /Users/htribus/Documents/xcode/MyCoolApp/Pods
    export IPHONEOS_DEPLOYMENT_TARGET=8.0
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.3.sdk -L/Users/htribus/Library/Developer/Xcode/DerivedData/MyCoolApp-aohceyadfctqrdcitohbmkiijnxq/Build/Products/Debug-iphonesimulator/Pods -F/Users/htribus/Library/Developer/Xcode/DerivedData/MyCoolApp-aohceyadfctqrdcitohbmkiijnxq/Build/Products/Debug-iphonesimulator/Pods -filelist /Users/htribus/Library/Developer/Xcode/DerivedData/MyCoolApp-aohceyadfctqrdcitohbmkiijnxq/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-AnalyticsKit.build/Objects-normal/x86_64/AnalyticsKit.LinkFileList -install_name @rpath/AnalyticsKit.framework/AnalyticsKit -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -objc_abi_version -Xlinker 2 -ObjC -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=8.0 -framework Foundation -single_module -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/htribus/Library/Developer/Xcode/DerivedData/MyCoolApp-aohceyadfctqrdcitohbmkiijnxq/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-AnalyticsKit.build/Objects-normal/x86_64/AnalyticsKit_dependency_info.dat -o /Users/htribus/Library/Developer/Xcode/DerivedData/MyCoolApp-aohceyadfctqrdcitohbmkiijnxq/Build/Products/Debug-iphonesimulator/Pods/AnalyticsKit.framework/AnalyticsKit

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_GAI", referenced from:
      objc-class-ref in AnalyticsKitGoogleAnalyticsProvider.o
  "_OBJC_CLASS_$_GAIDictionaryBuilder", referenced from:
      objc-class-ref in AnalyticsKitGoogleAnalyticsProvider.o
  "_kGAIScreenName", referenced from:
      -[AnalyticsKitGoogleAnalyticsProvider logScreen:] in AnalyticsKitGoogleAnalyticsProvider.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Even though its more an error of Google Analytics, then of AnalyticsKit you might state it in the readme

Optional providers

What if I want to send some spacific events for Google analytics and not to all providers I have?

CocoaPods master repo missing Parse-iOS-SDK

I was hoping that by the time my addition of Parse to AnalyticsKit was merged in that my Parse SDKs would be merged into the master CocoaPods repo. Unfortunately, at this time, it is not. For a temporary fix, just execute repo add bdbergeron https://github.com/bdbergeron/Specs in your terminal to add my fork of the CocoaPods specs. This needs to be done before executing pod install.

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.