Skip to content

Commit

Permalink
feat: update destination plugin to class
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyang1520 committed Dec 20, 2022
1 parent 5b9bf19 commit 8d15786
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
17 changes: 7 additions & 10 deletions Sources/Amplitude/Plugins/AmplitudeDestinationPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
//

public class AmplitudeDestinationPlugin: DestinationPlugin {
public let timeline = Timeline()
public var amplitude: Amplitude?
public let type: PluginType = .destination
private var pipeline: EventPipeline?

internal func enqueue(event: BaseEvent?) {
Expand All @@ -21,39 +18,39 @@ public class AmplitudeDestinationPlugin: DestinationPlugin {
}
}

public func track(event: BaseEvent) -> BaseEvent? {
public override func track(event: BaseEvent) -> BaseEvent? {
enqueue(event: event)
return event
}

public func identify(event: IdentifyEvent) -> IdentifyEvent? {
public override func identify(event: IdentifyEvent) -> IdentifyEvent? {
enqueue(event: event)
return event
}

public func groupIdentify(event: GroupIdentifyEvent) -> GroupIdentifyEvent? {
public override func groupIdentify(event: GroupIdentifyEvent) -> GroupIdentifyEvent? {
enqueue(event: event)
return event
}

public func revenue(event: RevenueEvent) -> RevenueEvent? {
public override func revenue(event: RevenueEvent) -> RevenueEvent? {
enqueue(event: event)
return event
}

public func flush() {
public override func flush() {
pipeline?.flush()
}

public func setup(amplitude: Amplitude) {
public override func setup(amplitude: Amplitude) {
self.amplitude = amplitude
pipeline = EventPipeline(amplitude: amplitude)
pipeline?.start()

add(plugin: IdentityEventSender())
}

public func execute(event: BaseEvent?) -> BaseEvent? {
public override func execute(event: BaseEvent?) -> BaseEvent? {
return event
}
}
34 changes: 31 additions & 3 deletions Sources/Amplitude/Plugins/DestinationPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,40 @@
// Created by Hao Yu on 11/15/22.
//

public protocol DestinationPlugin: EventPlugin {
var timeline: Timeline { get }
public class DestinationPlugin: EventPlugin {
public let type: PluginType = .destination
public var amplitude: Amplitude?
private var timeline = Timeline()

public func track(event: BaseEvent) -> BaseEvent? {
return event
}

public func identify(event: IdentifyEvent) -> IdentifyEvent? {
return event
}

public func groupIdentify(event: GroupIdentifyEvent) -> GroupIdentifyEvent? {
return event
}

public func revenue(event: RevenueEvent) -> RevenueEvent? {
return event
}

public func flush() {
}

public func execute(event: BaseEvent?) -> BaseEvent? {
return event
}

public func setup(amplitude: Amplitude) {
self.amplitude = amplitude
}
}

extension DestinationPlugin {

var enabled: Bool {
return true
}
Expand Down

0 comments on commit 8d15786

Please sign in to comment.