How to Create a Custom Plugin in Mobile SDKs

Create a custom plugin in the Android (Kotlin) and iOS (Swift) SDKs.

This guide lists the steps to create a sample custom plugin in the Android (Kotlin) and iOS (Swift) SDKs.

Overview

Custom plugins are user-defined plugins that provide flexibility in extending and modifying event processing within the SDK.

Android (Kotlin)

This section lists the steps to create a custom plugin EventFilteringPlugin for filtering out specific track events in the Android (Kotlin) SDK.

Specifically, it filters out the Application Opened and Application Backgrounded events and prevents them from being tracked.

  1. Add the plugin logic:
  1. Create an EventFilteringPlugin plugin:
  1. Add the plugin after initializing the SDK:
  1. To remove the plugin:

iOS (Swift)

This section lists the steps to create a custom plugin EventFilteringPlugin for filtering out specific track events in the iOS (Swift) SDK.

Specifically, it filters out the Application Opened and Application Backgrounded events and prevents them from being tracked.

  1. Add the plugin logic:
  1. Create an EventFilteringPlugin plugin:
  1. Add the plugin after initializing the SDK:
  1. To remove the plugin:
info

You can also use custom plugins with device mode integrations.

See Add custom plugins to integrations for more information.

Workflow overview

In the above example, EventFilteringPlugin is a custom plugin that intercepts and filters the specified events before they are processed.

The high-level workflow is described below:

  • While initializing the plugin, you can specify a list of events to be filtered.
  • When an event is received, the plugin checks if it matches any of the events specified in the filter list.
  • If the event is present in the filter list, the plugin logs a message and discards it by returning null. Otherwise, it forwards the event for processing, as usual.
  • The teardown method clears the event list whenever you remove the plugin.

Questions? Contact us by Email or on Slack