# 1: target="_blank", onclick Google Analytics
:
<a href="http://www.example.com" target="_blank" onclick="trackOutgoing(this);">outgoing</a>
javascript (, Google):
function trackOutgoing(el) {
ga('send', 'event', {eventCategory: 'outbound',
eventAction: 'send',
eventLabel: el.getAttribute('href'),
eventValue: 1});
};
:
:
# 2: Javascript Google Analytics
:
<a href="http://www.example.com" onclick="trackOutgoingAndRedirect(this); return false;">outgoing</a>
javascript (, Google):
function trackOutgoingAndRedirect(el) {
var url = el.getAttribute('href');
ga('send', 'event', {eventCategory: 'outbound',
eventAction: 'send',
eventLabel: url,
eventValue: 1,
hitCallback: function() { document.location = url; }});
}
:
target="_blank"- Google Analytics ( โ1)
:
โ3: URL-
:
<a href="/redirect?url=http://www.example.com">outgoing</a>
script, .
Your redirect script will most likely track the outbound link and then redirect to the provided URL.
Pros:
- No Javascript Required
- Does NOT require Google Analytics
- Does NOT help link behavior
Minuses:
- It's harder to trigger Google Analytics events.
- Links do not link to the source URL. Which may have negative consequences for SEO.
source
share