Last active
December 27, 2018 23:46
-
-
Save talosdev/4b357b94fde1bae865615e05c4bfbaf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FunalyticsTracker { | |
private final Analytics analytics; | |
private DisposableObserver<FunalyticsEvent> eventsDisposable; | |
public FunalyticsTracker(Context context) { | |
analytics = Analytics.getInstance(context); | |
if (isInterestedInEvents()) { | |
subscribeToEvents(); | |
} | |
if (isInterestedInUserProperties()) { | |
subscribeToUserProperties(); | |
} | |
} | |
// Custom tracker logic about whether this tracker | |
// is interested in the Events stream | |
private boolean isInterestedInEvents() { | |
return true; | |
} | |
// Custom tracker logic about whether this tracker | |
// is interested in the User Properties stream | |
private boolean isInterestedInUserProperties() { | |
return true; | |
} | |
private void subscribeToEvents() { | |
eventsDisposable = analytics.eventsStream() | |
.filter(this::acceptEvent) | |
.doOnNext(this::logEvent) | |
.map(this::transformEvent) | |
.subscribeWith(new DisposableObserver<FunalyticsEvent>() { | |
@Override | |
public void onNext(@NonNull FunalyticsEvent funalyticsEvent) { | |
postEvent(funalyticsEvent); | |
} | |
@Override | |
public void onError(@NonNull Throwable throwable) { | |
// Log the error | |
} | |
@Override | |
public void onComplete() { | |
} | |
}); | |
} | |
// Whether this tracker is interested in this specific event | |
public boolean acceptEvent(@NonNull Event event) { | |
return true; | |
} | |
@NonNull | |
private FunalyticsEvent transformEvent(@NonNull Event event) { | |
// Transform the generic event to the platform-specific event. | |
} | |
private void logEvent(@NonNull Event event) { | |
// Log the event as processed by this tracker, if necessary | |
} | |
private void postEvent(@NonNull FunalyticsEvent funalyticsEvent) { | |
// Send the event to the Funalytics platform using the Funalytics SDK | |
} | |
// .... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment