Question
- How can I hide the Messaging widget from non-authenticated users
- How can I hide the Messaging widget from users who aren't logged in
Answer
You can use some custom javascript to prevent (hide) the Messaging widget from users who are not authenticated on your help centre or external website.
There are 2 different methods that you can use to achieve this which we'll dive into below.
Method 1:
You can deploy this method when incorporating curly braces exclusively for signed-in users. These curly braces should encompass the entire messaging widget script.
Please note that this approach is applicable to both the Header and Footer pages of your help centre or website.
{{#if signed_in}}
<INSERT MESSAGING SCRIPT HERE>
{{/if}}
Example:
Method 2:
You can employ this method when incorporating curly braces along with API code to determine the display status of the messaging widget, contingent on the user's logged-in status.
To implement this method, apply the changes beneath the original Messaging script on your help centre or website.
{{#if signed_in}}
<script type="text/javascript">
zE('messaging', 'show');
</script>
{{else}}
<script type="text/javascript">
zE('messaging', 'hide');
</script>
{{/if}}
Example: