Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
We are implementing a custom IRawPageviewLocationExtractor so we have location data in the analytics as documented here : https://documentation.umarketingsuite.com/analytics/extending-analytics/implement-an-ip-to-location-provider/
How can I get the country for the current visitor so I can show different content based on that information ?
Unfortunately there is no API at the moment to retrieve the Location of a Visitor. Locations obtained from the IRawPageviewLocationExtractor are persisted alongside the Pageview they belong to and are currently only used to render a chart in Analytics in the backoffice (Analytics > Location).
If you want to show different content to a visitor based on their location you would actually have to implement a custom segment parameter, i.e. "Location". This custom segment parameter would then show up in the segment builder:
You can then create segments based on this parameter, e.g. one for "country = Netherlands" and one for "country = Belgium" or so and use them in personalizations to customize content.
Of course a "Location" segment parameter is a good candidate to be part of the built-in UMS parameters but unfortunately we have not made this one yet. I imagine when we do we would actually require an implementation of IRawPageviewLocationExtractor and use those locations in this parameter, but if you want to implement this today you will have to create a custom one and then you could just perform the location lookup in the parameter only.
I found a away to get visitors location. I am using the GetState method on the IAnalyticsStateProvider
The model returned from that allows me to drill down to IP information and the location is part of that.
Excellent! Yes that is indeed the ILocation associated with the current IPageview so you can use that too if that is enough. If you want to allow editors to customize content in splitview as part of a personalization for example you will need a segment though.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted