Zendesk
Overview
Glean offers two distinct options for implementing search functionality within Zendesk Guide:
Modal Search
A modal search interface that overlays the current page when activated
Autocomplete & Results Page
An integrated search experience with autocomplete and a dedicated results page
These implementation instructions are based on the Copenhagen Zendesk Template. While they should work with other themes with minimal modifications, some adjustments may be needed depending on your specific theme.
Modal Search Implementation
Access Theme Customization
Navigate to the Customize design section by clicking the "eye" icon in the left navigation
Select Theme
Locate the Live theme section and click Customize on your theme
For live help centers, we recommend creating a copy of your theme for testing:
- Find your live theme
- Click the three vertical dots menu
- Select Copy
Edit Theme Code
- Click Edit Code to access the theme code editor
- Open script.js from the left panel
- Add the following code at the top level:
const gleanScript = document.createElement("script");
gleanScript.src = "https://{YOUR_GLEAN_DOMAIN}/browser-api/embedded-search-latest.min.js";
gleanScript.defer = true;
gleanScript.addEventListener("load", function () {
EmbeddedSearch.attach(document.querySelector("input[type=search]"));
});
document.head.append(gleanScript);
- Click Save
Preview and Publish
- Click Preview in the left panel to verify your changes
- Once confirmed, apply the changes to your live theme
- Click Publish to make the changes live
Autocomplete and Search Results Implementation
Import JavaScript Files
- Access theme customization as described above
- Click Edit Code
- Open document_header.hbs
- Add the following script tag:
<script defer src="https://{YOUR_GLEAN_DOMAIN}/browser-api/glean-for-zendesk-guide-latest.min.js"></script>
Replace Search UI Components
Home Page Search
- Open home_page.hbs
- Replace the existing
{{search}}
component with:
<div
class="glean-search-box"
style="width: 100%; height: 60px; max-width: 600px; margin:auto; position: relative;"
>
</div>
Search Results Page
- Open search_results.hbs
- Replace all existing code with:
<div class="glean-search-results" style="width: 100%; margin:auto; position: relative;"></div>
Add Compact Search Box
- Open article_page.hbs
- Replace the existing search code with:
<div
class="glean-search-box--compact"
style="width: 100%; height: 42px; max-width: 600px; margin:auto; position: relative;"
>
</div>
Initialize Glean Search
- Open script.js
- Add the following code at the end of the file:
/** Setup Glean search **/
function initializeGleanSearch () {
// Note: This should match the backend URL for your Glean setup
const backend = '<CHANGEME>';
// See available customizations here: https://app.glean.com/meta/browser_api/interfaces/SearchBoxCustomizations.html
const customizations = {
boxShadow: 'none',
borderRadius: 8,
placeholderText: 'Search...', // Change me to a placeholder of your choice
};
// Initialize GleanForZendesk
GleanForZendeskGuide.init({
// This should match the search page used by your theme -- this usually matches /hc/search
searchUrl: '/hc/search',
// If your Glean setup supports guest users, mark this as true.
// Note: If your Glean setup is internal users only, this option will be ignored.
anonymous: false,
backend,
}).then((instance) => {
// Attach hero search box
instance.renderSearchBox('.glean-search-box', {
searchBoxCustomizations: Object.assign({}, customizations, {
fontSize: 20,
// Additional customizations can be added here
}),
backend,
});
// Attach compact search box
instance.renderSearchBox('.glean-search-box--compact', {
searchBoxCustomizations: Object.assign({}, customizations, {
fontSize: 16,
// Additional customizations can be added here
}),
backend,
});
// Attach search results
instance.renderSearchResults('.glean-search-results', { backend, showInlineSearchBox: true });
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeGleanSearch);
} else {
initializeGleanSearch();
}
Verify and Publish
- Click Preview to test your changes
- Apply the changes to your live theme
- Click Publish to make the changes live