Exclude logged in agents from Zendesk search results

I’m hoping to build on the logic used in this post about differentiating between two Zendesk environments.

I’d like to include some logic in the JS API like:

     applicationId: 'APP_ID', 
     apiKey: 'API_KEY', 
     subdomain:  {{#is help_center.name 'Production Site Center'}}'prod-subdomain'{{else}}'staging-subdomain'{{/is}} , 
     analytics: {{#is help_center.user.role 'manager'}}'false'{{else}}'true'{{/is}} 

Of course, help_center.user.role 'manager' doesn’t work, or I wouldn’t be posting this as a question.

Has anyone solved this, perhaps using tips from this Zendesk post?


{{ help_center.user.role }}doesn’t exist (or isn’t available) from Zendesk’s templating engine.

What the article you linked to suggests is using the JavaScript global variable they expose, HelpCenter.
This variable is however not available yet when our code is called.
You need to wait for the document to be loaded.

document.addEventListener('DOMContentLoaded', function () { 
    applicationId: 'APP_ID',
    apiKey: 'API_KEY',
    subdomain: 'SUBDOMAIN'

That being said, the parameter you’re trying to set, analytics, is not available on this library.
See Documentation - Algolia for Zendesk for the complete list.

That would be a great addition, and we’d welcome a Pull Request on GitHub - algolia/algoliasearch-zendesk: Integrate Algolia within your Zendesk Help Center in minutes. to add support for it.

1 Like


Would the feature request look something like the code here?

This would indeed be a good starting point.

The code has changed quite a bit since then though, so maybe this more recent PR will also be useful, especially as to how to add an option in the options validation system:
feat(instantsearch): add support for hitsPerPage configuration by Jerska · Pull Request #74 · algolia/algoliasearch-zendesk · GitHub

Also, make sure to check out the Development section of the README to know how to test it in a live Zendesk instance:
algoliasearch-zendesk/app at master · algolia/algoliasearch-zendesk · GitHub

1 Like

We’ve got success with putting the last bit of the Algolia setup code in the footer, which can be set in consideration for if the logged in user has the role of Manager or not.

Of course, now we need the Algolia code to pass this value along… see

I’m sure you’ll have a far easier time knowing if this is the work that needs to be done… please check it out?

@Jerska I’ll try the local testing you describe, however, without knowing all the places this flag could be sent, and the one test I know how to do (see if something did not show up) is hard to prove, I’d greatly appreciate your review as well.

Thank you!

Definitely! I’ve just added a few comments on your PR to help you with that!
Thanks for going through this!

1 Like

My pleasure… I’ve added the changes you suggested. thanks for that!

As for the changelog/tagging… I told github you have permission to send more commits to this PR. have at it!

Tagging and changelog are only made when releasing, which will only be done after merging the PR.

The Changelog is automatically generated based on a commit name convention.
(Don’t worry about it, I’ll change it to match the convention when I’ll squash & merge)

1 Like