Here are steps to create a Drupal custom search. In this method, we will use expertrec to create a custom search engine and use Google tag manager to add it to your Drupal site.
Create a Drupal custom search
- Create a Drupal custom search engine using expertrec from https://cse.expertrec.com/?platform=cse
- Inside your expertrec control panel, enter your Drupal sitemap URL.
- Wait for your site crawl to complete.
- Download and Install google tag manager extension for Drupal from here. https://www.drupal.org/project/google_tag
- Once you install, enter your Google tag manager ID. Click on save the configuration.
- Go to https://cse.expertrec.com/csedashboard/home/code and copy your code.
- Copy the first part of the code in your control panel
-
<script> (function() { var id = 'YOUR_API_KEY'; var ci_search = document.createElement('script'); ci_search.type = 'text/javascript'; ci_search.async = true; ci_search.src = 'https://cse.expertrec.com/api/js/ci_common.js?id=' + id; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ci_search, s); })(); </script>
Add this code to your Google tag manager. Replace YOUR_API_KEY with your API key.
- Add Triggers ( set to all pages).
- Go to Structure-> Block layout-> Header ->Place block-> Add custom block-> click on source and enter the following code. (choose full HTML). This places the search box in your header
<ci-search></ci-search>
- Click Save.
- Now the search box will be added to the header section of your Drupal site.