iOS SDK for Amplitude Analytics and tracking
Carrier Tracking
- Unsupported in iOS 16+ due to deprecated APIs.
- Amplitude will update when Apple provides a replacement.
Installing the SDK
- Install with CocoaPods, Carthage, or Swift Package Manager.
CocoaPods
- Add to
Podfile
and run pod install
.
Carthage
- Add to
Cartfile
and follow Carthage documentation.
Swift Package Manager
- Navigate to
File
> Swift Package Manager
> Add Package Dependency
and add the repository URL.
Initializing the SDK
- Requires API key for your Amplitude project.
- Initialize in
application:didFinishLaunchingWithOptions:
Example Code
[Amplitude instance].defaultTracking.sessions = YES;
[Amplitude instance].initializeApiKey("API_KEY");
Amplitude.instance().defaultTracking.sessions = true;
Amplitude.instance().initializeApiKey("API_KEY");
Configuring the SDK
- Customize settings such as event upload periods, max batch size, and server URL.
setServerZone
for EU data residency.
Sending Events
- Log user interactions like button clicks.
- Events can include properties for more context.
User Properties
- Manage using
AMPIdentify
class.
- Operations available:
set
, setOnce
, add
, remove
, and more.
- Allows for detailed user analysis and tracking.
Default Event Tracking
- Track sessions, app lifecycles, screen views, and deep links.
- Controlled via
defaultTracking
options.
User and Group Management
- Set user IDs, user properties, and group memberships.
- Use
setGroup
and logEventWithGroups
for group-based analytics.
Revenue Tracking
- Track revenue with
AMPRevenue
class.
- Log revenue-related events for financial analytics.
Advanced Topics
User Sessions
- Sessions are tracked automatically; custom configurations available.
- Log events out-of-session if necessary.
Debugging and Privacy Settings
- Enable debug logging and manage user privacy with options like COPPA control.
Dynamic Configuration
- Allows automatic server URL configuration based on user location.
Security and Privacy
- Unique instance names can prevent unauthorized access to app data.
- Apple privacy manifest updates required for compliance.
tvOS, watchOS, and App Clips
- SDK supports these platforms with specific configurations.
Middleware and Offline Mode
- Extend functionality with middleware.
- Offline mode enables local event storage until connectivity is restored.
Opt-Out Tracking
- Users can completely disable tracking if they choose.
Additional Considerations
- Ensure compliance with Apple's privacy requirements.
- Update privacy manifests according to app configuration.