Show web widget/answer bot only to signed-in users?

Answered

7 Comments

  • Christopher Kennedy
    Zendesk Developer Advocacy
    Hi David,
     
    That snippet can work to accomplish the goal.  Are you seeing an error?  Is the widget displaying in cases where you expect it to be hidden?  Or vice versa?
     
    Best,
    0
  • David Nguyen

    Hi Christopher,

    It seems that the widget is not hiding as expected if the user is not logged in.

    Looking at the console, I believe that the culprit is that we are now using the Web SDK and not the Web Widget (Classic)

    "

    Method webWidget.hide does not exist.

    A note from Zendesk: API methods associated with the Web Widget (Classic) are still being executed on this page. This website is now using the new Web SDK (messaging experience) which no longer supports these APIs. If you don't intend to use the Web Widget (Classic), we recommend that you remove this code from your website.  Whilst not recommended, leaving them won't cause any issues. "

    Is it possible to hide the web SDK through similar code on the theme or elsewhere?

    0
  • Christopher Kennedy
    Zendesk Developer Advocacy
    Hi David,
     
    That note about the Web SDK for Messaging is correct.  There is no Hide API available at this time.  However you can work around that fact in your theme using the same signed_in helper from your post.  Instead of using it to determine when to call a show or hide API method, place the widget launch snippet inside the signed_in block:
     
    {{#if signed_in}}
    // insert launch snippet from admin settings here
    {{/if}}
     
    By doing this, the widget will only load on the page at all if the user is signed in.
     
    Best,
    0
  • William Sedgwick

    Christopher Kennedy

    Where abouts is the signed in block in the themes? 
    thank you for helping

    0
  • Guido T.
    Hello William!

    You can add this piece of code to either the footer or the header of your help centre by going to Guide admin >  Themes > Customize > Edit code > Header:


     
    I recommend adding it to the footer or header because they are present in every page of your help centre, allowing the widget code logic that we have added to work in all of it.

    Thank you!
    0
  • Stephen Marron

    Hi everyone,

    I also use the Web Widget (Classic) chat and would like it only to display for logged in Zendesk Help centre users.

    In admin > channels > chat settings, the 'Add to Help Centre' option is checked and I am using a customised copy of the 'Copenhagen' theme.

    Is there an option in admin to enable chat for logged in users only or do I need to disable the 'Add to Help Centre' option and manually add the chat embed snippet to my custom there footer.hbs using the {{#if signed_in}} tag as outlined above?

    What is the best method to achieve the desired outcome? 

    Thank you,

    0
  • Stephen Marron

    UPDATE:

    I opted for the below working solution:

    1. Turn off 'Add to Help Centre' in admin > channels > chat settings
    2. Copy the chat embed snippet from admin > channels > chat settings
    3. Go to Guide Admin > Themes > click 'customise' on the current active theme.
    4. Click 'Edit code' in bottom right of screen
    5. Open/edit templates/footer.hbs and paste the follow code at the bottom of the file
    6. Publish & test
    {{#if signed_in}}
    <script id="ze-snippet" src="your-specific-zd-chat-url-here"> </script>
    {{/if}}
    0

Please sign in to leave a comment.

Powered by Zendesk