I'm trying to track outbound links using Google Analytics as discussed here: https://support.google.com/analytics/answer/1136920?hl=en
The links that I need to track are contained in the article body field in Expression Engine and I need the code to be formatted automatically because our users don't have the technical ability to add tracking code to all of their links.
What I did is put the article body in a div with an id of 'article_body'. What I would like to do with Javascript is to add the code necessary to track the event when the page loads.
I need the links in the article_body div to change from:
<a href="http://www.foo.com" target="_blank">Foo</a>
to
<a href="http://www.foo.com" onclick=”trackOutboundLink(‘http://www.foo.com’); return false;" target="_blank">Foo</a>
Is anyone aware of a way to do this in js or can you point me in the right direction?
Thank you very much, I appreciate your assistance.