Skip to content

Commit cfd67fa

Browse files
authored
Merge pull request #27 from aptabase/fix/debug-only-data
fix: events logged only as debug
2 parents 7357925 + c86b2ff commit cfd67fa

8 files changed

+59
-7
lines changed

Aptabase.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Aptabase'
3-
s.version = '0.3.10'
3+
s.version = '0.3.11'
44
s.summary = 'Swift SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps'
55
s.homepage = 'https://aptabase.com'
66
s.license = { :type => 'MIT', :file => 'LICENSE' }

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 0.3.11
2+
3+
* Reverts previous change which caused RELEASE data not to show up
4+
* 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.
5+
6+
- Setting to release
7+
`Aptabase.shared.initialize(appKey: "", options: InitOptions(trackingMode: .asRelease))`
8+
9+
- Setting to debug
10+
`Aptabase.shared.initialize(appKey: "", options: InitOptions(trackingMode: .asDebug))`
11+
12+
- Setting omitting the value, same as setting to `.readFromEnvironment`:
13+
`Aptabase.shared.initialize(appKey: "")`
14+
`Aptabase.shared.initialize(appKey: "", options: InitOptions(trackingMode: .readFromEnvironment))`
15+
116
## 0.3.10
217

318
* Fix isDebug environment for multiple non RELEASE build configs https://github.com/aptabase/aptabase-swift/pull/24

Examples/HelloWorldMac/HelloWorldMacApp.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import Aptabase
44
@main
55
struct HelloWorldMacApp: App {
66
init() {
7-
Aptabase.shared.initialize(appKey: "A-DEV-0000000000");
7+
Aptabase.shared.initialize(
8+
appKey: "A-DEV-0000000000",
9+
// optionally track events as release, avoiding the default environment variable
10+
options: InitOptions(trackingMode: .asRelease)
11+
)
812
}
913

1014
var body: some Scene {

Sources/Aptabase/Aptabase.swift

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public class Aptabase: NSObject {
3333
return
3434
}
3535

36+
if let trackingMode = options?.trackingMode, trackingMode != .readFromEnvironment {
37+
env.isDebug = trackingMode.isDebug
38+
}
39+
3640
client = AptabaseClient(appKey: appKey, baseUrl: baseUrl, env: env, options: options)
3741

3842
let notifications = NotificationCenter.default

Sources/Aptabase/AptabaseClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

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

Sources/Aptabase/EnvironmentInfo.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ struct EnvironmentInfo {
3535
}
3636

3737
private static var isDebug: Bool {
38-
#if RELEASE
39-
false
40-
#else
38+
#if DEBUG
4139
true
40+
#else
41+
false
4242
#endif
4343
}
4444

Sources/Aptabase/InitOptions.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import Foundation
44
public final class InitOptions: NSObject {
55
let host: String?
66
let flushInterval: Double?
7+
let trackingMode: TrackingMode
78

89
/// - Parameters:
910
/// - host: The custom host to use. If none provided will use Aptabase's servers.
1011
/// - flushInterval: Defines a custom interval for flushing events.
11-
@objc public init(host: String? = nil, flushInterval: NSNumber? = nil) {
12+
/// - 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.
13+
@objc public init(host: String? = nil, flushInterval: NSNumber? = nil, trackingMode: TrackingMode = .readFromEnvironment) {
1214
self.host = host
1315
self.flushInterval = flushInterval?.doubleValue
16+
self.trackingMode = trackingMode
1417
}
1518
}

Sources/Aptabase/TrackingMode.swift

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Foundation
2+
3+
/// Represents the tracking mode (release/debug) for the client.
4+
@objc public class TrackingMode: NSObject {
5+
@objc public static let asDebug = TrackingMode(rawValue: 0)
6+
@objc public static let asRelease = TrackingMode(rawValue: 1)
7+
@objc public static let readFromEnvironment = TrackingMode(rawValue: 2)
8+
9+
private let rawValue: Int
10+
11+
private init(rawValue: Int) {
12+
self.rawValue = rawValue
13+
}
14+
15+
@objc public var isDebug: Bool {
16+
return self.rawValue == 0
17+
}
18+
19+
@objc public var isRelease: Bool {
20+
return self.rawValue == 1
21+
}
22+
23+
@objc public var isReadFromEnvironment: Bool {
24+
return self.rawValue == 2
25+
}
26+
}

0 commit comments

Comments
 (0)