Location Tracking

You can track user's location or set it yourself by following the below steps. This data will allow you to create a geo-location-based target audience.

If you have set the SMT_IS_AUTO_FETCHED_LOCATION in meta-data tag inside the AndroidManifest file with value 1 then SDK will fetch location for events only if the application has location permission.

<meta-data
     android:name="SMT_IS_AUTO_FETCHED_LOCATION"
     android:value="1" />

If you want to manually set the location, you can use setUserLocation() method which takes the Location class object as a parameter. The location will only be the same until and unless this method gets the new location, if the location is not updated then for every event the same location will be sent and it will only reset after the app launch.

Smartech.getInstance(new WeakReference<>(context)).setUserLocation(location);
Smartech.getInstance(WeakReference(context)).setUserLocation(location)
SmartechSDK.setUserLocation(LATITUDE_DOUBLE_VALUE,  LONGITUDE_DOUBLE_VALUE);

// Sample code for reference purpose only
SmartechSDK.setUserLocation(19.0760, 72.8777);
📘

Key Points to Note

If you're using Location Tracking for Geofencing, please note the below points:

  • Geofence functionality is supported from Android SDK v3.1.11 and iOS SDK v3.1.3 onwards. Ensure to integrate location tracking steps for Android and iOS.
  • Implement location permission on the app side to get both foreground and background location permission.
  • If your app includes the location permissions in the manifest when uploading the APK to the Play Console, you must inform Google why your app needs them.
    Google requires clear justification for using these permissions. If the reason is not valid, your app may be rejected.
  • This feature is available for Native, React Native, and Flutter platforms.
  • Event tracking is available only for Android SDK.


Did this page help you?