Using Geofencing in mobile apps

With geofencing in mobile apps, you can run location-based ads with extremely high precision. This boosts campaign KPIs, as Smart AdServer was able to demonstrate: click rates of campaigns increased by 40% to up to 100% when compared with campaigns without geofencing.



A Geofence is a circle (2) around an exact location (1). The area around the exact location is also called catchment area.

Examples for usage

  • A retailer with outlets across the country can serve geo-targeted ads to users stepping into the geofence around all of its stores.
  • At special event venues, an advertiser can target ads to any user within a certain radius around the venue.

Smart AdServer supports geofencing:

  • in native apps only; you must use one of the SDKs
  • in iOS SDK v 4.0 or higher and in Android SDK v 2.0 or higher
  • for the script template MRAID Interstitial

GPS data in insertions and forecast

Geofencing requires the end user to accept sharing of GPS data. If the end users accepts, her location (longitude/latitude) is passed within the ad call.

You can restrict (target) the insertion to show it only to user who pass their GPS location. Go to the targeting tab of the insertion and enable the checkbox "Limit delivery to users enabling location-based targeting" (1).

In the Forecast, enable the option "Only users who accept sharing their GPS localization" to restrict your query to these users (2).

GPS data in insertions and forecast

The script template MRAID SDK Geofencing Interstitial

To set up geofencing campaigns, you need to use a mobile insertion and the script template MRAID SDK Geofencing Interstitial

General specifications

Specification Description
Orientation portrait
Creative rotation mode not supported
Dimensions Smartphone portrait: 720x1280
Tablet portrait: 1536x2048
Note: the SDK will resize creatives for smaller screen resolutions.
Sizes Smartphone: 200kb (max)
Tablet: 350kb (max)
Format jpg, gif, png
Miscellaneous Image can be scaled to cover the entire screen area or scaled to the largest possible size respecting both its width and height

Creatives in the insertion

  • Creative #1: displayed when the end user is within the geofence (circle around the geofencing locations);
    you can add additional creatives if you have multiple creatives for multiple geofences (example: creative #1a: "paris"; creative #1b: "marseille"); in this case, you must add an additional column in the csv file named "geofencingImageName" - see below) and add the creative's name in the column (exact matching is not needed: "marseille" in the csv file will match "marseille123" in the file name); if the column "geofencingImageName" is missing, the backup image (Creative #3) will be displayed;
  • Creative #2: contains a csv file with all the geofencing locations and (optionally) custom columns
  • Creative #3: displayed when the user is in none of the specified geofences (backup creative)
Creatives in the insertion

Locations file (.csv) specifications

Prepare a csv file as follows:

  • mandatory: name the first 2 columns (header cells): lat,lng
  • mandatory: define values for the lat (latitude) and lng (longitude) columns
  • optional: column named "geofencingImageName" in case of multiple geofence creatives (see above)
  • optional: define additional columns; example names: clickUrl,name,address,abcdef... (read about the clickUrl below)
  • save the csv file in UTF-8 encoding (to support special characters)
  • separate column headers and values using a comma (,)
  • if a value (in the column) contains a comma (,) or a semicolon (;), wrap the entire value in quotes; e. g.: "4 Boulevard Haussmann, 75009 Paris"

Example of first line of a csv file, in text mode:

48.8721020,2.3395090,[positionLatLng]&daddr=[destinationLatLng],Store 1,"4 Boulevard Haussmann, 75009 Paris"

Example of complete csv table with 4 locations:

lat lng geofencingImageName clickUrl name address
48.8721020 2.3395090 Paris[positionLatLng]&daddr=[destinationLatLng] Store 1 "4 Boulevard Haussmann, 75009 Paris"
43.296066 5.369804 Marseille[positionLatLng]&daddr=[destinationLatLng] Store 2 "68 Quai du Port, 13002 Marseille, France"
45.768148 4.833223 Lyon[positionLatLng]&daddr=[destinationLatLng] Store 3 "Rue Sainte-Catherine, 69001 Lyon, France"
43.694299 7.258766 Nice[positionLatLng]&daddr=[destinationLatLng] Store 4 "37 Prom. des Anglais, 06000 Nice, France"

Clickurl: csv file vs. user interface

You can specify the clickUrl for the creative:

  • in the csv file (in the clickUrl column, see above)
  • in the creative (edit the creative uploaded into the insertion)
  • in both

If a clickUrl is defined in the csv file, it will have priority over the clickUrl in the creative. The clickUrl in the creative will only be used, when there is no clickUrl defined in the csv file.

Targeting to users allowing location-based targeting

Geofencing only works when end users allow passing the device's longitude/latitude. Thus, you must target the insertion accordingly.

  • Go to the insertion's targeting tab
  • Enable the checkbox Limit delivery to users enabling location-based targeting
Targeting to users allowing location-based targeting

Custom macros (.csv file custom columns)

Custom macros are replaced by the appropriate value of the column. To build a customized macro, simply take the column's name enclosed in brackets, e. g. [address], [abcdef]...


  • the macro [address] will be replaced by the appropriate value in the "address" column (e. g.: 4 Boulevard Haussmann, 75009 Paris).
  • the macro [abcdef] will be replaced by the appropriate value from the "abcdef" column.

Macros related to position and distance

Macro Description
[destinationLatLng] Closest latitude/longitude from the csv file
[positionLatLng] Latitude/longitude of the user's position
[distanceInMeters] Distance in meters between the user's position and the closest location from csv file
[distanceInKilometers] Distance in kilometers between the user's position and the closest location from the csv file
[distanceInFeet] Distance in feet between the user's position and the closest location from the csv file
[distanceInMiles] Distance in miles between the user's position and the closest location from the csv file

Standard macros

The script template also supports the following standard macros:

Macro Description
[sas_deviceid] Android Advertising Id or Apple IDFA
[sas_deviceidSHA1] SHA1 hashed device ID
[sas_deviceidMD5] MD5 hashed device ID
[sas_latitude] Latitude, if available. For now, only supported in SDK. Format is culture invariant (e. g. 48.856578).
[sas_longitude] Longitude, if available. For now, only supported in SDK. Format is culture invariant (e. g. 2.351828).
[timestamp] Generates a random number; is replaced by a unix timestamp in milliseconds

Script template parameters

Parameters Default
3rd Party impression pixels n/a Field to paste a 3rd party impression counting pixels
Duration 5s Interstitial display duration (seconds)
Background color #ffffff
Close button position top right (MRAID default)
Close on click enabled
Close appearance delay (s) 0 Time until the close button is displayed.
Open in-app (Android option) disabled
Confirm before exiting (iOS option) enabled
Redirect to third party (iOS option) disabled Used for creatives with a click destination to a native iOS app (e. g. tel: or sms:). The option (a) enables iOS to manage the click to the correct native application; (b) enables Smart AdServer to count this click
Enable viewability tracking (iOS SDK >= 6.0) disabled
Viewability exposure duration (s) 1 The time the creative must be visible to be considered as a viewable impression.
Background size cover Cover: Scale the creative (image), so that it covers the entire screen area
Contain: Scale the creative (image) to the largest possible size, respecting both its width and height
Geofencing radius 500
Geofencing radius unit meter
HTML script horizontal position (%) 0
HTML script horizontal position from center
HTML script vertical position (%) 0
HTML script vertical position from center

Example 1

Ads for users located close to stores

  • for each store, define the location (longitude/latitude) in the csv file; this works for up to 10k addresses
  • define the radius in the script template's parameters (Geofencing radius, Geofencing radius unit)

=> creative #1 (main creative) is displayed for users within the radius; creative #3 (backup) for users outside the radius

Example 2

Display a custom message showing the user's position and distance to the closest store

  • edit the main creative (creative #1)
  • paste a custom HTML code into into the field Customized script


.text {background-color: #ffffff; opacity:0.7;}
<div class="text">
The store [name]<br/>is located [distanceInMiles] miles from <br/>
[address] <br/> click url: <small> [clickurl]</small>

The example above uses the macros [name], [distanceInMiles], [address] and [clickurl] in the displayed text. Each macro will be replaced by the appropriate values. The end user will see the text with the appropriate values, e. g.:

The store Starbucks, Poissonnière
is located 0,18 miles from
8-10 Rue Saint-Fiacre, 75002 Paris 
Was this article helpful?
0 out of 0 found this helpful
Powered by Zendesk