Skip to content

Commit fbb4883

Browse files
committed
fix live plugin short lived issue
1 parent becdb0a commit fbb4883

File tree

1 file changed

+6
-1
lines changed
  • analytics-kotlin-live/src/main/java/com/segment/analytics/liveplugins/kotlin

1 file changed

+6
-1
lines changed

analytics-kotlin-live/src/main/java/com/segment/analytics/liveplugins/kotlin/JSAnalytics.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ class JSAnalytics {
131131

132132
fun add(plugin: JSObject): Boolean {
133133
if (!mainAnalytics) return false // Only allow adding plugins to injected analytics
134-
135134
val type: Plugin.Type = pluginTypeFromInt(plugin.getInt("type")) ?: return false
135+
136+
// persist plugin in the global scope to avoid being garbage collected
137+
engine.sync {
138+
this[plugin.ref.toString()] = plugin
139+
}
140+
136141
var result = false
137142
val livePlugin = LivePlugin(plugin, type, engine)
138143
val destination = plugin["destination"]

0 commit comments

Comments
 (0)