amplitude / Amplitude-Swift

Native iOS/tvOS/macOS/watchOS SDK
MIT License
32 stars 22 forks source link

Amplitude won't initialize #191

Closed cliffordh closed 3 months ago

cliffordh commented 3 months ago

Expected Behavior

The Amplitude setup wizard web page should have detected events from my mobile app.

Current Behavior

Amplitude does not appear to be initializing.

Possible Solution

No soluttion.

Steps to Reproduce

Install Amplitude via Swift Package Manager Add following code to init() method of SwiftUI, SwiftApp.swift

     let amplitude = Amplitude(
        configuration: Configuration(
            apiKey: "xxx",
            logLevel: LogLevelEnum.DEBUG,
            callback: { (event: BaseEvent, code: Int, message: String) -> Void in
                print("eventcallback: \(event), code: \(code), message: \(message)")
            },
            defaultTracking: .ALL
        )
     )

     amplitude.track(eventType: "App Launch")

     print("Amplitude initialized")
     print("Amplitude user ID: \(amplitude.getUserId() ?? "NO user")")

The event "App Launch" is not tracked. The words "Amplitude initialized" and "NO user" are output to the console. The setup wizard web page does not detect any event. There is no other Amplitude related debug output in the console.

Environment

cliffordh commented 3 months ago

Following the iOS SDK instructions does not work, but I was able to get events to flow mimicing the Example app from 2022 in the project:

extension Amplitude {
    static var amp = Amplitude(
        configuration: Configuration(
            apiKey: "xxx",
            logLevel: LogLevelEnum.DEBUG,
            callback: { (event: BaseEvent, code: Int, message: String) -> Void in
                print("eventcallback: \(event), code: \(code), message: \(message)")
            },
            trackingOptions: TrackingOptions().disableTrackCarrier().disableTrackDMA(),
            flushEventsOnClose: true,
            minTimeBetweenSessionsMillis: 15000,
            defaultTracking: .ALL
        )
    )
}
crleona commented 3 months ago

Hi @cliffordh, I'm glad you were able to get things working. We do recommend that you keep a reference to the Amplitude object as you've done, and we'll update the documentation to reflect this.