Location Tracking

In many cases it’s important to log the location of a user and associate that location with other events. The mParticle SDK allows you to include detailed location information with all of your events.

There are two ways to approach location tracking:

  1. You can call the beginLocationTracking method and let the mParticle SDK collect and update location information for you. Remember to call endLocationTracking when you no longer need to track location
  2. Set the location property directly. In this case you are responsible for maintaining location updated and setting it to nil/null when no longer needed
// Begins tracking location
[[MParticle sharedInstance] beginLocationTracking:kCLLocationAccuracyThreeKilometers

// Ends tracking location
[[MParticle sharedInstance] endLocationTracking];
// Begins tracking location
                                             minDistance: 1000)

// Ends tracking location

Setting the location property directly

- (void)updateLocation:(CLLocation *)newLocation {        
    [MParticle sharedInstance].location = newLocation;    
func updateLocation(newLocation: CLLocation) -> Void {
    MParticle.sharedInstance().location = newLocation

Starting with iOS 8 not only a user has to give permission to an app to use their location, they also need to give permission when location tracking is active after the app has gone to the background (iOS 8 will prompt the user with a new location permission dialog.) The backgroundLocationTracking property enables or disables the inclusion of location information to events when your app is running on the background. The default value is YES. Setting it to NO will cause the SDK to stop including location information when your app is running in the background and resumes the inclusion of location information when the app comes back to the foreground.

This way you can fine tune the location tracking behavior and which permission dialogs are displayed by the O.S., since even apps compiled with iOS versions prior to 8 would trigger this new dialog to be displayed to a user of your app.

[MParticle sharedInstance].backgroundLocationTracking = NO;


Location tracking is not supported for tvOS.