I work with two different Google Analytics services (Google Analytics and Mixpanel) for my Android application.
I created an abstract base class as follows:
public abstract class AnalyticsService {
public abstract void trackAppOpen();
public abstract void identifyUserOnLogin();
}
Then I created specific subclasses that were extended from the base class AnalyticsService.
public class MPAnalytics extends AnalyticsService {
@Override
public void trackAppOpen() {
}
@Override
public void identifyUserOnLogin() {
}
}
public class GoogleAnalytics extends AnalyticsService {
@Override
public void trackAppOpen() {
}
@Override
public void identifyUserOnLogin() {
}
}
Now Google Analytics does not actually support user authentication, so I had to create an empty method implementation registerUserOnLogin().
I believe this is probably the wrong way to do this, since user identification is not a behavior in Google Analytics, and therefore, ideally, it should not be part of the base class AnalyticsServiceand should be defined in the MPAnalyticsclass.
, , AnalyticsService .
List<AnalyticsService> analyticsServices;
for (AnalyticsService service : analyticsServices) {
service.trackAppOpen();
service.identifyUserOnLogin();
}
? .