Show a section to a specific country only
RespondidaHello community!
We are implementing a new feature that will be available in one country only.
We want to create how to articles on the Guide for this but since it will only be for one country, I would like to know what would be the best way to go about it, what would the best practices for this be?
Thanks in advance!
-
I'm interested too :)
-
Hey Rebeca,
Great question! I think the easiest solution would be to create a user segment for these how to articles in your Help Center. If you decide to identify these users via custom user field, or a user tag, you can then define these user segments based on that information. I hope this points you in the right direction!
Cheers!
-
Hi Brett Bowser great, thanks for the response, will look into this option! thanks
-
it will work if a visitor is logged in, but not for anonymous visitors from a specified country.
-
Hi everyone,
A possible solution is modifying your guide theme script.js to get user country by querying an external api. Then you can hide the desired section if the country does not match the intended country. Here is a minimal example to add to the end of the file:
var endpoint = 'http://ip-api.com/json/?fields=status,message,country';
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = JSON.parse(this.responseText);
if(response.status !== 'success') {
console.log('query failed: ' + response.message);
return;
}
if(response.country !== 'Singapore') {
for (section of document.querySelectorAll('section.section')) {
if (section.children[0].children[0].getAttribute('href').split('/')[4].split('-')[0] == '123456789') {
section.remove();
return;
}
}
}
}
};
xhr.open('GET', endpoint, true);
xhr.send();The code hides section with id=123456789 if the user IP is not in Singapore. This only targets sections in a category page (It assumes the help center has multiple categories that are not empty to anonymous users. Otherwise, help center behaviour changes). Keep in mind that only the section is hidden, not its articles if displayed in "promoted" or "recent activity" section.
The example also uses a free service (ip-api.com) which does not provide SSL. Hence, testing requires the browser to enable mixed or insecure content. Using a premium subscription or any other service over https solves this problem.I had fun trying to solve this use case. Hope this helps.
Regards,
Ahmed -
Hey Ahmed, that's a good solution!
The only thing is what about the search results page?
Or submit a ticket page and suggested articles?
-
It is possible to target specific articles to hide by their id using similar logic with adjustments to suit the location we are hiding it from. I can only see issues with answer bot and searching within Web widget. That's another challenge altogether.
-
Agree, but it's not that handy to hide each article compared to category or a section.
I mean on the search results page if it says eg 4 results found but we have hidden two of them, so it's another thing that should be taken care of as well. Pagination is another thing etc etc. -
It does get more complex in order to be very thorough. I think the use case has to be very compelling to justify all the changes.
Perhaps utilising translations and different locales can be a better option.
Iniciar sesión para dejar un comentario.
9 Comentarios