Does Dynamicweb have some kind of tag that show what country a user come from based by ex. IP?
We need to set currency based on the user country, and would like to know if there are something in DW we can use, or if we have to code something our selves.
Developer forum
E-mail notifications
Find out what country the user come from
Replies
Not something that is publicly available. However, it's easy to do with Geo IP: https://www.maxmind.com/en/geoip-demo
They provide an IP database and .NET classes that expose methods to convert an IP into a country code.
Imar
You could use the GeolocationService.
Example:
var ipAddress = Dynamicweb.Context.Current.Request.UserHostAddress; var results = Dynamicweb.Analytics.Utilities.GeolocationService.LookupBasic(new[] { ipAddress }); var countryCode = results.ContainsKey(ipAddress) ? results[ipAddress].CountryCode : string.Empty;
However, I'm not sure how well it performs. You might want to persist/cache this for the current user or session.
Thanks, works like a charm!
I have to advice against this solution. It makes a call everytime to a service hosted by us used for the lead tool. It is slow and cannot be guarenteed to live forever...
BR Nicolai
Do we have any alternatives to this?
In 9.6 and newer we actually track this - but there is no public available API to get hold of the data. You can get hold of Dynamicweb.Tracking.Tracker.Current - it has an internal property with the session that again has a property of the country. But it is internal. You might be able to get hold of the information using reflection.
Or more simple, you can use this one:
You must be logged in to post in the forum