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:

  1. In every file that uses analytics, import Amplitude.h at the top #import "Amplitude.h"
  2. Be sure to initialize the API in your didFinishLaunchingWithOptions delegate [[Amplitude instance] initializeApiKey:@"YOUR_API_KEY_HERE"];
  3. Track an event anywhere in the app [[Amplitude instance] logEvent:@"EVENT_IDENTIFIER_HERE"];
  4. 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

  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

  instanceName

Name of the SDK instance (ex: no name for default instance, or custom name for a named instance)

@property (nonatomic, copy, readonly, nullable) NSString *instanceName

Discussion

Name of the SDK instance (ex: no name for default instance, or custom name for a named instance)

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.

@property (nonatomic, assign, readwrite) 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

  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 lcoally. The default is 1000 events.

@property (nonatomic, assign) int eventMaxCount

Discussion

The maximum number of events that can be stored lcoally. 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

  trackingSessionEvents

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

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

  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

  showEventExplorer

Show Amplitude Event Explorer when you’re running a debug build.

@property (nonatomic, assign, readwrite) BOOL showEventExplorer

Discussion

Show Amplitude Event Explorer when you’re running a debug build.

Declared In

Amplitude.h

Fetching Amplitude SDK instance

+ 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:(nullable 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

Initialize the Amplitude SDK with your Amplitude API Key

– 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:

Initializes the Amplitude instance with your Amplitude API key and sets a user identifier for the current user.

- (void)initializeApiKey:(NSString *)apiKey userId:(nullable NSString *)userId

Parameters

apiKey

Your Amplitude key obtained from your dashboard at https://amplitude.com/settings

userId

If your app has its own login system that you want to track users with, you can set the userId.

Discussion

Initializes the Amplitude instance with your Amplitude API key and sets a user identifier for the current user.

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

Logging Events

– 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:(nullable 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:(nullable 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.

Declared In

Amplitude.h

– logEvent:withEventProperties:withGroups:

Tracks an event. Events are saved locally.

- (void)logEvent:(NSString *)eventType withEventProperties:(nullable NSDictionary *)eventProperties withGroups:(nullable 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.

Declared In

Amplitude.h

– logEvent:withEventProperties:withGroups:outOfSession:

Tracks an event. Events are saved locally.

- (void)logEvent:(NSString *)eventType withEventProperties:(nullable NSDictionary *)eventProperties withGroups:(nullable 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:(nullable NSDictionary *)eventProperties withGroups:(nullable 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:(nullable NSDictionary *)eventProperties withGroups:(nullable 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

Logging Revenue

– 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.

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:(nullable 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:(nullable NSString *)productIdentifier quantity:(NSInteger)quantity price:(NSNumber *)price receipt:(nullable 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

User Properties and User Property Operations

– 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!

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

Setting User and Device Identifiers

– setUserId:

Sets the userId and starts a new session.

- (void)setUserId:(nullable NSString *)userId

Parameters

userId

If your app has its own login system that you want to track users with, you can set the userId.

Discussion

Sets the userId and starts a new session.

Declared In

Amplitude.h

– 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:(nullable 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.

Declared In

Amplitude.h

– setDeviceId:

Sets the deviceId.

- (void)setDeviceId:(NSString *)deviceId

Parameters

deviceId

If your app has its own system for tracking devices, you can set the deviceId.

Discussion

Sets the deviceId.

NOTE: not recommended unless you know what you are doing

Declared In

Amplitude.h

Configuring the SDK instance

– 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

– 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

– 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

Other Methods

– 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

– 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

– 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.

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.

Declared In

Amplitude.h

– setSessionId:

Sets the sessionId.

- (void)setSessionId:(long long)timestamp

Parameters

timestamp

Timestamp representing the sessionId

Discussion

Sets the sessionId.

NOTE: not recommended unless you know what you are doing

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

– 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

Other Methods

– 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

– 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

– startOrContinueSessionNSNumber:

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

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

– 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

– 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