Quantcast
Channel: Backstage - Medium
Viewing all articles
Browse latest Browse all 103

GoLytics- The Art of Drawing Insights

$
0
0

A custom framework built for usage tracking on Android app. Sends tracking data to multiple data analytics platforms through a single method call.

As a leader in internet space, we keep on enhancing on our product lines and features rapidly. Due to this, fast execution lies at the core of engineering at Goibibo. This helps us in achieving our primary motive i.e. solving problems and delighting our customers in a shot, while endorsing the fact that speed is the soul of our business.

But when speaking of releasing features and products rapidly, a few grey areas that come into existence are the performance tracking, analytics, insights, and data capturing of those new features. As tracking them has never been a straight forward task for any product engineering group. Many suggest one should go the tap way, i.e. an event should be pushed on every touch interaction. But when building complex flows and large scale features, this approach could lead to huge data generation, resulting into an un-manageable events list on various tracking platforms. Also FYI. most of the platforms have an event limit based plan, restricting us to send all events everywhere. Another concern is when using mobile apps, where data usage is also a concern for app users, we cannot have a mandate to send an event to all app tracking platforms, at the cost of user’s mobile data. Hence when building a usage tracking framework for Goibibo’s Android app, we had to track user’s every action by maintaining a balance between network calls and sending data across multiple platforms. Therefore to send only required events to respective platforms something bespoke had to be built.

Hence at Goibibo’s Android mobile team, we invented a new event tracking design pattern codenamed GoLytics. A loosely structured framework on Java’s builder pattern. This framework is built with single thing in mind — Flexibility.

Understanding the problem in detail

Generally speaking, any leading market app would rely on more than one analytics platform to gain insights on their app. Similarly, here at Goibibo as well we rely on many platforms like:

  1. Appsflyer
  2. Google Analytics
  3. Firebase Analytics
  4. Facebook Analytics
  5. Segment
  6. New Relic
  7. Data warehouse
  8. GCP BigQuery
  9. Branch
  10. Web Engage

Now if an android app starts sending all the usage data directly to the above mentioned tracking platforms, it would result into a data explosion at all of these platforms. As most of it might not be relevant at them. Also this would consume a huge amount data bandwidth and cost at end user’s mobile device.

Solution- Inception of GoLytics

A perfect solution to this problem would be in two parts:

Step 1

Start sending all the tracking data to a single platform and integrate it with other tracking platforms to pass on the events and tracking data. Just like a stream of events. This would reduce the redundant event pushes from the app, optimising bandwidth and data usage on network.

To actually implement this we used Segment as our integration partner, where all the events are pushed and further passed on to respective tracking platforms.

Step 2

Since tech industry keeps on changing rapidly and also Segment is still an evolving company, it does not have integrations with all the analytics providers that our app uses. Hence we built GoLyitcs an in house, common event pushing framework for Goibibo’s android app. So that we have the capability to send events to a single or multiple analytics partners with minimal code change.

So now with GoLytics integrated in our Android app, we have a very simplified event push structure. Where as of now events are pushed only to two analytics platforms, i.e. Segment and Firebase Analytics, minimizing bandwidth and data costs:

Also as mentioned above, this framework gives us the flexibility, since its built on the Java’s builder pattern. Therefore if we feel that we need to add any new analytics partner which cannot be integrated through Segment, we can effortlessly use GoLytics and send events from the app itself. Next lets have a look at few lines of code for better understanding:

Step 2.1- Defining GoLytics class to send events:

public class GoLytics {
private Context mContext;
private AppEventsLogger fbLogger;
private Options segmentOptions;
private FirebaseAnalytics firebaseAnalytics;

public GoLytics(GoLyticsBuilder builder) {
this.mContext = builder.mContext;
fbLogger = builder.fbLogger;
segmentOptions = builder.mOptions;
firebaseAnalytics = builder.mFirebaseAnalytics;
}

public void sendEvent(final String eventName,
@Nullable final Map<String, Object> eventValues) {
//facebook events block
if (fbLogger != null) {
if (eventValues == null) {
fbLogger.logEvent(eventName);
} else {
Bundle bundle = GoLyticsBuilder.
convertMapToBundle(eventValues);
fbLogger.logEvent(eventName, bundle);
}
}
// Segment.io block
if (segmentOptions != null) {
if (eventValues == null || eventValues.size() == 0) {
Analytics.with(mContext).track(eventName,
null, segmentOptions);
} else {
Properties properties = new Properties();
properties.putAll(eventValues);
Analytics.with(mContext)
.track(eventName, properties, segmentOptions);
}
}
// Firebase events block
if (firebaseAnalytics != null) {
if (eventValues == null || eventValues.size() == 0) {
firebaseAnalytics.logEvent(eventName, null);
} else {
Bundle bundle = GoLyticsBuilder.
convertMapToBundle(eventValues);
firebaseAnalytics.logEvent(eventName, bundle);
}
}
}

.
.
.
.
.
.

}

This way it solves another major problem for us i.e. integration of a new analytics partner. For ex. if we have to include a new analytics SDK, and push events to it, with this design pattern it would be very simple to do so. Addition of just a few lines of code is required in the main ‘sendEvent’ method and we are good to roll out.

Step 2.2- Defining GoLytics Builder:

public class GoLyticsBuilder {

public AppEventsLogger fbLogger;
public Options mOptions;
public Context mContext;
public FirebaseAnalytics mFirebaseAnalytics;

public GoLyticsBuilder(Context ctx) {
mContext = ctx;
}

public GoLyticsBuilder initFacebook() {
this.fbLogger = AppEventsLogger.newLogger(mContext);
return this;
}

public GoLyticsBuilder initSegment() {
mOptions = buildSegmentOptions(mContext);
return this;
}

public GoLyticsBuilder initFirebaseEvents() {
mFirebaseAnalytics = FirebaseAnalytics.getInstance(mContext);
return this;
}

//Return the finally constructed object
public GoLytics build() {
GoLytics goLytics = new GoLytics(this);
return goLytics;
}

public static GoLytics buildDefault(Context ctx) {
GoLyticsBuilder mBuilder = new GoLyticsBuilder(ctx);
return mBuilder.initSegment().initFirebaseEvents().build();
}
  .
.
.
}

Earlier we had to send segment and firebase events separately, but from now on this can be done with a single line of code. Since the new GoLytics framework is deeply integrated in to our application project, making the process of sending an event quite simple. All we need to do is build a default GoLytics object and call sendEvent method, as shown below:

Map<String, Object> eventValues = new HashMap<>();
eventValues.put(GoLyticAttributes.CustomDimentions.APPSFLYER_INSTALL_SOURCE, conversionData.get(Constant.MEDIA_SOURCE));
eventValues.put(GoLyticAttributes.CustomDimentions.APPSFLYER_INSTALL_CAMPAIGN, conversionData.get(Constant.CAMPAIGN));
mGoLytics.sendEvent(GoLyticEvents.Attribution.INSTALL_ATTRIBUTION_PING_RECEIVED, eventValues);

Sending Events with a custom object

For example an event has to be sent on Facebook Analytics.

Step 1: Initialise a GoLytics object using the GoLyticsBuilder

GoLyticsBuilder mBuilder = new GoLyticsBuilder(ctx);
GoLytics goLytics = mBuilder.initFacebook().build();

Step 2: Send the event

Map<String, Object> eventValues = new HashMap<>();
eventValues.put(GoLyticAttributes.CustomDimentions.APPSFLYER_INSTALL_SOURCE, conversionData.get(Constant.MEDIA_SOURCE));
eventValues.put(GoLyticAttributes.CustomDimentions.APPSFLYER_INSTALL_CAMPAIGN, conversionData.get(Constant.CAMPAIGN));
goLytics.sendEvent(GoLyticEvents.Attribution.INSTALL_ATTRIBUTION_PING_RECEIVED, eventValues);

As of now GoLytics is deeply integrated with more tracking platforms than shown above, but for maintaining simplicity some of the integrations are not shown. In near future we will be extending the support to even more platforms and making this framework open-source. Watch this space for updates.


GoLytics- The Art of Drawing Insights was originally published in Backstage on Medium, where people are continuing the conversation by highlighting and responding to this story.


Viewing all articles
Browse latest Browse all 103

Trending Articles