Project:Google Analytics
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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.

Comments

#1

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

#3

Version:7.x-1.x-dev» 6.x-1.x-dev
Status:active» 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! :-)

AttachmentSizeStatusTest resultOperations
google_analytics_add_site_search_support.patch3.68 KBIgnored: Check issue status.NoneNone

#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?

AttachmentSizeStatusTest resultOperations
google_analytics_add_site_search_support_2008020301.patch4.1 KBIgnored: Check issue status.NoneNone

#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

Status:needs review» patch (to be ported)

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

AttachmentSizeStatusTest resultOperations
google_analytics_add_site_search_support_2008020401.patch5.22 KBIgnored: Check issue status.NoneNone

#10

Version:6.x-1.x-dev» 5.x-1.x-dev
Status:patch (to be ported)» fixed

#11

Status:fixed» closed (fixed)

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

#12

Version:5.x-1.x-dev» 7.x-1.2
Category:feature request» support request

Hi,

are there special requirements for D7? I activated the feature but I still have no query parameters in the URL.

Tekl

#13

Version:7.x-1.2» 5.x-1.x-dev
Category:support request» feature request

No. Look into code, not the browser address bar.