Amplitude Class Reference
Inherits from | NSObject |
---|---|
Declared in | Amplitude.h Amplitude.m |
Overview
Amplitude iOS SDK.
Use the Amplitude SDK to track events in your application.
Setup:
- In every file that uses analytics, import Amplitude.h at the top
#import "Amplitude.h"
- Be sure to initialize the API in your didFinishLaunchingWithOptions delegate
[[Amplitude instance] initializeApiKey:@"YOUR_API_KEY_HERE"];
- Track an event anywhere in the app
[[Amplitude instance] logEvent:@"EVENT_IDENTIFIER_HERE"];
You can attach additional data to any event by passing a NSDictionary object:
NSMutableDictionary *eventProperties = [NSMutableDictionary dictionary]; [eventProperties setValue:@"VALUE_GOES_HERE" forKey:@"KEY_GOES_HERE"]; [[Amplitude instance] logEvent:@"Compute Hash" withEventProperties:eventProperties];
Note: you should call SDK methods on an Amplitude instance, for example logging events with the default instance: [[Amplitude instance] logEvent:@"testEvent"];
Note: the SDK supports tracking data to multiple Amplitude apps, via separate named instances. For example: [[Amplitude instanceWithName:@"app1"] logEvent:@"testEvent"];
See Tracking Events to Multiple Apps.
For more details on the setup and usage, be sure to checkout the README
Other Methods
+ instance
This fetches the default SDK instance. Recommended if you are only logging events to a single app.
+ (Amplitude *)instance
Return Value
the default Amplitude SDK instance
Discussion
This fetches the default SDK instance. Recommended if you are only logging events to a single app.
Declared In
Amplitude.h
+ instanceWithName:
This fetches a named SDK instance. Use this if logging events to multiple Amplitude apps.
+ (Amplitude *)instanceWithName:(NSString *)instanceName
Parameters
instanceName |
the name of the SDK instance to fetch. |
---|
Return Value
the Amplitude SDK instance corresponding to instanceName
Discussion
This fetches a named SDK instance. Use this if logging events to multiple Amplitude apps.
Declared In
Amplitude.h
– initializeApiKey:
Initializes the Amplitude instance with your Amplitude API key
- (void)initializeApiKey:(NSString *)apiKey
Parameters
apiKey |
Your Amplitude key obtained from your dashboard at https://amplitude.com/settings |
---|
Discussion
Initializes the Amplitude instance with your Amplitude API key
We recommend you first initialize your class within your “didFinishLaunchingWithOptions” method inside your app delegate.
Note: this is required before you can log any events.
Declared In
Amplitude.h
– initializeApiKey:userId:setUserId:
SetUserId: client explicitly initialized with a userId (can be nil). If setUserId is NO, then attempt to load userId from saved eventsData.
- (void)initializeApiKey:(NSString *)apiKey userId:(NSString *)userId setUserId:(BOOL)setUserId
Discussion
SetUserId: client explicitly initialized with a userId (can be nil). If setUserId is NO, then attempt to load userId from saved eventsData.
Declared In
Amplitude.m
– checkInForeground
Manually check in and set the forground related settings including dynamic config and sesstion. Need to be called manually when onEnterForeground if deferCheckInForeground = true.
- (void)checkInForeground
Discussion
Manually check in and set the forground related settings including dynamic config and sesstion. Need to be called manually when onEnterForeground if deferCheckInForeground = true.
Declared In
Amplitude.h
– runOnBackgroundQueue:
Run a block in the background. If already in the background, run immediately.
- (BOOL)runOnBackgroundQueue:(void ( ^ ) ( void ))block
Discussion
Run a block in the background. If already in the background, run immediately.
Declared In
Amplitude.m
– runSynchronouslyOnMainQueue:
Run a block on the main thread. If already on the main thread, run immediately.
- (void)runSynchronouslyOnMainQueue:(void ( ^ ) ( void ))block
Discussion
Run a block on the main thread. If already on the main thread, run immediately.
Declared In
Amplitude.m
– logEvent:
Tracks an event. Events are saved locally.
- (void)logEvent:(NSString *)eventType
Parameters
eventType |
The name of the event you wish to track. |
---|
Discussion
Tracks an event. Events are saved locally.
Uploads are batched to occur every 30 events or every 30 seconds (whichever comes first), as well as on app close.
See Also
Declared In
Amplitude.h
– logEvent:withEventProperties:
Tracks an event. Events are saved locally.
- (void)logEvent:(NSString *)eventType withEventProperties:(NSDictionary *)eventProperties
Parameters
eventType |
The name of the event you wish to track. |
---|---|
eventProperties |
You can attach additional data to any event by passing a NSDictionary object with property: value pairs. |
Discussion
Tracks an event. Events are saved locally.
Uploads are batched to occur every 30 events or every 30 seconds (whichever comes first), as well as on app close.
See Also
Declared In
Amplitude.h
– logEvent:withEventProperties:outOfSession:
Tracks an event. Events are saved locally.
- (void)logEvent:(NSString *)eventType withEventProperties:(NSDictionary *)eventProperties outOfSession:(BOOL)outOfSession
Parameters
eventType |
The name of the event you wish to track. |
---|---|
eventProperties |
You can attach additional data to any event by passing a NSDictionary object with property: value pairs. |
outOfSession |
If YES, will track the event as out of session. Useful for push notification events. |
Discussion
Tracks an event. Events are saved locally.
Uploads are batched to occur every 30 events or every 30 seconds (whichever comes first), as well as on app close.
See Also
Declared In
Amplitude.h
– logEvent:withEventProperties:withGroups:
Tracks an event. Events are saved locally.
- (void)logEvent:(NSString *)eventType withEventProperties:(NSDictionary *)eventProperties withGroups:(NSDictionary *)groups
Parameters
eventType |
The name of the event you wish to track. |
---|---|
eventProperties |
You can attach additional data to any event by passing a NSDictionary object with property: value pairs. |
groups |
You can specify event-level groups for this user by passing a NSDictionary object with groupType: groupName pairs. Note the keys need to be strings, and the values can either be strings or an array of strings. |
Discussion
Tracks an event. Events are saved locally.
Uploads are batched to occur every 30 events or every 30 seconds (whichever comes first), as well as on app close.
See Also
Declared In
Amplitude.h
– logEvent:withEventProperties:withGroups:outOfSession:
Tracks an event. Events are saved locally.
- (void)logEvent:(NSString *)eventType withEventProperties:(NSDictionary *)eventProperties withGroups:(NSDictionary *)groups outOfSession:(BOOL)outOfSession
Parameters
eventType |
The name of the event you wish to track. |
---|---|
eventProperties |
You can attach additional data to any event by passing a NSDictionary object with property: value pairs. |
groups |
You can specify event-level groups for this user by passing a NSDictionary object with groupType: groupName pairs. Note the keys need to be strings, and the values can either be strings or an array of strings. |
outOfSession |
If YES, will track the event as out of session. Useful for push notification events. |
Discussion
Tracks an event. Events are saved locally.
Uploads are batched to occur every 30 events or every 30 seconds (whichever comes first), as well as on app close.
Declared In
Amplitude.h
– logEvent:withEventProperties:withGroups:withLongLongTimestamp:outOfSession:
Tracks an event. Events are saved locally.
- (void)logEvent:(NSString *)eventType withEventProperties:(NSDictionary *)eventProperties withGroups:(NSDictionary *)groups withLongLongTimestamp:(long long)longLongTimestamp outOfSession:(BOOL)outOfSession
Parameters
eventType |
The name of the event you wish to track. |
---|---|
eventProperties |
You can attach additional data to any event by passing a NSDictionary object with property: value pairs. |
groups |
You can specify event-level groups for this user by passing a NSDictionary object with groupType: groupName pairs. Note the keys need to be strings, and the values can either be strings or an array of strings. |
longLongTimestamp |
You can specify a custom timestamp by passing the milliseconds since epoch UTC time as a long long. |
outOfSession |
If YES, will track the event as out of session. Useful for push notification events. |
Discussion
Tracks an event. Events are saved locally.
Uploads are batched to occur every 30 events or every 30 seconds (whichever comes first), as well as on app close.
Declared In
Amplitude.h
– logEvent:withEventProperties:withGroups:withTimestamp:outOfSession:
Tracks an event. Events are saved locally.
- (void)logEvent:(NSString *)eventType withEventProperties:(NSDictionary *)eventProperties withGroups:(NSDictionary *)groups withTimestamp:(NSNumber *)timestamp outOfSession:(BOOL)outOfSession
Parameters
eventType |
The name of the event you wish to track. |
---|---|
eventProperties |
You can attach additional data to any event by passing a NSDictionary object with property: value pairs. |
groups |
You can specify event-level groups for this user by passing a NSDictionary object with groupType: groupName pairs. Note the keys need to be strings, and the values can either be strings or an array of strings. |
timestamp |
You can specify a custom timestamp by passing an NSNumber representing the milliseconds since epoch UTC time. We recommend using [NSNumber numberWithLongLong:milliseconds] to create the value. If nil is passed in, then the event will be timestamped with the current time. |
outOfSession |
If YES, will track the event as out of session. Useful for push notification events. |
Discussion
Tracks an event. Events are saved locally.
Uploads are batched to occur every 30 events or every 30 seconds (whichever comes first), as well as on app close.
Declared In
Amplitude.h
– logRevenue:
Tracks revenue.
- (void)logRevenue:(NSNumber *)amount
Parameters
amount |
The amount of revenue to track, e.g. “3.99”. |
---|
Discussion
Tracks revenue.
To track revenue from a user, call [[Amplitude instance] logRevenue:[NSNumber numberWithDouble:3.99]] each time the user generates revenue. logRevenue: takes in an NSNumber with the dollar amount of the sale as the only argument. This allows us to automatically display data relevant to revenue on the Amplitude website, including average revenue per daily active user (ARPDAU), 7, 30, and 90 day revenue, lifetime value (LTV) estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts.
See Also
Declared In
Amplitude.h
– logRevenue:quantity:price:
Tracks revenue. This allows us to automatically display data relevant to revenue on the Amplitude website, including average revenue per daily active user (ARPDAU), 7, 30, and 90 day revenue, lifetime value (LTV) estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts.
- (void)logRevenue:(NSString *)productIdentifier quantity:(NSInteger)quantity price:(NSNumber *)price
Parameters
productIdentifier |
The identifier for the product in the transaction, e.g. “com.amplitude.productId” |
---|---|
quantity |
The number of products in the transaction. Revenue amount is calculated as quantity * price |
price |
The price of the products in the transaction. Revenue amount is calculated as quantity * price |
Discussion
Tracks revenue. This allows us to automatically display data relevant to revenue on the Amplitude website, including average revenue per daily active user (ARPDAU), 7, 30, and 90 day revenue, lifetime value (LTV) estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts.
Declared In
Amplitude.h
– logRevenue:quantity:price:receipt:
Tracks revenue. This allows us to automatically display data relevant to revenue on the Amplitude website, including average revenue per daily active user (ARPDAU), 7, 30, and 90 day revenue, lifetime value (LTV) estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts.
- (void)logRevenue:(NSString *)productIdentifier quantity:(NSInteger)quantity price:(NSNumber *)price receipt:(NSData *)receipt
Parameters
productIdentifier |
The identifier for the product in the transaction, e.g. “com.amplitude.productId” |
---|---|
quantity |
The number of products in the transaction. Revenue amount is calculated as quantity * price |
price |
The price of the products in the transaction. Revenue amount is calculated as quantity * price |
receipt |
The receipt data from the App Store. Required if you want to verify this revenue event. |
Discussion
Tracks revenue. This allows us to automatically display data relevant to revenue on the Amplitude website, including average revenue per daily active user (ARPDAU), 7, 30, and 90 day revenue, lifetime value (LTV) estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts.
For validating revenue, use [[Amplitude instance] logRevenue:@“com.company.app.productId” quantity:1 price:[NSNumber numberWithDouble:3.99] receipt:transactionReceipt]
Declared In
Amplitude.h
– logRevenueV2:
Tracks revenue - API v2. This uses the AMPRevenue
object to store transaction properties such as quantity, price, and revenue type. This is the recommended method for tracking revenue in Amplitude.
- (void)logRevenueV2:(AMPRevenue *)revenue
Parameters
revenue |
AMPRevenue object revenue object contains all revenue information |
---|
Discussion
Tracks revenue - API v2. This uses the AMPRevenue
object to store transaction properties such as quantity, price, and revenue type. This is the recommended method for tracking revenue in Amplitude.
For validating revenue, make sure the receipt data is set on the AMPRevenue object.
To track revenue from a user, create an AMPRevenue object each time the user generates revenue, and set the revenue properties (productIdentifier, price, quantity). logRevenuev2: takes in an AMPRevenue object. This allows us to automatically display data relevant to revenue on the Amplitude website, including average revenue per daily active user (ARPDAU), 7, 30, and 90 day revenue, lifetime value (LTV) estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts.
See Also
Declared In
Amplitude.h
– continueUserActivity:
Call to send the Deep Link Opened event, only when defaultTracking.deepLinks is enabled.
- (void)continueUserActivity:(NSUserActivity *)activity
Discussion
Call to send the Deep Link Opened event, only when defaultTracking.deepLinks is enabled.
Declared In
Amplitude.h
– uploadEvents
Manually forces the instance to immediately upload all unsent events.
- (void)uploadEvents
Discussion
Manually forces the instance to immediately upload all unsent events.
Events are saved locally. Uploads are batched to occur every 30 events and every 30 seconds, as well as on app close. Use this method to force the class to immediately upload all queued events.
Declared In
Amplitude.h
– startOrContinueSessionNSNumber:inForeground:
Creates a new session if we are in the background and the current session is expired or if there is no current session ID]. Otherwise extends the session.
- (BOOL)startOrContinueSessionNSNumber:(NSNumber *)timestamp inForeground:(BOOL)inForeground
Discussion
Creates a new session if we are in the background and the current session is expired or if there is no current session ID]. Otherwise extends the session.
Returns YES if a new session was created.
Declared In
Amplitude.m
– startOrContinueSession:
Call to check if the SDK is ready to start a new session at timestamp. Returns YES if a new session was started, otherwise NO and current session is extended. Only use if you know what you are doing. Recommended to use current time in UTC milliseconds for timestamp.
- (BOOL)startOrContinueSession:(long long)timestamp
Discussion
Call to check if the SDK is ready to start a new session at timestamp. Returns YES if a new session was started, otherwise NO and current session is extended. Only use if you know what you are doing. Recommended to use current time in UTC milliseconds for timestamp.
Declared In
Amplitude.h
– setSessionId:
Sets the session ID in memory and persists it to disk.
- (void)setSessionId:(long long)timestamp
Discussion
Sets the session ID in memory and persists it to disk.
Declared In
Amplitude.m
– refreshSessionTime:
Update the session timer if there’s a running session.
- (void)refreshSessionTime:(NSNumber *)timestamp
Discussion
Update the session timer if there’s a running session.
Declared In
Amplitude.m
– identify:
Update user properties using operations provided via Identify API.
- (void)identify:(AMPIdentify *)identify
Parameters
identify |
An AMPIdentify object with the intended user property operations |
---|
Discussion
Update user properties using operations provided via Identify API.
To update user properties, first create an AMPIdentify object. For example if you wanted to set a user’s gender, and then increment their karma count by 1, you would do:
AMPIdentify *identify = [[[AMPIdentify identify] set:@"gender" value:@"male"] add:@"karma" value:[NSNumber numberWithInt:1]];
Then you would pass this AMPIdentify object to the identify function to send to the server:
[[Amplitude instance] identify:identify];
Declared In
Amplitude.h
– identify:outOfSession:
Update user properties using operations provided via Identify API. If outOfSession is YES
then the identify event is logged with a session id of -1 and does not trigger any session-handling logic.
- (void)identify:(AMPIdentify *)identify outOfSession:(BOOL)outOfSession
Parameters
identify |
An AMPIdentify object with the intended user property operations |
---|---|
outOfSession |
Whether to log identify event out of session |
Discussion
Update user properties using operations provided via Identify API. If outOfSession is YES
then the identify event is logged with a session id of -1 and does not trigger any session-handling logic.
To update user properties, first create an AMPIdentify object. For example if you wanted to set a user’s gender, and then increment their karma count by 1, you would do:
AMPIdentify *identify = [[[AMPIdentify identify] set:@“gender” value:@“male”] add:@“karma” value:[NSNumber numberWithInt:1]];
Then you would pass this AMPIdentify object to the identify function to send to the server:
[[Amplitude instance] identify:identify outOfSession:YES];
Declared In
Amplitude.h
– setUserProperties:
Adds properties that are tracked on the user level.
- (void)setUserProperties:(NSDictionary *)userProperties
Parameters
userProperties |
An NSDictionary containing any additional data to be tracked. |
---|
Discussion
Adds properties that are tracked on the user level.
Note: Property keys must be NSString
objects and values must be serializable.
Declared In
Amplitude.h
– setUserProperties:replace:
Adds properties that are tracked on the user level.
- (void)setUserProperties:(NSDictionary *)userProperties replace:(BOOL)replace
Parameters
userProperties |
An NSDictionary containing any additional data to be tracked. |
---|---|
replace |
In earlier versions of this SDK, this replaced the in-memory userProperties dictionary with the input, but now userProperties are no longer stored in memory, so this parameter does nothing. |
Discussion
Adds properties that are tracked on the user level.
Note: Property keys must be NSString
objects and values must be serializable.
Declared In
Amplitude.h
– clearUserProperties
Clears all properties that are tracked on the user level.
- (void)clearUserProperties
Discussion
Clears all properties that are tracked on the user level.
Note: the result is irreversible!
See Also
Declared In
Amplitude.h
– setGroup:groupName:
Adds a user to a group or groups. You need to specify a groupType and groupName(s).
- (void)setGroup:(NSString *)groupType groupName:(NSObject *)groupName
Parameters
groupType |
You need to specify a group type (for example “orgId”). |
---|---|
groupName |
The value for the group name, can be a string or an array of strings, (for example for groupType orgId, the groupName would be the actual id number, like 15). |
Discussion
Adds a user to a group or groups. You need to specify a groupType and groupName(s).
For example you can group people by their organization. In that case groupType is “orgId”, and groupName would be the actual ID(s). groupName can be a string or an array of strings to indicate a user in multiple groups.
You can also call setGroup multiple times with different groupTypes to track multiple types of groups (up to 5 per app).
Note: this will also set groupType: groupName as a user property.
See Also
Declared In
Amplitude.h
– setTrackingOptions:
By default the iOS SDK will track several user properties such as carrier, city, country, ip_address, language, platform, etc. You can use the provided AMPTrackingOptions interface to customize and disable individual fields.
- (void)setTrackingOptions:(AMPTrackingOptions *)options
Discussion
By default the iOS SDK will track several user properties such as carrier, city, country, ip_address, language, platform, etc. You can use the provided AMPTrackingOptions interface to customize and disable individual fields.
Note: Each operation on the AMPTrackingOptions object returns the same instance which allows you to chain multiple operations together.
AMPTrackingOptions *options = [[[[AMPTrackingOptions options] disableCity] disableIPAddress] disablePlatform];
[[Amplitude instance] setTrackingOptions:options];
Declared In
Amplitude.h
– enableCoppaControl
Enable COPPA (Children’s Online Privacy Protection Act) restrictions on IDFA, IDFV, city, IP address and location tracking. This can be used by any customer that does not want to collect IDFA, IDFV, city, IP address and location tracking.
- (void)enableCoppaControl
Discussion
Enable COPPA (Children’s Online Privacy Protection Act) restrictions on IDFA, IDFV, city, IP address and location tracking. This can be used by any customer that does not want to collect IDFA, IDFV, city, IP address and location tracking.
Declared In
Amplitude.h
– disableCoppaControl
Disable COPPA (Children’s Online Privacy Protection Act) restrictions on IDFA, IDFV, city, IP address and location tracking.
- (void)disableCoppaControl
Discussion
Disable COPPA (Children’s Online Privacy Protection Act) restrictions on IDFA, IDFV, city, IP address and location tracking.
Declared In
Amplitude.h
– setUserId:
– setUserId:startNewSession:
Sets the userId. If startNewSession is true, the previous session for the previous user will be terminated and a new session will begin for the new userId.
- (void)setUserId:(NSString *)userId startNewSession:(BOOL)startNewSession
Parameters
userId |
If your app has its own login system that you want to track users with, you can set the userId. |
---|---|
startNewSession |
Terminates previous user session and creates a new one for the new user |
Discussion
Sets the userId. If startNewSession is true, the previous session for the previous user will be terminated and a new session will begin for the new userId.
See Also
Declared In
Amplitude.h
– setOptOut:
Enables tracking opt out.
- (void)setOptOut:(BOOL)enabled
Parameters
enabled |
Whether tracking opt out should be enabled or disabled. |
---|
Discussion
Enables tracking opt out.
If the user wants to opt out of all tracking, use this method to enable opt out for them. Once opt out is enabled, no events will be saved locally or sent to the server. Calling this method again with enabled set to NO will turn tracking back on for the user.
Declared In
Amplitude.h
– setOffline:
Disables sending logged events to Amplitude servers.
- (void)setOffline:(BOOL)offline
Parameters
offline |
Whether logged events should be sent to Amplitude servers. |
---|
Discussion
Disables sending logged events to Amplitude servers.
If you want to stop logged events from being sent to Amplitude severs, use this method to set the client to offline. Once offline is enabled, logged events will not be sent to the server until offline is disabled. Calling this method again with offline set to NO will allow events to be sent to server and the client will attempt to send events that have been queued while offline.
Declared In
Amplitude.h
– setServerUrl:
Sends events to a different URL other than kAMPEventLogUrl. Used for proxy servers
- (void)setServerUrl:(NSString *)serverUrl
Discussion
Sends events to a different URL other than kAMPEventLogUrl. Used for proxy servers
We now have a new method setServerZone. To send data to Amplitude’s EU servers, recommend to use setServerZone method like [client setServerZone:EU]
Declared In
Amplitude.h
– setContentTypeHeader:
Sets Content-Type header for event sending requests
- (void)setContentTypeHeader:(NSString *)contentType
Discussion
Sets Content-Type header for event sending requests
Declared In
Amplitude.h
– updateEventUploadMaxBatchSize:
Sets event upload max batch size. This controls the maximum number of events sent with each upload request.
- (void)updateEventUploadMaxBatchSize:(int)eventUploadMaxBatchSize
Parameters
eventUploadMaxBatchSize |
Set the event upload max batch size |
---|
Discussion
Sets event upload max batch size. This controls the maximum number of events sent with each upload request.
Declared In
Amplitude.h
– optOut
Whether or to opt the current user out of tracking. If true then this blocks the logging of any events and properties, and blocks the sending of events to Amplitude servers.
- (BOOL)optOut
Discussion
Whether or to opt the current user out of tracking. If true then this blocks the logging of any events and properties, and blocks the sending of events to Amplitude servers.
Declared In
Amplitude.h
– setDeviceId:
– regenerateDeviceId
Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you are doing. This can be used in conjunction with setUserId:nil to anonymize users after they log out. With a nil userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
- (void)regenerateDeviceId
Discussion
Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you are doing. This can be used in conjunction with setUserId:nil to anonymize users after they log out. With a nil userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
See Also
Declared In
Amplitude.h
– useAdvertisingIdForDeviceId
Uses advertisingIdentifier instead of identifierForVendor as the device ID
- (void)useAdvertisingIdForDeviceId
Discussion
Uses advertisingIdentifier instead of identifierForVendor as the device ID
Apple prohibits the use of advertisingIdentifier if your app does not have advertising. Useful for tying together data from advertising campaigns to anlaytics data.
NOTE: Must be called before initializeApiKey: is called to function.
Declared In
Amplitude.h
– setServerZone:
Set Amplitude Server Zone, switch to zone related configuration, including dynamic configuration and server url. To send data to Amplitude’s EU servers, you need to configure the serverZone to EU like [client setServerZone:EU]
- (void)setServerZone:(AMPServerZone)serverZone
Discussion
Set Amplitude Server Zone, switch to zone related configuration, including dynamic configuration and server url. To send data to Amplitude’s EU servers, you need to configure the serverZone to EU like [client setServerZone:EU]
Declared In
Amplitude.h
– setServerZone:updateServerUrl:
Set Amplitude Server Zone, switch to zone related configuration, including dynamic configuration and server url. If updateServerUrl is true, including server url as well. Recommend to keep updateServerUrl to be true for alignment.
- (void)setServerZone:(AMPServerZone)serverZone updateServerUrl:(BOOL)updateServerUrl
Discussion
Set Amplitude Server Zone, switch to zone related configuration, including dynamic configuration and server url. If updateServerUrl is true, including server url as well. Recommend to keep updateServerUrl to be true for alignment.
Declared In
Amplitude.h
– addEventMiddleware:
Adds a new middleware function to run on each logEvent() call prior to sending to Amplitude.
- (void)addEventMiddleware:(id<AMPMiddleware> _Nonnull)middleware
Discussion
Adds a new middleware function to run on each logEvent() call prior to sending to Amplitude.
Declared In
Amplitude.h
– removeEventMiddleware:
Removes an existing middleware function to run on each logEvent() call prior to sending to Amplitude.
- (void)removeEventMiddleware:(id<AMPMiddleware>)middleware
Discussion
Removes an existing middleware function to run on each logEvent() call prior to sending to Amplitude.
Declared In
Amplitude.h
– setIdentifyUploadPeriodSeconds:
The amount of time after an identify is logged that identify events will be batched before being uploaded to the server. The default is 30 seconds.
- (BOOL)setIdentifyUploadPeriodSeconds:(int)uploadPeriodSeconds
Discussion
The amount of time after an identify is logged that identify events will be batched before being uploaded to the server. The default is 30 seconds.
Declared In
Amplitude.m
– disableIdentifyBatching:
Don’t.
- (void)disableIdentifyBatching:(BOOL)disable
Discussion
Don’t.
Declared In
Amplitude.m
– getDeviceId
Fetches the deviceId, a unique identifier shared between multiple users using the same app on the same device.
- (NSString *)getDeviceId
Return Value
the deviceId.
Discussion
Fetches the deviceId, a unique identifier shared between multiple users using the same app on the same device.
Declared In
Amplitude.h
– getSessionId
Fetches the current sessionId, an identifier used by Amplitude to group together events tracked during the same session.
- (long long)getSessionId
Return Value
the current session id
Discussion
Fetches the current sessionId, an identifier used by Amplitude to group together events tracked during the same session.
See Also
Declared In
Amplitude.h
– printEventsCount
Prints the number of events in the queue.
- (void)printEventsCount
Discussion
Prints the number of events in the queue.
Debugging method to find out how many events are being stored locally on the device.
Declared In
Amplitude.h
– upgradePrefs
Move all preference data from the legacy name to the new, static name if needed.
- (BOOL)upgradePrefs
Discussion
Move all preference data from the legacy name to the new, static name if needed.
Data used to be in the NSCachesDirectory, which would sometimes be cleared unexpectedly, resulting in data loss. We move the data from NSCachesDirectory to the current location in NSLibraryDirectory.
Declared In
Amplitude.m
Other Methods
apiKey
API key for your Amplitude App.
@property (nonatomic, copy, readonly) NSString *apiKey
Discussion
API key for your Amplitude App.
Declared In
Amplitude.h
userId
Identifier for the current user.
@property (nonatomic, copy, readonly, nullable) NSString *userId
Discussion
Identifier for the current user.
Declared In
Amplitude.h
deviceId
Identifier for the current device.
@property (nonatomic, copy, readonly) NSString *deviceId
Discussion
Identifier for the current device.
Declared In
Amplitude.h
useDynamicConfig
Turning this flag on will find the best server url automatically based on users' geo location.
Note:
1. If you have your own proxy server and use setServerUrl
API, please leave this off.
2. If you have users in China Mainland, we suggest you turn this on.
@property (nonatomic, assign, readwrite) BOOL useDynamicConfig
Discussion
Turning this flag on will find the best server url automatically based on users' geo location.
Note:
1. If you have your own proxy server and use setServerUrl
API, please leave this off.
2. If you have users in China Mainland, we suggest you turn this on.
Declared In
Amplitude.h
Configurable SDK thresholds and parameters
eventUploadThreshold
The maximum number of events that can be stored locally before forcing an upload. The default is 30 events.
@property (nonatomic, assign) int eventUploadThreshold
Discussion
The maximum number of events that can be stored locally before forcing an upload. The default is 30 events.
Declared In
Amplitude.h
eventUploadMaxBatchSize
The maximum number of events that can be uploaded in a single request. The default is 100 events.
@property (nonatomic, assign) int eventUploadMaxBatchSize
Discussion
The maximum number of events that can be uploaded in a single request. The default is 100 events.
Declared In
Amplitude.h
eventMaxCount
The maximum number of events that can be stored locally. The default is 1000 events.
@property (nonatomic, assign) int eventMaxCount
Discussion
The maximum number of events that can be stored locally. The default is 1000 events.
Declared In
Amplitude.h
eventUploadPeriodSeconds
The amount of time after an event is logged that events will be batched before being uploaded to the server. The default is 30 seconds.
@property (nonatomic, assign) int eventUploadPeriodSeconds
Discussion
The amount of time after an event is logged that events will be batched before being uploaded to the server. The default is 30 seconds.
Declared In
Amplitude.h
minTimeBetweenSessionsMillis
When a user closes and reopens the app within minTimeBetweenSessionsMillis milliseconds, the reopen is considered part of the same session and the session continues. Otherwise, a new session is created. The default is 5 minutes.
@property (nonatomic, assign) long minTimeBetweenSessionsMillis
Discussion
When a user closes and reopens the app within minTimeBetweenSessionsMillis milliseconds, the reopen is considered part of the same session and the session continues. Otherwise, a new session is created. The default is 5 minutes.
Declared In
Amplitude.h
)
Whether to automatically log start and end session events corresponding to the start and end of a user’s session.
@property (nonatomic, assign) BOOL trackingSessionEvents DEPRECATED_MSG_ATTRIBUTE ( "Use `defaultTracking.sessions` instead" )
Discussion
Whether to automatically log start and end session events corresponding to the start and end of a user’s session.
Declared In
Amplitude.h
defaultTracking
Whether to enable the default events: - sessions tracking, replacing the previous trackingSessionEvents, including session_start, session_end, default to disabled. - appLifecycles tracking, including Application Installed, Application Updated, Application Opened, Application Backgrounded, default to disabled. - deepLinks tracking, including Deep Link Opened, note you will still need to call continueUserActivity or openURL method manually, default to disabled. - screenViews tracking, including Screen Viewed, default to disabled.
@property (nonatomic, strong) AMPDefaultTrackingOptions *defaultTracking
Discussion
Whether to enable the default events: - sessions tracking, replacing the previous trackingSessionEvents, including session_start, session_end, default to disabled. - appLifecycles tracking, including Application Installed, Application Updated, Application Opened, Application Backgrounded, default to disabled. - deepLinks tracking, including Deep Link Opened, note you will still need to call continueUserActivity or openURL method manually, default to disabled. - screenViews tracking, including Screen Viewed, default to disabled.
Declared In
Amplitude.h
libraryName
Library name is default as amplitude-ios
.
Notice: You will only want to set it when following conditions are met.
1. You develop your own library which bridges Amplitude iOS native library.
2. You want to track your library as one of the data sources.
@property (nonatomic, copy, nullable) NSString *libraryName
Discussion
Library name is default as amplitude-ios
.
Notice: You will only want to set it when following conditions are met.
1. You develop your own library which bridges Amplitude iOS native library.
2. You want to track your library as one of the data sources.
Declared In
Amplitude.h
libraryVersion
Library version is default as the latest Amplitude iOS SDK version. Notice: You will only want to set it when following conditions are met. 1. You develop your own library which bridges Amplitude iOS native library. 2. You want to track your library as one of the data sources.
@property (nonatomic, copy, nullable) NSString *libraryVersion
Discussion
Library version is default as the latest Amplitude iOS SDK version. Notice: You will only want to set it when following conditions are met. 1. You develop your own library which bridges Amplitude iOS native library. 2. You want to track your library as one of the data sources.
Declared In
Amplitude.h
adSupportBlock
Sets a block to be called when IDFA / AdSupport identifier is created. This is to allow for apps that do not want ad tracking to pass App Store guidelines in certain categories while still allowing apps that do ad tracking to continue to function. This block will be called repeatedly during the life of the application as IDFA is needed.
@property (nonatomic, strong, nullable) AMPAdSupportBlock adSupportBlock
Discussion
Sets a block to be called when IDFA / AdSupport identifier is created. This is to allow for apps that do not want ad tracking to pass App Store guidelines in certain categories while still allowing apps that do ad tracking to continue to function. This block will be called repeatedly during the life of the application as IDFA is needed.
This achieve the previous SDK behavior use the example as follows. It assumes you’ve handled any setup and dialogs necessary to receive permissions from the user.
Example: amplitude.adSupportBlock = ^{ return [[ASIdentifierManager sharedManager] advertisingIdentifier]; };
Declared In
Amplitude.h
locationInfoBlock
Sets a block to be called when location (latitude, longitude) information can be passed into an event. This is to allow for apps that do not want location tracking to function without defining location permission while still allowing apps that do location tracking to continue to function. This block will be called repeatedly when location information is needed for constructing an event.
@property (nonatomic, strong, nullable) AMPLocationInfoBlock locationInfoBlock
Discussion
Sets a block to be called when location (latitude, longitude) information can be passed into an event. This is to allow for apps that do not want location tracking to function without defining location permission while still allowing apps that do location tracking to continue to function. This block will be called repeatedly when location information is needed for constructing an event.
Location information is a NSDictionary with 2 keys in it, “lat” and “lng”. Example: amplitude.locationInfoBlock = ^{ return @{ @“lat” : @37.7, @“lng” : @122.4 }; };
Declared In
Amplitude.h
contentTypeHeader
Content-Type header for event sending requests. Only relevant for sending events to a different URL (e.g. proxy server)
@property (nonatomic, copy, readonly) NSString *contentTypeHeader
Discussion
Content-Type header for event sending requests. Only relevant for sending events to a different URL (e.g. proxy server)
Declared In
Amplitude.h
initCompletionBlock
Sets a block to be called after completely initialized.
@property (nonatomic, strong, nullable) AMPInitCompletionBlock initCompletionBlock
Discussion
Sets a block to be called after completely initialized.
Example: typeof(amp) weak weakAmp = amp; amp.initCompletionBlock = ^(void){ NSLog(@“deviceId: %@, userId: %@”, weakAmp.deviceId, weakAmp.userId); };
Declared In
Amplitude.h
deferCheckInForeground
Defer the forground check in initializeApiKey. checkInForeground need to be manually called in order to get the right config and session info if deferCheckInForeground = true has been set.
@property (nonatomic, assign) BOOL deferCheckInForeground
Discussion
Defer the forground check in initializeApiKey. checkInForeground need to be manually called in order to get the right config and session info if deferCheckInForeground = true has been set.
Declared In
Amplitude.h