Amplitude’s Quickstart Guide lacks the most important part, after installing Amplitude SDK as a dependency, it gives this code to init it:
import AmplitudeSwift
let amplitude = Amplitude(
configuration: Configuration(
apiKey: "YOUR-API-KEY"
)
)
OK, … so what should I do with it (after I insert my own API Key)?
Should it be in the @main
‘s init? Should I put it in didFinishLaunchingWithOptions
? Include it as a Singleton? Or a static var? Or paste this let amplitude = Amplitude(configuration...)
in each file?
P.S. I’ve looked at the SDK on GitHub and noticed that they use the static var
approach. As I understand it, this way Amplitude won’t be initialized until that static var is accessed for the first time. So if my app has 5 consecutive screens and I track an Amplitude Event on Screen #4, — only then will Amplitude start, and only then will fire Session events (session start), which would be incorrect as the user started his session on Screen #1.
P.P.S. Crazy how such a leading company doesn’t have straightforward guide on how to include it’s SDK. Mixpanel has it in Step 2 https://docs.mixpanel.com/docs/quickstart/connect-your-data?sdk=swift Firebase has it in Step 5 https://firebase.google.com/docs/ios/setup Straight and clear.