Events are dispatched to collectors via plugins.
There are three plugins provided with the SDK:
It is possible to create custom plugins, for example for testing purposes
Plugins must conform to the TagPlugin
interface:
interface TagPlugin {
submitEvent(eventType, event);
getSessionInfo();
initializeFromSessionInfo(data);
}
Plugins must conform to the TagPlugin
interface:
interface TagPlugin {
submitEvent(eventType: EventType, event: Event): void;
getSessionInfo(): TagPluginSessionInfo;
initializeFromSessionInfo(data: TagPluginSessionInfo): void;
}
The TagPluginSessionInfo
describes a dictionary of string properties that the plugin needs to store between sessions.
Plugins must conform to the NPOPlugin
protocol:
class YourPlugin: NPOPlugin {
func submit(event: NPOEvent) {
// Add your logic here
}
}
class CustomPlugin: TagPlugin {
override fun start() {
TODO("Implement")
}
override fun submit(event: TagEvent) {
TODO("Implement")
}
override fun stop() {
TODO("Implement")
}
override fun getSerializedSessionInfo(onSessionInfoRetrieved: (Map<String, Any>) -> Unit) {
TODO("Implement")
}
}
From the getSessionInfo
function of the plugin, the plugin can return a dictionary of string values. Return an empty dictionary if there is no data to transfer.
From the getSessionInfo
function of the plugin, the plugin can return a dictionary of string values. Return an empty dictionary if there is no data to transfer.
In case you need to transfer information from your custom plugin to another device, you can edit the exported properties by conforming to the Exportable
protocol
extension CustomPlugin: Exportable {
/// You can use a custom object to define your exported properties
typealias ExportablePropertyType = CustomPluginExportable
/// Make sure to build your export function with the data you need to fetch when transfering the session
func export(completion: @escaping (CustomPluginExportable?) -> Void) {
let exportableObject = CustomPluginExportable(property: "property-value")
completion(exportableObject)
}
}
struct CustomPluginExportable: Codable {
let property: String
private enum CodingKeys: String, CodingKey {
case property = "yourPropertyName"
}
}
If you need to transfer information from your custom plugin to another device, consider overriding the getSerializedSessionInfo()
method.
override fun getSerializedSessionInfo(onSessionInfoRetrieved: (Map<String, Any>) -> Unit) {
val data = mapOf(
"key" to "value",
)
onSessionInfoRetrieved(data)
}
Regarding how to retrieve the data and start your session based on the imported information, you can check its section