Skip to main content

Analytics

The LikeMinds SDK provides a set of predefined user events that you might want to track for your community application. To receive these analytics events and handle them according to your requirements, you need to implement the LMFeedAnalyticsProtocol.

Refer to Analytic Events to see the list of events that are tracked.

LMFeedAnalyticsProtocol

This protocol defines a single method that you must implement:

func trackEvent(for eventName: LMFeedAnalyticsEventName, eventProperties: [String: AnyHashable])
  • eventName: An instance of LMFeedAnalyticsEventName that represents the type of event being tracked. This enum contains various cases corresponding to different user actions or events within the LikeMinds SDK.
  • eventProperties: A dictionary containing key-value pairs with additional information or metadata related to the tracked event.

Example Implementation

Here's an example implementation of the LMFeedAnalyticsProtocol in a custom class called CustomAnalytics:

final class CustomAnalytics: LMFeedAnalyticsProtocol {
func trackEvent(for eventName: LMFeedAnalyticsEventName, eventProperties: [String: AnyHashable]) {
// Handle the analytics event here
print("Event: \(eventName)")
print("Properties: \(eventProperties)")

// You can send the event data to a third-party analytics service,
// log it locally, or perform any other desired action.
}
}

In this implementation, the trackEvent(for:eventProperties:) method simply prints the event name and properties to the console. However, you can modify this method to send the analytics data to a third-party service, log it locally, or perform any other desired action based on your application's requirements.

SDK Setup

To use your custom analytics implementation with the LikeMinds SDK, you need to provide an instance of your analytics class when setting up the SDK. Here's an example of how to do this in the AppDelegate:

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
let customAnalytics = CustomAnalytics()
LMFeedCore.shared.setupLikeMindsFeed(apiKey: "YOUR_API_KEY", analytics: customAnalytics)
// ...
return true
}

Replace YOUR_API_KEY with your actual LikeMinds API key, and provide an instance of your CustomAnalytics class (or any other class that conforms to LMFeedAnalyticsProtocol) as the analytics parameter.

By implementing the LMFeedAnalyticsProtocol and setting up your custom analytics class with the LikeMinds SDK, you can receive notifications for various user events and handle them according to your application's requirements.