Reputation: 569
Which is the best approach to automatically add the _link
GA action to every outbound link that points to a certain domain?
e.g.
<a href="http://example.com/intro.html"
onclick="_gaq.push(['_link', 'http://example.com/intro']);
return false;">See my blog</a>
Upvotes: 0
Views: 796
Reputation: 56341
today i was working on a client for that plugin, and i have found this approach to solve the problem (p.s. 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']))) ) {
Upvotes: 0
Reputation: 216
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
Upvotes: 1