Show a section to a specific country only

Answered

9 Comments

  • Vlad
    Community Moderator
    The Wise One - 2022

    I'm interested too :) 

    0
  • Brett Bowser
    Zendesk Community Manager
    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!
    1
  • Rebeca Hernandez

    Hi Brett Bowser great, thanks for the response, will look into this option! thanks

    0
  • Vlad
    Community Moderator
    The Wise One - 2022

    it will work if a visitor is logged in, but not for anonymous visitors from a specified country. 

    1
  • Ahmed Zaid

    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

    0
  • Vlad
    Community Moderator
    The Wise One - 2022

    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? 

    0
  • Ahmed Zaid

    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.

    0
  • Vlad
    Community Moderator
    The Wise One - 2022

    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.

    0
  • Ahmed Zaid

    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.

    0

Please sign in to leave a comment.

Powered by Zendesk