Is there a way to serve in-house ads based on the current user's location?


I just wanted to check, is there a Discourse way to serve in-house ads based on the current user’s location? I understand we have: House Ads in the official Ad Plugin ready for serving the ads, but I’d just like to know if there’s a way to find the current users location via Discourse.

If there isn’t a Discourse way to do this (such as requiring a 3rd party tool) I know we have the IPs for signups as well, is there a way to use those to determine a user’s location?


Hi hyphalos! :blob_wave:

Regardless of the context of an existing or hypothetical ad plugin, there is a built-in feature for this in Disourse available from the admin view of a user profile:

The endpoint is:{user_ip}, with a GET request.

Hi @Canapin ,

Thanks for your swift response!

I attempted to make a short python script for this, but it’s only returning a webpage for me and not JSON. When I added .json to the GET URL, it’s returning just {}. However, when I make the request with the User ID ({user_id}/ip-info.json?ip={user_ip}), it does appear the users information with the IP Address.

I even attempted to visit that URL from the browser, only to get an Oops! That page doesn’t exist or is private.

FWIW, our Discourse is currently on Stable version (v3.1.1).

I just wanted to ask, do I need a MaxMind license for this to work? If not, is it possible that the endpoint provided is incorrect? I’m getting a response from /admin/users/{user_id}.json, but for some reason not getting a proper response from /admin/users/ip-info?ip={user_ip}. I just get a blank webpage from our Discourse site in HTML.

In addition, is there a link to the list of useful endpoints that Discourse provides such as the one you shared?

Thank you!

That’s because it only returns the content of{user_id}.json. It ignores the ip-info part, it’s not a valid endpoint here.

And yes, I didn’t think about that :person_facepalming: but yes, I think you probably need a Maxmind key in order to return the location.

So, to summarize:

  1. If you want to get a user’s IP, you need to make a GET request (with admin credentials) to{user_id}.json. It will return the IP among other user info.

  2. If you want to locate the IP, you need a Maxmind key (to be added in app.yml), and make a GET request to this endpoint:{user_ip} .

There’s the API documentation:
But all endpoints aren’t listed here. Discourse’s API is very easy to reverse engine, though: Reverse engineer the Discourse API. This is how I got the info here.

Thanks @Canapin , I think this is what I needed. I’ll see if I can sort out a MaxMind license and go from there. Will update this thread if I do acquire a license and re-attempt. Cheers!

1 Like

Hi @Canapin ,

I’ve acquired a free MaxMind license and the API{user_ip} . is working great, thank you!

I have an additional question, since this requires user ID to get the IP and then call this API above, what about anonymous users? What if we wanted to house serve ads to them as well, but they don’t have a user ID? Would it still be possible, or is this just strictly for signed-in users?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.