How can I use Zendesk tags to hide the community in my Help Center?

Answered

9 Comments

  • Jessie Schutz
    Zendesk Team Member

    Hey Josh! Welcome to the Community!

    I'll see if one of our Community Moderators can take a look at this for you!

    0
  • Josh Vasile

    Hey Jessie, 

     

    Thank you so much! I greatly appreciate it! As long as I can get the JS to see a tag from our Zendesk, then I can take it from there, but it just seems the JS does not grab the tags as it should, and others have said works. Is there a chance the new templates (template update) may have had something to do with it? 

    0
  • Andrew Schreiner

    Hi Josh,

    This should work

    <script type="text/javascript">

    $(document).ready(function(){
    var isCustomer = false;
    HelpCenter.user.organizations.forEach(function(org){

    //replace abcd with the string you are looking for
    if($.inArray('abcd', org.tags) > -1)
    {
    isCustomer = true;
    }
    });
    console.log('Is Customer: ' + isCustomer);

    });

    </script>

    0
  • Nicole Saunders
    Zendesk Community Team

    Thanks for sharing, Andrew! Great to see our community members helping one another. 

    Hey Josh - 

    Do you mind if I edit the title of your original post so that it shows up better in search? I think other users could benefit from being able to find and read through this conversation. 

    0
  • Josh Vasile

    Hey Guys! 

    Nicole, please feel free to change the title as I have no problem helping the community learn from my situation! 

     

    Andrew, I cannot thank you enough for the help! I first added this code without the Script tags into the JS page and it did not want to work. I took it into HTML on the homepage and threw it in, and it did not want to load either. I even tried making some code for it to work and it did not want to load, is there a chance I could have set something up wrong? I tried these things: 

    In the JS page: 

    var isCustomer = false;
    HelpCenter.user.organizations.forEach(function(org){

    //replace abcd with the string you are looking for
    if($.inArray('owner', org.tags) > -1)
    {
    isCustomer = true;
    }
    });
    console.log('Is Customer: ' + isCustomer);

    });

    Then I tried this as well: 

    var isCustomer = false;
    HelpCenter.user.organizations.forEach(function(org){

    //replace abcd with the string you are looking for
    if($.inArray('owner', org.tags) > -1)
    {
    isCustomer = true;
    }
    });
    document.getElementById("helpdeskhide").remove();

    });

    helpdeskhide is simply: 

    <div id="helpdeskhide">

    <style>

    #helpdesk{
    visibility: hidden;
    }

    </style>

    </div>

     

    Is that script you gave something you actively use? I have a feeling, I have JS that I created which could be causing this not to work. 

    0
  • Andrew Schreiner

    Hi Josh, 

    I wrote this code last night and tested it to confirm it does read the values. 

    1. Do you have jquery added to your help center? This would be required for the code I wrote
    2. Did you try putting the code in the style.js file instead of directly on the home template? 
    3. If you use my original code, if you enter the developer tools (usually F12 on the browser), you should see the output of "Is Customer: true" or false depending on the tag being present.
    4. Try changing your style for #helpdesk visibility to #helpdesk{display:none;} and document.getElementById("helpdeskhide").remove(); to $('#helpdesk').show();
    0
  • Josh Vasile

    Hey Andrew! I cannot thank you enough for your help, sorry I was out of the office for the past few days. 

    I have confirmed that jquery is alive and well on our site, it successfully does all other jquery stuff and prints hello world too. 

    Something important to note, I overlooked it before, but I saw that you wanted to log to console if it was true or false, it does not show up in the console at all which is weird. 

    Thanks for all your help, I appreciate it. I feel this has something else going on within our support site if we add it to the style sheet like this: 

    var isCustomer = false;
    HelpCenter.user.organizations.forEach(function(org){

    //replace abcd with the string you are looking for
    if($.inArray('abcd', org.tags) > -1)
    {
    isCustomer = true;
    }
    });
    console.log('Is Customer: ' + isCustomer);

    });

    It will cause our other JS to not load which is strange. We will keep working on it and report back here if we and when we get the hang of it. Thanks again for your help! 

    0
  • Dustin DeMayo

    I just wanted to share how we achieved this

    let ZDtags = HelpCenter.user.tags;
    if (ZDtags.indexOf("signed in") < 0){
    // If not signed in remove commForum object
    let cobject = document.getElementById("commForum");
    cobject.style.display = "none";
    }

    0
  • Nicole Saunders
    Zendesk Community Team

    Thanks so much for coming back and sharing the answer, Dustin! 

    0

Please sign in to leave a comment.

Powered by Zendesk