简体   繁体   中英

Cross domain tracking - Wordpress & Google Analytics

Which is the best approach to automatically add the _link GA action to every outbound link that points to a certain domain?

eg

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

This plugin seems to fill your needs: http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

Some people are mentioning that the cross-domain tracking functionality is somewhat broken, but can be fixed by doing the suggestions in this thread: http://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking

today i was working on a client for that plugin, and i have found this approach to solve the problem (ps you can add your manual approach to these codes too..):

( note: the plugin may not work correctly while your are viewing the site with administrator login. )

open "wp-content/plugins/google-analytics-for-wordpress/frontend/class-frontend.php" file, then:

1) on line 336-338 there is written:

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

change that code to this:

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

2) If you are haveing problems for subdomain tracking, then maybe on line 361, this code:

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

needs to change to

            } 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']))) ) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM