Use multiple analytics and other trackers in your Application easily
- Google Analytics
- Crashlytics
- Firebase
- Dito
- Intercom
- Mixpanel
Just added the necessary SDKs to your gradle file:
def darylVersion = '0.0.58'
compile "com.appprova.daryl:daryl:$darylVersion"
compile "com.appprova.daryl:googleanalytics:$darylVersion"
compile "com.appprova.daryl:crashlytics:$darylVersion"
compile "com.appprova.daryl:firebase:$darylVersion"
compile "com.appprova.daryl:facebook:$darylVersion"
compile "com.appprova.daryl:dito:$darylVersion"
compile "com.appprova.daryl:intercom:$darylVersion"
compile "com.appprova.daryl:mixpanel:$darylVersion"
GoogleAnalytics googleAnalytics = GoogleAnalytics
.getInstance(app.getApplicationContext());
Tracker googleTracker = googleAnalytics.newTracker(R.xml.app_tracker);
googleTracker.enableAdvertisingIdCollection(true);
TrackerAdapter googleAnalyticsTracker = new GoogleAnalyticsTracker(googleTracker);
TrackerAdapter firebaseTracker = new FirebaseTracker(FirebaseAnalytics.getInstance(context.getApplicationContext()));
TrackerAdapter crashlyticsLogTracker = new CrashlyticsLogTracker();
TrackerAdapter facebookTracker = new FacebookTracker(AppEventsLogger.newLogger(context.getApplicationContext()));
TrackerAdapter intercomTracker = new IntercomTracker(Intercom.client());
MixpanelAPI mixpanel =
MixpanelAPI.getInstance(context, MIXPANEL_TOKEN);
TrackerAdapter mixpanelTracer = new MixpanelTracer(mixpanelApi);
MultipleTrackerAdapter trackerAdapter = new MultipleTrackerAdapter();
trackerAdapter.addTracker(googleAnalyticsTracker);
trackerAdapter.addTracker(ditoTracker);
trackerAdapter.addTracker(firebaseTracker);
trackerAdapter.addTracker(facebookTracker);
trackerAdapter.addTracker(intercomTracker);
trackerAdapter.addTracker(mixpanelTracker);
if (!BuildConfig.DEBUG) {
trackerAdapter.addTracker(crashlyticsLogTracker);
}
After all trackers are registered you can just use the multiple tracker to track all events at once
trackerAdapter.logEvent(new EventBuilder("event name")
.setCategory("event category")
.setAction("event action")
.setProperty("custom property", "property value")
.get());
trackerAdapter.logPageView("page name");
Avaibles for : Firebase, CrashlyticsLog and Google Analytics
trackerAdapter.logException(new Exception("something went wrong"));
Avaibles for : Firebase, CrashlyticsLog
trackerAdapter.setUserProperty(Constants.USER_PROPERTY_EMAIL, "[email protected]");
In oder to create a custom tracker you just need to implement the TrackerAdapter
interface.