Site search feature

jmesam - December 13, 2007 - 21:04
Project:Google Analytics
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Since november, google analytics can track how people search your site using your internal search, but we can't track it with Drupal's internal search because analytics' code use the 'Query Parameter' of the search (I think it uses GET method) and Drupal sites typically have URLs like '/search/node/keyword1+keyword2' (I think it uses POST method).

Is there a way to tell google analytics code what are the keywords of search?

See http://drupal.org/node/189523#comment-621683 for more information.

#1

budda - December 14, 2007 - 14:18

Do you have a link to the info on the Google Analytics site for this functionality.

#3

hass - December 30, 2007 - 23:08
Version:HEAD» 6.x-1.x-dev
Status:active» patch (code needs review)

I tried to build this feature in GA. Patch attached against latest D6 code. I will not commit this patch until we get some good reviews and the search results are tracked for sure correctly in GA. I have not done much testing on this patch, yet. Please also check the wording in the strings.

Today i don't trust this urlencode($keys) and the $keys list very much... It should be tested with special chars, Chinese, Arabic, German Sonderzeichen, double blanks and whatever bad chars you might think about... let's try to break it! :-)

AttachmentSize
google_analytics_add_site_search_support.patch3.68 KB

#4

jmesam - February 2, 2008 - 22:06

Wow!
I have test your patch and it works almost perfectly, but foreigns char.
If I search for: artículo, analytics show it like: art%25C3%25ADculo
Thank you!

Is it possible to have a Drupal 5.x version?

#5

hass - February 2, 2008 - 23:23

Could you try again this patch, please. I missed to see url() does URL encoding themself for query params. So it was double escaped with the prior patch. This should be fixed now, but it'm not sure if this is correct inside GA JS code. It could be possible we must use drupal_to_js() here and do not use url() what is the source of this encoding.

Do you have any info how special chars are handled by google and how they must be escaped here?

AttachmentSize
google_analytics_add_site_search_support_2008020301.patch4.1 KB

#6

hass - February 2, 2008 - 23:38

If the above patch do not work, could you please try to replace the following line in googleanalytics.module line 123:

<?php
$url_custom
= url('search/node', array('query' => 'search='. urlencode($keys)));
?>

with this:

<?php
$keys_clean
= str_replace(array("\r", "\n", "<", ">", "&"),
                        array(
'\r', '\n', '\x3c', '\x3e', '\x26'),
                       
addslashes($keys));
$url_custom = base_path() .'search/node?search='. $keys_clean;
?>

I found a discussions where some people complain about a bug in GA... they have troubles with Turkish and Polish chars, too. It could be possible that we commit the patch above and wait for google to fix this bug in ga.js... maybe you are able to test urchin.js and ga.js for a comparison!?

#7

jmesam - February 3, 2008 - 21:02

I have tested this patch (ga.js) and yet the foreign chars are wrong, but I think it is a google problem, because in "Content Overview" it shows: /search/node?search=españa but in Site Search Terms it shows: espa%C3%B1a.

Let my try the other mod: http://drupal.org/node/200701#comment-715041 <- Updated: the same problem with foreign chars

#8

hass - February 4, 2008 - 00:16

I wonder how this is possible...?!? With the code in #6 there is no URL encoding in place... this must be a GA bug...

#9

hass - February 4, 2008 - 19:45
Status:patch (code needs review)» patch (to be ported)

This patch has been committed to D6 and could be back ported to D5.

AttachmentSize
google_analytics_add_site_search_support_2008020401.patch5.22 KB

#10

hass - February 9, 2008 - 20:28
Version:6.x-1.x-dev» 5.x-1.x-dev
Status:patch (to be ported)» fixed

#11

Anonymous (not verified) - February 23, 2008 - 20:31
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.