A Scalable Solution for Mobile App Analytics: The Publisher-Subscriber Model
Introduction
In the realm of mobile applications, we often find ourselves grappling with the need to gather valuable insights into user behaviour and application performance. This is particularly true for products that involve real-time interactions, such as Inbox SDK and Partner App. Before delving deeper for Analytics Manager and discussing the solution. Let’s understand the responsibility of both products first. We will delve deeper into the functionalities and capabilities of these two products, shedding light on their crucial roles.
Understanding the Roles and Responsibilities of Inbox SDK and Partner App
Inbox SDK
The Inbox SDK is a robust platform designed to bolster customer support operations, offering a wide array of features that empower businesses to efficiently manage their customer interactions. Let's take a closer look at its core responsibilities:
Overview and Analytics: The Inbox SDK offers a user-friendly interface for detailed ticket insights, covering live visitor count, chat sessions, queue stats, agent availability, and daily summaries.
Group-Based Analytics: Inbox SDK enables segmented data analysis, empowering businesses to tailor customer support and engagement strategies for specific groups.
Chat Management: Inbox SDK provides vital chat tools: segment-based chat lists (e.g., "My Chat," "Open," "Archive"), access to chat details and contacts, actions like transfer, close, reopen, and easy collaboration management within chats.
Public APIs: Inbox SDK goes beyond UI, offering public APIs for profile tasks. Users manage agent status, make updates, and seamlessly engage with and select bots.
Partner App
While the inbox SDK is responsible for managing various chat-related operations, the Partner App integrates the Inbox SDK and extends its capabilities, allowing agents to perform partner-specific tasks directly from their mobile devices. Here are its primary responsibilities:
Pre-Login Operations
Profile Interface
Bot Selection and Agent Management
Problem Statement
However, a common challenge developers face is how to log analytics events within their applications effectively. Analytics event loggers like MixPanel and Firebase require the application to initiate events for logging. In our case, this posed a significant challenge: how do we trigger events within our SDKs and ensure that the right events are logged at the right time?
Solution
The Analytics Manager
At the heart of our approach is the Analytics Manager, a central figure in the orchestration of our analytics framework. This component is responsible for collecting, processing, and dispatching analytics events to the relevant event loggers. Its key features include:
Event Collection: The Analytics Manager collects events from various sources, such as our Inbox SDK and the Partner App. This ensures that no matter where the event originates, it is captured and processed in a consistent manner.
Standardized Logging: The Manager enforces a standardized logging format for analytics events. This consistency is vital for data quality and the accuracy of subsequent analysis.
Event Dispatch: After processing, the Manager dispatches events to the appropriate event loggers, which may include real-time monitoring and custom analytics modules.
Publisher-Subscriber Model
Our solution is not just about addressing current analytics challenges; it's also designed to accommodate future growth and evolving requirements. This is where the publisher-subscriber pattern comes into play. By incorporating this model into our Analytics Manager, we future-proof our analytics framework in the following ways:
Dynamic Event Handling: As our software evolves, new events and logging requirements may arise. The publisher-subscriber model allows us to seamlessly integrate these changes. Adding new event types is as simple as introducing a new publisher and subscriber without requiring extensive modifications to the existing infrastructure.
Robust Analytics Enhancements: As our software matures, the need for advanced analytics capabilities becomes more apparent. By utilizing the publisher-subscriber pattern, we build a robust foundation for enhancing our analytics modules, enabling real-time analytics, historical data analysis, and customized analytics solutions tailored to our unique needs.
This approach ensures that analytics events are logged consistently and accurately, regardless of whether they originate from the Inbox SDK or the Partner App
.
The YellowAnalytics Class
At the core of our solution is the creation of a stateless class called YellowAnalytics
. This class is responsible for initiating and managing all events related to the SDK. By centralizing event management in this class, we ensure a clean and organized approach to analytics tracking.
The trackEvent
Function
To enable the Partner App to listen to and respond to events generated by the SDK, we've implemented a trackEvent
function within the YellowInbox
public class. This function acts as a subscriber to events published by the SDK, making it easy for the Partner App to integrate event logging. Here's how it works:
YellowInbox.trackEvent { event, payload in // Call Event loggers to log the new event }
The trackEvent
function accepts a closure that takes two parameters: event
and payload
. These parameters allow the Partner App to access event information and payload data, which can then be passed to the appropriate event loggers like MixPanel or Firebase for logging.
Benefits of Our Approach
Centralized Event Management: By using the
YellowAnalytics
class, we centralize event management within our SDKs, making it easier to maintain and extend our analytics capabilities.logEvent
function ofYellowAnalytics
class is responsible for logging events through out the SDKFlexibility for Partner App: The
trackEvent
function provides flexibility to the Partner App, allowing it to choose which events to log and how to handle them. This empowers developers to tailor analytics tracking to their specific needs.Consistency in Logging: With this approach, events are consistently logged, regardless of whether they originate from the Inbox SDK or the Partner App. This ensures that no valuable data is lost, and analytics reports remain accurate.
Scalability: When it comes to the scalability of an evolving SDK, this approach shines by effortlessly incorporating new events and logging demands. The beauty of this mechanism is that it necessitates no changes on the subscriber's end. All that's required is for the publisher to introduce the new events to your application. It's this innate adaptability that fortifies the groundwork for future enhancements in analytics, making it an ideal choice for growth and evolution.
Conclusion
Analytics tracking is a vital aspect of mobile application development, enabling data-driven decision-making and user experience improvements. By implementing an Analytics Manager using a publisher and subscriber pattern, we've overcome the challenge of logging events within our Inbox SDK and Partner App effectively. This approach not only centralises event management but also provides flexibility and scalability for future analytics needs, ensuring that we capture and leverage valuable insights to enhance our mobile Inbox products.