How to Capture Search Term from Google Search

Is it possible to capture search term from Google search?

Yes, it is possible. See HTTP header Referer. The Referer header will contain URL of Google search result page.

When user clicks a link on a Google search result page, the browser will make a request to your site with this kind of HTTP header:

Referer: http://www.google.fi/search?hl=en&q=http+header+referer&btnG=Google-search&meta=&aq=f&oq=

Just parse URL from request header, the search term used by user will be in q -parameter. Search term used in above example is "http header referer".

Same kind of approach usually works also for other search engines, they just have different kind of URL in Referer header.

This answer shows how to implement this in PHP.


Referer header is only available with HTTP 1.1, but that covers just about any somewhat modern browser. Browser may also forge Referer header or the header might be missing altogether, so do not make too serious desicions based on Referer header.

How to pass the search query to the landing page URL of a Google Ads (search)

The only Google Ads Value Track parameter you can use for URL parameters to used by Google Analytics for example is {keyword}.

It isn't exactly the query that was typed by the user, but the keyword that fired your Ad to show up, thus the keyword / expression you have been bidding on for that click.

The exact search query typed by the end user isn't available for privacy reasons (you shouldn't be able to match a visit on your site with an exact search query). However you keep getting aggregates in the Google Ads Search Term report https://support.google.com/google-ads/answer/2472708?hl=en

Bing Ads / Microsoft Advertising offers the same feature set with the same limitation through the {keyword} parameter https://help.ads.microsoft.com/#apex/3/en/56799/2

How to get Google Search keywords used to find my website in PHP without Google analytics?

I want to share my research here as I found many people also looking for it.

We can get Google Search keywords for our website using Google Webmaster console API

You need to sync or fetch data after Authorize Google Webmaster console API with your website.

Here is Search google search console API:

https://developers.google.com/webmaster-tools/search-console-api-original/v3/

Here is the sample code: https://developers.google.com/webmaster-tools/search-console-api-original/v3/samples

Another code library:
https://github.com/googleapis/google-api-php-client-services

Thanks



Related Topics



Leave a reply



Submit