How to use Google Programmable Search Engine (CSE) in your website

How to use Google Programmable Search Engine (CSE) in your website

Published at: 08/06/2022
Updated at: 11/17/2022
Categories
Tags

Technical guide for installing and configuring the Google search engine on a website

Google's Programmable Search Engine (formerly: Custom Search Engine or Google CSE) is the free version of the search engine that you can insert on your site.

However, advertisements may appear in the search results. To remove them, we will need to use the paid API.

Suppose a user searches the site for "books" or "lamps", among the results they may see "books" or "lamps" from a particular company (perhaps competitor), which is paying for its ads to appear on the Google AdWords Display Network.

Let's see how to configure both the free search engine and the paid solution using the Custom Search API and the PHP library that I developed!

How to implement the free programmable search engine?

To implement the search engine:

  • create a new engine on Programmable Search Engine
  • enter the address of the site to search for results, for example www.gaminghouse.community
  • choose a language
  • gives the search engine a name

You will get a code for the implementation, you can copy and insert it as indicated by Google, inside the HEAD tag of your page .

How to implement the paid and ad-free version of CSE?

Let's get more technical.

I didn't want to use the systems indicated by Google, such as Custom Search Element Control API 2.0 or ready-made libraries. The documentation wasn't clear enough.

I therefore opted for the alternative of JSON / Atom API but starting from scratch. In the emails that I exchanged with Google support, I had confirmation that the only way to not have the advertisements was to use the paid version, only that no one gave you a simple implementation.

Instead of spending hours figuring out how to use the libraries, which might not be suitable, I wanted to create my own custom solution.

Steps to follow:

  1. Create or modify your search engine and obtain the engine identification code (Search engine ID or CX )
  2. Sign up for Google Cloud and set up a payment method
  3. Create a project in the Google Cloud
  4. Add the Custom Search API from library
  5. Create an API key (api key) for Custom Search. We will need this key to implement our engine
  6. (optional) Set restrictions on the API key, for example by associating it only with the Custom Search API
  7. Use the identification code (engine ID) and API key in your script.

Useful information:

  1. We can test with the API Explorer or in the parameter references
  2. The single query is defined by the parameter "q".

Free and open source PHP library: PHP Google CSE Standalone

I created a special PHP library on Github: PHP Google CSE Standalone.

In a nutshell, a request is sent to the Custom Search API, then the result is processed in PHP and the engine is built search, deciding separately whether to show the "promoted" results or just the normal ones.

The code is open source and the library is free: you can use it on your site to integrate the Google search with the Custom Search API.

Promoted results

You can configure in your own search engine, via the control panel, of the promoted results, ie the pages highlighted in the results list.

You need to associate keywords, which will act as a trigger, to URLs which will be shown as search results. </p >

For example, a user searching for "men's shoes" or "red shoes" might see a page that we highlighted because we want to promote a new shoe model.

Search engine prices

The cost is that of the consumption of queries. Remembering that a query is every single request made through the search engine, the cost established by Google is $ 5 for every 1000 queries. The first 100 requests of each day are free, so if on average the site uses 120 queries per day, we will only pay 20.

Google will charge a invoice via Google Cloud in the first few days of each month. If we signed up for the Google Cloud for the first time, we will have a bonus of € 300 to spend in the various APIs, so as long as we have this bonus we will not be charged.

Suppose we expect an average of 25,000 searches per year for a site. The estimate will be 125 € (25,000 * 5/1000).

The real cost, charged by Google, being on consumption, will be calculated on what is really used by users. Furthermore, if the engine receives less than 100 requests per day, in the end we will not pay anything, precisely because the first 100 searches per day are at no cost.

See the Google Custom Search API price list.

Which engine to choose? Free or paid?

Using the free search engine, users performing searches may see advertisements in their search results.

In the days of Google Site Search, you bought a license to have a query blocker. A query is every single search made by the user. It often happened that you buy 150,000, or 500,000 queries, paid in advance, and then consume less than half of them.

Now Google, through the use of the Search API, will charge queries on consumption, based on what is actually used.

This way many users will likely use the free search engine, which will expand the number of people who see ads advertisements.

Those who do not want other companies' ads on their website, like many public administration bodies, or like many private companies, will pay for the service because they need it.

This will allow on the one hand to save for those who want to implement search at no cost, and on the other hand it allows advertisers and publishers to have more space for their advertisements. In any case, obviously the one who gains is Google.

So my advice is to use the free solution if the advertisements don't bother you, for example for a small personal site that doesn't sell products.

Otherwise, if you have an e-commerce or a company website, the paid solution is worth your while.

Congratulations on implementing the CSE search engine on your site!

I hope this article was helpful to you, leave a comment and follow me on Facebook and Youtube!

See you next time!

Leave a comment

All comments will be subject to approval after being sent. They might be published after several hours.

You can just use a random nickname, it is usefull to allow me to at least answer your comments. And if you choose to submit your email, you can receive a notification whenever I reply to your comment.

No comments have been written so far on this article. Be the first to share your thoughts!

*