This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final class AmplitudeProvider: TrackingProviderType { | |
| private let amplitude = Amplitude() | |
| func setup() { | |
| amplitude.initializeApiKey("XXXX-XXXX") | |
| amplitude.eventUploadPeriodSeconds = 120 | |
| } | |
| func track(event: TrackingEventType) { | |
| amplitude.logEvent(event.identifier, withEventProperties: event.properties) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol TrackingClientType: TrackingProviderType { | |
| var providers: [TrackingProviderType] { get } | |
| func add(provider: TrackingProviderType) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TrackingClient: TrackingClientType { | |
| var providers = [TrackingProviderType]() | |
| func add(provider: TrackingProviderType) { | |
| providers.append(provider) | |
| } | |
| func track(event: TrackingEventType) { | |
| for provider in providers { | |
| provider.track(event: event) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { | |
| App.trackingClient = TrackingClient() | |
| App.trackingClient.add(provider: AmplitudeProvider()) | |
| App.trackingClient.add(provider: GoogleProvider()) | |
| App.trackingClient.add(provider: FacebookProvider()) | |
| App.trackingClient.setup() | |
| return true | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arsen = User(id: "1", name: "Arsen", age: 26) | |
| App.trackingClient.track(event: UserEvents.created(user: arsen)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TestTrackingClient: TrackingClientType { | |
| var providers = [TrackingProviderType]() | |
| var events = [TrackingEventType]() | |
| func track(event: TrackingEventType) { | |
| events.append(event) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| App.trackingClient = TestTrackingClient() | |
| let productViewController = ProductViewController(product: product) | |
| productViewController.buy() | |
| App.trackingClient.events[0] == UserEvents.bought(product: product) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol TrackingEventType { | |
| var identifier: String { get } | |
| var properties: [String: Any] { get } | |
| } | |
| protocol TrackingProviderType { | |
| func track(event: TrackingEventType) | |
| func associate(with user: User) | |
| func disassociateUser() | |
| func setup() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is a comment | |
| nil # is used to represent the absence of a value | |
| true # A Bool that is true | |
| false # A Bool that is false | |
| 10 # Int32 | |
| 1.0 # Float64 | |
| 'a' # a Char represents a Unicode code point. It occupies 32 bits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def one | |
| 1 | |
| end | |
| proc = ->one | |
| proc.call #=> 1 |