Skip to content

AppAmbit Analytics iOS

Submit Analytics Events

Use this class to send analytics events from your iOS application. To get started, make sure you've added the module to your app. For setup instructions, refer to the Getting Started guide.

AppAmbit Analytics gives you insight into user behavior and engagement, helping you improve your application experience. The SDK automatically collects session data and device details such as model and OS version. You can also define custom events to track interactions that matter to you. All collected data is accessible through the AppAmbit portal for analysis.

Session and Device Information

After integrating AppAmbit Analytics and starting the SDK, it will begin tracking user sessions and device information (e.g., OS version, device model) automatically—no extra code required, unless Analytics.enableManualSession() is called.

Manual Management for Session

Info

Manual mode is disabled by default, if you need more control over sessions, events and logs you can do so by following the steps below.

In case you want to handle your session manually you must call enableManualSession, before you start using AppAmbit

Swift

    import SwiftUI
    import AppAmbit;

    @main
    struct AppAmbitTestingApp: App {
        init() {
            Analytics.enableManualSession()
            AppAmbit.start(appKey: "<YOUR-APPKEY>")                
        }
        var body: some Scene {
            WindowGroup {
                ContentView()
            }
        }
    }

Objective-C

    #import "ViewController.h"
    #import "AppAmbitSdk/AppAmbitSdk-Swift.h"   

    - (void)viewDidLoad {
        [super viewDidLoad];

        [Analytics enableManualSession];
        [AppAmbit startWithAppKey:@"<YOUR-APPKEY>"];

    }

Warning

If this option is enabled no event, log or crash will be sent or saved locally until a session is started manually using Analytics.startSession(); anywhere in your code where you need it.

Start Session

If you already called enableManualSession, you can now start a session manually, calling StartSession:

Swift

Analytics.startSession();

Objective-C

[Analytics startSessionWithCompletion:nil];

If the method is called again before ending the session the call will be ignored.

End Session

If you already called EnableManualSession, and you already started a session, you can now end the session session manually, calling EndSession:

Swift

Analytics.endSession();

Objective-C

[Analytics endSessionWithCompletion:nil];

If the method is called again before ending the session the call will be ignored.

Generate a Test Event

AppAmbit Analytics includes an API to trigger a test event, useful for verifying SDK integration.

Swift

Analytics.generateTestEvent();

Objective-C

[Analytics generateTestEventWithCompletion:nil];

Custom Events

Track custom events to capture meaningful user interactions. Once the SDK is initialized, use the trackEvent() method to track your events with properties. You can send up to 150 distinct event names. Also, there's a maximum limit of 120 characters per event name and 80 characters per event property name and event property value.

Swift

Analytics.trackEvent(eventTitle: "Test TrackEvent", data: ["test1":"test1"])

Objective-C

[Analytics trackEventWithEventTitle:@"Test TrackEvent" data:@{ @"test1": @"test1" } createdAt:nil completion:nil];

Properties are optional. The following code is for send a simple event without additional data:

Swift

Analytics.trackEvent(eventTitle: "Test Batch TrackEvent", data: [:])

Objective-C

[Analytics trackEventWithEventTitle:@"Test TrackEvent" data:@{} createdAt:nil completion:nil];