How to Prompt for Location Tracking

Prompt Android and iOS mobile app users to allow location tracking.

Using OneSignal's In-App Messages you can easily create and customize a "soft-prompt" to ask users to grant location tracking.


See Android Location Tracking and iOS Location Tracking guidelines for frameworks to add to your app.
Location tracking permissions must be set in your AndroidManifest.xml and/or info.plist.

// Make sure you add one of the following permissions
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
//These are examples of how you may setup the app. See Apple's Guide on this:
// Example plist image:

  <string>Your message goes here</string>
    <string>Your message goes here</string>  
  <string>Your message goes here</string>
    <string>Your message goes here</string>

New In-App Message

Head to Messages > In-App > New In-App

If location tracking is required for all users of the app, you can select "Show to all users", otherwise you can show to a particular Segment or your choice. We will show how/when to trigger this prompt below.

Setup your message

When prompting for location tracking, it is best to inform your user's why this is recommended. People don't usually share their location without a good reason. Explain with concise detail on what specific functionality this provides and why they should allow location tracking.


Image showing in-app blocks and ability to add click actions alongside preview

Add the Click Action

Create a button for the user to click if they wish to allow location tracking. In the button settings, select Add Click Action and Location Permission Prompt. When the user clicks this button, OneSignal will automatically trigger the native Location Permission Prompt (required for location tracking).

If location is already being tracked, adding this Click Action will prevent the entire in-app message from showing.

The native Location Permission Prompt is required by Android and iOS for location tracking. Showing the native prompt and being denied limits the amount of times you can show it. By adding this pre-prompt it allows you to prompt the user as many times as required for opt-in.


Image showing in-app blocks and ability to add click actions

Trigger the In-App Message

You can trigger this message any time you like. However, if the device has already allowed location tracking permissions, the entire in-app message will not show to the user until location tracking has been disabled.

Trigger After Time In-App

For example, if you want to trigger this after being in the app for 30 seconds, set the trigger like so:


Image showing in-app trigger settings

Programmatic Triggers

Under the Triggers section select In-App Trigger and set location_prompt is true for example.

You will add this "key": "value" trigger programmatically in the app with addTrigger method soon.


Image showing in-app trigger with location prompt

Trigger The Prompt

You can trigger this prompt anytime by simply use the addTrigger method.

Make sure the trigger "key" and "value" match what you added to the in-app message Trigger. In this example, we used location_prompt for the key and true for the value.

OneSignal.addTrigger("location_prompt", "true");
OneSignal.addTrigger("location_prompt", withValue: "true")
[OneSignal addTrigger:@"location_prompt" withVaue:@"true"]
OneSignal.AddTrigger("location_prompt", "true");
OneSignal.addTrigger("location_prompt", "true");
OneSignal.addTrigger("location_prompt", "true");
OneSignal.addTrigger("location_prompt", "true");