在Google Analytics中包含drupal搜索参数?

时间:2012-09-25 06:34:24

标签: drupal google-analytics

Drupal 6的htaccess说:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

因此,如果您搜索,您可以输入如下路径:

mysite.com/search/SEARCH_STRING

我希望Google Analytics能够跟踪此用户搜索“SEARCH_STRING”。我该怎么做?

1 个答案:

答案 0 :(得分:1)

Google Analytics支持搜索查询跟踪。

如果您将GA代码包含在模板文件中并且无法返回到GA模块,则可以提取搜索查询并将其附加到JavaScript中的跟踪网址,例如:

var search_matches = window.location.pathname.match(/\/search\/(.*?)\/(.*)/);
if (search_matches) {
  _gaq.push(['_trackPageview', window.location.pathname + [window.location.search, (window.location.search ? '&' : '?'), 'search=', search_matches[2] , '&search_type=', search_matches[1]].join('')]);
}
else {
  _gaq.push(['_trackPageview']);
}