Skip to content

Commit

Permalink
Merge pull request #27 from aptabase/fix/debug-only-data
Browse files Browse the repository at this point in the history
fix: events logged only as debug
  • Loading branch information
ivnbogdan authored Oct 6, 2024
2 parents 7357925 + c86b2ff commit cfd67fa
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Aptabase.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Aptabase'
s.version = '0.3.10'
s.version = '0.3.11'
s.summary = 'Swift SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps'
s.homepage = 'https://aptabase.com'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 0.3.11

* Reverts previous change which caused RELEASE data not to show up
* Adds an option to explicitly set the tracking mode to Debug or Release. Not setting this option will fallback to the previous reading of environment value.

- Setting to release
`Aptabase.shared.initialize(appKey: "", options: InitOptions(trackingMode: .asRelease))`

- Setting to debug
`Aptabase.shared.initialize(appKey: "", options: InitOptions(trackingMode: .asDebug))`

- Setting omitting the value, same as setting to `.readFromEnvironment`:
`Aptabase.shared.initialize(appKey: "")`
`Aptabase.shared.initialize(appKey: "", options: InitOptions(trackingMode: .readFromEnvironment))`

## 0.3.10

* Fix isDebug environment for multiple non RELEASE build configs https://github.com/aptabase/aptabase-swift/pull/24
Expand Down
6 changes: 5 additions & 1 deletion Examples/HelloWorldMac/HelloWorldMacApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import Aptabase
@main
struct HelloWorldMacApp: App {
init() {
Aptabase.shared.initialize(appKey: "A-DEV-0000000000");
Aptabase.shared.initialize(
appKey: "A-DEV-0000000000",
// optionally track events as release, avoiding the default environment variable
options: InitOptions(trackingMode: .asRelease)
)
}

var body: some Scene {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Aptabase/Aptabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class Aptabase: NSObject {
return
}

if let trackingMode = options?.trackingMode, trackingMode != .readFromEnvironment {
env.isDebug = trackingMode.isDebug
}

client = AptabaseClient(appKey: appKey, baseUrl: baseUrl, env: env, options: options)

let notifications = NotificationCenter.default
Expand Down
2 changes: 1 addition & 1 deletion Sources/Aptabase/AptabaseClient.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

class AptabaseClient {
private static let sdkVersion = "[email protected].10"
private static let sdkVersion = "[email protected].11"
// Session expires after 1 hour of inactivity
private static let sessionTimeout: TimeInterval = 1 * 60 * 60

Expand Down
6 changes: 3 additions & 3 deletions Sources/Aptabase/EnvironmentInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ struct EnvironmentInfo {
}

private static var isDebug: Bool {
#if RELEASE
false
#else
#if DEBUG
true
#else
false
#endif
}

Expand Down
5 changes: 4 additions & 1 deletion Sources/Aptabase/InitOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import Foundation
public final class InitOptions: NSObject {
let host: String?
let flushInterval: Double?
let trackingMode: TrackingMode

/// - Parameters:
/// - host: The custom host to use. If none provided will use Aptabase's servers.
/// - flushInterval: Defines a custom interval for flushing events.
@objc public init(host: String? = nil, flushInterval: NSNumber? = nil) {
/// - trackingMode: Use TrackingMode.asDebug for debug events, TrackingMode.asRelease for release events, or TrackingMode.readFromEnvironment to use the environment setting. Defaults to .readFromEnvironment if omitted.
@objc public init(host: String? = nil, flushInterval: NSNumber? = nil, trackingMode: TrackingMode = .readFromEnvironment) {
self.host = host
self.flushInterval = flushInterval?.doubleValue
self.trackingMode = trackingMode
}
}
26 changes: 26 additions & 0 deletions Sources/Aptabase/TrackingMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation

/// Represents the tracking mode (release/debug) for the client.
@objc public class TrackingMode: NSObject {
@objc public static let asDebug = TrackingMode(rawValue: 0)
@objc public static let asRelease = TrackingMode(rawValue: 1)
@objc public static let readFromEnvironment = TrackingMode(rawValue: 2)

private let rawValue: Int

private init(rawValue: Int) {
self.rawValue = rawValue
}

@objc public var isDebug: Bool {
return self.rawValue == 0
}

@objc public var isRelease: Bool {
return self.rawValue == 1
}

@objc public var isReadFromEnvironment: Bool {
return self.rawValue == 2
}
}

0 comments on commit cfd67fa

Please sign in to comment.