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
Do you have a link to the info on the Google Analytics site for this functionality.
#2
Here you have some info:
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=75969
http://analytics.blogspot.com/2007/11/site-search-now-available.html
http://www.epikone.com/blog/2007/10/16/ga-on-site-search-pt-1-overview-s...
#3
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! :-)
#4
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
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?
#6
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
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
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
This patch has been committed to D6 and could be back ported to D5.
#10
#11
Automatically closed -- issue fixed for two weeks with no activity.