Best practice: how to track outbound links?

How do you track outbound links for your website, since the request is logged on the destination server, and not on yours?

+5
source share
5 answers

You can add a quick jQuery script to a page that will track external links and can either redirect them to a file on your server that will track the link and then forward it or add an ajax request that will be clicked on for external links and track them thus.

See here: http://www.prodevtips.com/2008/08/19/tracking-clicks-with-jquery-and-google-analytics/

: http://www.justskins.com/development/how-to-track-clicks-on-outgoing-links/132

+4

onclick onmousedown . , , Google.

+2

, , , , " " .

, onClick , , URL- . , , , " /24h", " /1w" ..

, .

+2

, , , . . URL- , .

, URL-.

+1

# 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});
};

:

  • URL

:

  • onclick ( )

# 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)

:

  • return false;

โ„–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.
+1
source

All Articles