0

如何通过以下搜索代码(设置为 google 搜索“KEYWORDS site:MYDOMAIN.com”)合并 Google Analytics(分析)页内搜索跟踪?

我面临的问题是,按 Enter 会导致用户立即跳转到 google 进行搜索查询。我已经看到了一些使用hitCallback的点点滴滴,但我不确定如何在这个设置的页面上实现它。

<form action="http://www.google.com/search" name="searchbox";
method="get" id="searchform" class="form-search">;
<input type="hidden" name="hl" value="en" />;
<input type="hidden" name="ie" value="ISO-8859-1" />;
<input type="hidden" name="sitesearch" id="s" value="MYDOMAIN.com" />;
<input maxlength="256" size="40" name="q" class="search" value="" />;
</form>

我知道我不能使用新的 Universal Analytics 提供的传统页内搜索,但我不明白为什么在提交时不应该在离开我的域之前提交给 GA谷歌搜索页面。在思考问题时,我相信可以重定向到另一个页面,提交 GA,然后重定向到 google,但我当然希望尽量减少我的请求并提出一个简单的解决方案。

4

2 回答 2

0

您可以action从表单中删除并在设置超时后使用 jQuery 设置它以让 GATC 触发。像这样的东西:

$('#searchform').on('submit', function(e){
    e.preventDefault();
    window.setTimeout(function(){
        if (typeof _gaq != 'undefined') {
            _gaq.push(['_trackEvent', 'Search', 'value', 'paramX', 'valueY', false]);
        }                                        

        $('#searchform').attr('action', 'http://www.google.com/search');

    },1000);

});
于 2014-06-04T13:44:35.337 回答
0
    <script>

    $("#searchform").submit(function (event) {



        event.preventDefault(); // cancel default behavior

        var searchTerms = $('input[name=q]').val();
        searchTerms = searchTerms.replace(" ", "+");
        console.debug(searchTerms);
        ga('send', {
            'hitType': 'pageview',
            'page': "http://MYDOMAIN.com/search?hl=en&ie=ISO-8859-1&sitesearch=MYDOMAIN.com&q=" + searchTerms,
            'title': 'Google Search'
        });
        setTimeout(function () {
            window.location.href = "http://google.com/search?hl=en&ie=ISO-8859-1&sitesearch=MYDOMAIN.com&q=" + searchTerms;
        }, 500);

    });

     </script>

尽管访问了外部域,但我发现实现伪站内搜索(通过谷歌搜索提供)的最佳方法是在重定向到正确的搜索页面之前导致虚假页面查看。我插入了半秒的延迟,以确保页面视图在重定向之前发送。

于 2014-06-16T15:39:41.013 回答