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:

 algoliasearchZendeskHC({ 
     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?

TIA

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

image

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 () { 
  console.log(HelpCenter.user.role);
  algoliasearchZendeskHC({
    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 https://community.algolia.com/zendesk/documentation/#available-options for the complete list.

That would be a great addition, and we’d welcome a Pull Request on https://github.com/algolia/algoliasearch-zendesk/ to add support for it.

1 Like

Thanks!

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:
https://github.com/algolia/algoliasearch-zendesk/pull/74

Also, make sure to check out the Development section of the README to know how to test it in a live Zendesk instance:
https://github.com/algolia/algoliasearch-zendesk/tree/master/app#development

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