So I'd rather not install yet another module to risk trouble-shooting against so many others if I can just get something done in code.
I need to track outgoing links on a certain page but Google Analytics doesn't do that by default.
From Google Analytics documentation, I found this:
<script type="text/javascript">
function trackOutboundLink(link, category, action) {
try {
_gaq.push(['_trackEvent', category , action]);
} catch(err){}
setTimeout(function() {
document.location.href = link.href;
}, 100);
}
</script>
easy enough to include in my other scripts. But, I need to use this on the a links:
<a href="http://www.example.com" onClick="trackOutboundLink(this, 'Outbound Links', 'example.com'); return false;">
I have a form whereby the content-type for each link is entered directly into a cck field. Then, that field is set to show as a Title/Link so the actual hyperlinking is done by Drupal.
I need to figure out a way to put that inline code into particular links.
Quickly, I thought I could use jquery to select the attribute 'href' of all the 'a' elements of the parent container and use 'src' to change them all, but there will be the little issue of parsing and first grabbing the actual www.whatever.com part, store and stick it back.