Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update destination plugin to class #30

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Amplitude/Amplitude.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Amplitude {
return timeline
}()

lazy var logger: (any Logger)? = {
public lazy var logger: (any Logger)? = {
return self.configuration.loggerProvider
}()

Expand Down
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
}
}
37 changes: 34 additions & 3 deletions Sources/Amplitude/Plugins/DestinationPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,43 @@
// Created by Hao Yu on 11/15/22.
//

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

public init() {
}

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

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

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

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

open func flush() {
}

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

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

extension DestinationPlugin {

var enabled: Bool {
return true
}
Expand Down