Articles › Pushpad, Targeting Users

Geolocation with Pushpad

  • # javascript-sdk
  • # targeting
  • # web-notifications

Would you like to send web push notifications only to people located in a given place? If you use Pushpad you can implement that in different ways.

For web apps or website that require the user to sign up, you can track the user location (latitude and longitude) in your own database. Probably you already do that for other purposes.

Then when something happens:

  1. query your own database to find users (user IDs) near the specific location
  2. use the Pushpad API to send the notification to that users (IDs)

You can read more about tracking the user ID and targeting.

If you can't use the method above, for example because users don't sign up to your website, another option is to use tags (e.g. "city:crevoladossola", "zip:28865") to keep track of the user location. For example:

  • you can update the location tag using the Javascript SDK when the users type or select their location in a form
  • you can use the Javascript Geolocation API to get the coordinates and then use reverse geocoding to obtain the address details (e.g. country, city, ZIP code)
  • you can use the IP address of the visitors to get their country and city and then add some tags to their subscriptions using the Pushpad Javascript SDK

Once you have added the tags for geolocation to the subscriptions, you can use the dashboard (or the API) for sending the notifications. For places that you target frequently we also suggest to define some saved segments, so that you don't have to retype the tags manually every time.