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

budda’s picture

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

hass’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new3.68 KB

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! :-)

Anonymous’s picture

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?

hass’s picture

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?

hass’s picture

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

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

with this:

$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!?

Anonymous’s picture

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

hass’s picture

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

hass’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new5.22 KB

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

hass’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev
Status: Patch (to be ported) » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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

Wolfgang Reszel’s picture

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

Hi,

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

Tekl

hass’s picture

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

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