Pesquisas recentes


Sem pesquisas recentes

Restrict Web Widget to Certain Users?



Publicado 20 de mar. de 2025

Hello, I am trying to restrict the web widget to only appear for users with the user tag “administrator” and it does not appear to be working.

I am repurposing one suggested for organizations: https://support.zendesk.com/hc/en-us/articles/4408820799130/comments/4967400163482

 

for (var c in HelpCenter.user) {
 if (HelpCenter.user[c].tags.includes("administrator")){
     zE('messenger', 'show');}
 else
     {zE('messenger', 'hide');}}


0

1

1 comentário

Hey there! It sounds like you're diving into some custom widget logic, which is pretty cool. Let's see if we can get this working for you.

Looking at the code snippet you've shared, it seems like you're trying to iterate through properties of the HelpCenter.user object. However, HelpCenter.user isn't structured as an array or an object you can directly loop through with a for...in loop like that to access user details E-ZPassMD

Typically, the user information, including tags, is directly accessible within the HelpCenter object. You can usually check the tags like this:

JavaScript

 

if (HelpCenter.user.tags && HelpCenter.user.tags.includes("administrator")) {
  zE('messenger', 'show');
} else {
  zE('messenger', 'hide');
}

Here's a breakdown of why this might work better:

  • HelpCenter.user.tags: This directly accesses the tags property of the HelpCenter.user object. It's likely that the tags are stored as an array here.
  • && (Logical AND): We first check if HelpCenter.user.tags exists (is not null or undefined) before trying to use the includes() method. This prevents potential errors if a user doesn't have any tags.
  • .includes("administrator"): This array method checks if the string "administrator" exists within the HelpCenter.user.tags array.

Where to put this code:

You'll typically place this JavaScript code within your Help Center's theme. The exact location might depend on your theme, but common places include:

  • script.js: If your theme has a dedicated JavaScript file.
  • document_head.hbs or header.hbs: Within the <script> tags in these template files.

 

0


Entrar para comentar.

Não encontrou o que estava procurando?

Nova publicação