Google CSE does not set search keys

EvanDonovan - June 14, 2008 - 14:18
Project:Google Custom Search Engine
Version:5.x-1.4
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

On UrbanMinistry.org, we have been using the Google CSE module to implement a site search (http://www.urbanministry.org/search/google). Until we upgraded to Google Analytics module 5.x-1.5, we were tracking site search results using the query string parameter "query", which is standard for Google's custom search engine.

However, the more recent versions of Google Analytics are trying to use the parameter "search", and so are not tracking results.

Here is the relevant JavaScript from the bottom of the Google Analytics-module generated code: pageTracker._trackPageview("/search/google?search=");

Is there any way to get this code to say pageTracker._trackPageview("/search/google?query="); instead? I am willing to modify the source of our copy of the module to do so, if necessary.

Alternatively, I noticed that the code for the Google Custom Search webform includes this line:
<input type="text" maxlength="128" class="textinputwhite" name="query" id="edit-query"  value="" />
If I changed name to "search" and updated my Analytics settings accordingly would that work? If so, which method would you recommend?

#1

hass - June 14, 2008 - 22:14
Status:active» fixed

GA module have used "search" as the site search query parameter from the first day... we never used "query" here!? You can change the name of the search url parameter in your GA account. I thought some time about making it value customizable, but when I saw it's configurable in the GA account I thought we don't need this.

See http://www.google.com/support/googleanalytics/bin/answer.py?answer=75817. You can define up to 5 query strings. So you could add for e.g. "search,query" and you are fine. No code changes required...

If this doesn't work for you, please reopen and explain why.

#2

EvanDonovan - June 15, 2008 - 15:12

Sorry if I wasn't clear - maybe what happened is that we used to be using something else to track Google site search results and then when we upgraded the GA module, we started using it but it wasn't tracking the same parameter.

The Google Custom Search Engine module doesn't use "search" as the parameter. It only uses "query". So I don't think that adding "search" to the list of terms that Google was tracking would return statistics for the Google Custom Search Engine, but only for regular search (which we're not currently using). I'll try it and see.

It might be that all I need to do is add pageTracker._trackPageview("/search/google?query="); to the Custom Javascript Code box. I'll try that next if adding "search" doesn't work.

#3

hass - June 15, 2008 - 15:35

If you add this line to the "Custom Javascript Code" your page will be tracked twice. I'm sure this is something you don't like to get.

Change the config in your GA account and this should be solved. If not let us know.

#4

EvanDonovan - June 18, 2008 - 18:45
Status:fixed» active

I checked Analytics today again and the Visits with Search number on the Site Search page is back to its former levels.

However, now the #1 query under Top Site Searches is (not set). I believe this is because the code is tracking search/google?search when the actual search queries are of the form search/google?query.

(For example, http://www.urbanministry.org/search/google?cx=[]&cof=[]&query=urban+ministry&op=Search&form_id=google_cse_results_searchbox_form.)

So it looks like I'll have to change the site search code in my version of the module to track "query" instead of "search", so that I can get the specific search terms to show up in my Analytics results.

#5

hass - June 18, 2008 - 21:59
Status:active» postponed (maintainer needs more info)

1. Have you configured your GA account to use "query" AND "search" for search keywords?
2. It this working without any code changes to Drupal modules?
3. If not - what are the differences? Please provide examples and details. Maybe a screenshot... I'm not using this site search feature together with other modules...

#6

hass - June 18, 2008 - 22:13
Title:Google Analytics 5.x-1.5+ does not track search results from Google CSE» Google CSE does not set search keys
Project:Google Analytics» Google Custom Search Engine
Version:5.x-1.6» 5.x-1.4
Category:support request» bug report
Status:postponed (maintainer needs more info)» active

After thinking what is wrong here... the real issue is not the GA module and not your GA account settings!

The real issue is that Google CSE module does not provide the query search keys if the GA module calls the core function search_get_keys(). This need to be fixed in the CSE module. After this is fixed GA module will automatically track this correctly. After this is fixed you need configure the query param "search" in your GA account.

#7

mfb - June 18, 2008 - 22:21

I don't use Google Analytics and have no clue what you're talking about here :) So please provide a patch if you've found a bug.

#8

hass - June 18, 2008 - 22:33

Additional try to test #272215: Prevent blank search keys, please.

#9

hass - June 20, 2008 - 06:40

@mfb: Google CSE module does not use "clean URLs" for their search result URLs. All other search modules provide the search keys if i call the core function search_get_keys() except Google CSE. I fixed the related issue in GA, but Google CSE seems not working in a Drupal friendly way how other search modules do. Other modul's build a clean URL from the params you are searching for... Google CSE module doesn't do that and therefore does not provide the search keys to the core function. In this way I'm unable to know what the search keys are and cannot attach them to the custom "site search" URL the GA module builds.

With the fix in #272215 I'm no more changing the URL - if the keys are empty and this should keep the original URL logged in GA as is. I think the issue is solved by that fix, but you should think about changing the way how Google CSE module build the page URL after you submitted a search. I think many people would expect a clean URL here. If not possible, close the case.

#10

mfb - June 20, 2008 - 15:37

Google CSE does not exercise the Drupal search API at all, in fact it can function with the search module disabled completely. All the functionality happens in javascript, not on the PHP side at all. Google's CSE javascript looks for the "query" parameter on the url to determine what the search terms were, creates an iframe in the page and loads the search results into the iframe.

That said it would be possible for the Google CSE module to determine the search terms and pass them into a Google Analytics function, if available.

Also it would take some coding but it might be possible for Google CSE to optionally use the drupal search API, although I'd still want to preserve the ability for it to function independently.

#11

EvanDonovan - June 20, 2008 - 14:58

Yes, I am aware that Google CSE doesn't use the Drupal search API. In my particular use case, I am not interested in tracking the core Drupal search in Google Analytics, since the only user-facing search boxes use the Google CSE module.

My ideal solution for this issue would be to have a JavaScript that checked for the presence of the query parameter on the URL path and passed the search terms in to the Google Analytics.

Hass, would it be possible to put into the Custom JavaScript code box on the GA module a snippet that said something to the effect of

(pseudocode)
if (URL == "/search/google") {
pageTracker._trackPageview("/search/google?query="); }

Unfortunately, I don't know JavaScript, so I don't know how to write the if condition. But am I on the right track with this suggestion?

#12

mfb - June 20, 2008 - 15:57

It would probably be PHP, not javascript. But it looks like either google analytics module would need to add explicit support for Google CSE module or it would need to add a hook so other modules could inject a custom URL.

#13

hass - June 20, 2008 - 16:13

@EvanDonovan: You don't need to do this... try the latest GA DEV please. The issue is fixed and only thing you need to do is - configure your GA account at google.com to accept "query,search" as site search param and install the latest GA module DEV version.

#14

EvanDonovan - June 20, 2008 - 18:41

Ok, I'll do that. Thanks. I just wanted to make sure I understood the implications of the patch before applying to my site.

#15

hass - June 20, 2008 - 20:39

It's very simple and was a minor bug. If a search module does not provide any search keys - GA no more building a custom URL that have an empty "search" param. This make sure the page tracker log's the real URL and GCSE have a URL with "query" param inside. So it's correctly logged in the GA statistics... give it a try.

#16

mfb - June 24, 2008 - 21:03
Status:active» fixed

For Drupal 6 I added a small helper module, "Google CSE search," which implements the core Search API.

#17

Anonymous (not verified) - July 8, 2008 - 21:12
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#18

EvanDonovan - July 10, 2008 - 15:10

Just wanted to confirm that the patch in #8 fixed this issue for us.

 
 

Drupal is a registered trademark of Dries Buytaert.