Skip to content

fix: events logged only as debug #27

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

Merged
merged 3 commits into from
Oct 6, 2024
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 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
}
}
Loading