跨域跟踪 - Wordpress&谷歌分析

时间:2013-05-15 06:31:28

标签: wordpress google-analytics

哪种方法可以自动将_link GA操作添加到指向特定域的每个出站链接?

e.g。

<a href="http://example.com/intro.html" 
onclick="_gaq.push(['_link', 'http://example.com/intro']); 
return false;">See my blog</a>

2 个答案:

答案 0 :(得分:1)

此插件似乎满足您的需求: http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

有些人提到跨域跟踪功能有点破解,但可以通过执行此线程中的建议来修复: http://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking

答案 1 :(得分:0)

今天我正在为该插件开发一个客户端,我发现这种方法可以解决问题(例如,你可以在这些代码中添加手动方法......):

注意:当您通过管理员登录查看网站时,插件可能无法正常工作。

打开“wp-content / plugins / google-analytics-for-wordpress / frontend / class-frontend.php”文件,然后:

1)在336-338行写着:

        } else {
            $pushstr = "['_trackEvent','" . $prefix . "','" . esc_js( esc_url( $target ) ) . "']";
        }
        return

将该代码更改为:

        } else {
            if (stristr($prefix,'outbound')) 
            {$pushstr = "['_link','" . $prefix . "','" . esc_js( esc_url( $target ) ) . "']";}
            else 
            {$pushstr = "['_trackEvent','" . $prefix . "','" . esc_js( esc_url( $target ) ) . "']";    }
        } 
        return

2)如果您遇到子域跟踪问题,那么可能在第361行,这段代码:

            } else if ( $target["domain"] != $origin["domain"] ) {

需要改为

            } else if ( $target["domain"] != $origin["domain"] || (stristr($matches[3],'.'.str_replace('www.','',$_SERVER['HTTP_HOST'])) && !stristr($matches[3],'www.'.str_replace('www.','',$_SERVER['HTTP_HOST']))) ) {
相关问题