最佳实践:如何跟踪出站链接?

时间:2022-09-03 15:51:43

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

如何跟踪网站的出站链接,因为请求记录在目标服务器上,而不是您的?

5 个解决方案

#1


4  

You can add a quick JQuery script to the 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 to it, or add an ajax request that will submit on click for external links, and track them that way.

您可以将快速JQuery脚本添加到将跟踪外部链接的页面,并可以将它们重定向到服务器上的文件,该文件将跟踪链接然后转发给它,或者添加将在单击时提交的外部链接的ajax请求,并以这种方式跟踪他们。

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

见这里:http://www.prodevtips.com/2008/08/19/tracking-clicks-with-jquery-and-google-analytics/

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

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

#2


2  

Add an onclick or onmousedown handler to the anchor tag. You can see many sites doing this, such as Google.

将onclick或onmousedown处理程序添加到锚标记。您可以看到许多网站都在这样做,例如Google。

#3


2  

I don't like the redirect as described by Eric Tuttleman, as you unfortunately lose the 'search engine friendliness' of the link.

我不喜欢Eric Tuttleman所描述的重定向,因为你遗憾地失去了链接的“搜索引擎友好性”。

I handle this on a site I own by adding an onClick to my outgoing links, which fires a function which sends the link URL and a timestamp to my database. I then wrote a backend which retrieves the data, and lets me view it by such categories as 'Most clicked / 24h', 'Most clicked / 1w' etc.

我在我拥有的网站上通过向我的外发链接添加onClick来处理这个问题,该链接会触发一个函数,该函数将链接URL和时间戳发送到我的数据库。然后我编写了一个检索数据的后端,并让我通过“点击最多/ 24小时”,“点击次数最多/ 1w”等类别查看数据。

I hope this helps.

我希望这有帮助。

#4


2  

Method #1: target="_blank", onclick and Google Analytics Events

Format your outgoing links with the following attributes:

使用以下属性格式化外发链接:

<a href="http://www.example.com" target="_blank" onclick="trackOutgoing(this);">outgoing</a>

传出

Define a javascript tracking function (requires google analytics to be loaded already):

定义javascript跟踪功能(需要加载谷歌分析):

function trackOutgoing(el) {
  ga('send', 'event', {eventCategory: 'outbound',
                       eventAction: 'send',
                       eventLabel: el.getAttribute('href'),
                       eventValue: 1});
};

Pros:

  1. Does NOT interfere with normal link behavior
  2. 不会干扰正常的链接行为

  3. Does NOT require redirecting to another url
  4. 不需要重定向到另一个URL

Cons:

  1. The onclick is not guaranteed to execute (user or browser could terminate the main window)
  2. onclick不保证执行(用户或浏览器可以终止主窗口)

Method #2: Redirecting with Javascript and Google Analytics Callbacks

Format your outgoing links with the following attributes:

使用以下属性格式化外发链接:

<a href="http://www.example.com" onclick="trackOutgoingAndRedirect(this); return false;">outgoing</a>

传出

Define a javascript tracking function (requires google analytics to be loaded already):

定义javascript跟踪功能(需要加载谷歌分析):

function trackOutgoingAndRedirect(el) {
  var url = el.getAttribute('href');
  ga('send', 'event', {eventCategory: 'outbound',
                       eventAction: 'send',
                       eventLabel: url,
                       eventValue: 1,
                       hitCallback: function() { document.location = url; }});
}

Pros:

  1. Does not require target="_blank"
  2. 不需要target =“_ blank”

  3. Higher chance of your event being registered with Google Analytics (compared to Method #1)
  4. 您使用Google Analytics注册活动的可能性更高(与方法#1相比)

Cons:

  1. Overrides the default behavior of links with return false;
  2. 使用return false覆盖链接的默认行为;

  3. Cannot open outgoing links in a new window
  4. 无法在新窗口中打开传出链接

Method #3: Using a Redirect URL

Format your outgoing links with the following attributes:

使用以下属性格式化外发链接:

<a href="/redirect?url=http://www.example.com">outgoing</a>

On your site you will need to implement a redirect script which is beyond the scope of this answer.

在您的站点上,您需要实现一个超出此答案范围的重定向脚本。

Your redirect script would most likely track the outgoing link and then redirect to the provided url.

您的重定向脚本很可能会跟踪外发链接,然后重定向到提供的网址。

Pros:

  1. No Javascript required
  2. 不需要Javascript

  3. Does NOT require Google Analytics
  4. 不需要Google Analytics

  5. Does NOT interfere with the normal link behavior
  6. 不会干扰正常的链接行为

Cons:

  1. Harder to trigger Google Analytics Events
  2. 更难以触发Google Analytics事件

  3. Links do not link to their original URL. Which may have negative SEO implications.
  4. 链接不会链接到其原始URL。这可能会对SEO产生负面影响。

#5


1  

On one system I've worked on, we ended up storing redirects in a database table and creating a redirect page that takes an id as an input. On our content pages, we link to the redirect page with an unique id from this table. Once the redirect page looks up the url via the id from the table, it then sends the client a redirect response, sending them to the ending page.

在我工作的一个系统上,我们最终将重定向存储在数据库表中,并创建一个以id作为输入的重定向页面。在我们的内容页面上,我们链接到具有此表中唯一ID的重定向页面。一旦重定向页面通过表中的id查找URL,它就会向客户端发送重定向响应,并将它们发送到结束页面。

This does give us logging of external links, and as an added bonus, it makes mass changes to external urls a bit easier in some cases.

这确实为我们提供了外部链接的记录,并且作为额外的奖励,它在某些情况下使外部URL的大量更改变得更容易。

#1


4  

You can add a quick JQuery script to the 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 to it, or add an ajax request that will submit on click for external links, and track them that way.

您可以将快速JQuery脚本添加到将跟踪外部链接的页面,并可以将它们重定向到服务器上的文件,该文件将跟踪链接然后转发给它,或者添加将在单击时提交的外部链接的ajax请求,并以这种方式跟踪他们。

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

见这里:http://www.prodevtips.com/2008/08/19/tracking-clicks-with-jquery-and-google-analytics/

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

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

#2


2  

Add an onclick or onmousedown handler to the anchor tag. You can see many sites doing this, such as Google.

将onclick或onmousedown处理程序添加到锚标记。您可以看到许多网站都在这样做,例如Google。

#3


2  

I don't like the redirect as described by Eric Tuttleman, as you unfortunately lose the 'search engine friendliness' of the link.

我不喜欢Eric Tuttleman所描述的重定向,因为你遗憾地失去了链接的“搜索引擎友好性”。

I handle this on a site I own by adding an onClick to my outgoing links, which fires a function which sends the link URL and a timestamp to my database. I then wrote a backend which retrieves the data, and lets me view it by such categories as 'Most clicked / 24h', 'Most clicked / 1w' etc.

我在我拥有的网站上通过向我的外发链接添加onClick来处理这个问题,该链接会触发一个函数,该函数将链接URL和时间戳发送到我的数据库。然后我编写了一个检索数据的后端,并让我通过“点击最多/ 24小时”,“点击次数最多/ 1w”等类别查看数据。

I hope this helps.

我希望这有帮助。

#4


2  

Method #1: target="_blank", onclick and Google Analytics Events

Format your outgoing links with the following attributes:

使用以下属性格式化外发链接:

<a href="http://www.example.com" target="_blank" onclick="trackOutgoing(this);">outgoing</a>

传出

Define a javascript tracking function (requires google analytics to be loaded already):

定义javascript跟踪功能(需要加载谷歌分析):

function trackOutgoing(el) {
  ga('send', 'event', {eventCategory: 'outbound',
                       eventAction: 'send',
                       eventLabel: el.getAttribute('href'),
                       eventValue: 1});
};

Pros:

  1. Does NOT interfere with normal link behavior
  2. 不会干扰正常的链接行为

  3. Does NOT require redirecting to another url
  4. 不需要重定向到另一个URL

Cons:

  1. The onclick is not guaranteed to execute (user or browser could terminate the main window)
  2. onclick不保证执行(用户或浏览器可以终止主窗口)

Method #2: Redirecting with Javascript and Google Analytics Callbacks

Format your outgoing links with the following attributes:

使用以下属性格式化外发链接:

<a href="http://www.example.com" onclick="trackOutgoingAndRedirect(this); return false;">outgoing</a>

传出

Define a javascript tracking function (requires google analytics to be loaded already):

定义javascript跟踪功能(需要加载谷歌分析):

function trackOutgoingAndRedirect(el) {
  var url = el.getAttribute('href');
  ga('send', 'event', {eventCategory: 'outbound',
                       eventAction: 'send',
                       eventLabel: url,
                       eventValue: 1,
                       hitCallback: function() { document.location = url; }});
}

Pros:

  1. Does not require target="_blank"
  2. 不需要target =“_ blank”

  3. Higher chance of your event being registered with Google Analytics (compared to Method #1)
  4. 您使用Google Analytics注册活动的可能性更高(与方法#1相比)

Cons:

  1. Overrides the default behavior of links with return false;
  2. 使用return false覆盖链接的默认行为;

  3. Cannot open outgoing links in a new window
  4. 无法在新窗口中打开传出链接

Method #3: Using a Redirect URL

Format your outgoing links with the following attributes:

使用以下属性格式化外发链接:

<a href="/redirect?url=http://www.example.com">outgoing</a>

On your site you will need to implement a redirect script which is beyond the scope of this answer.

在您的站点上,您需要实现一个超出此答案范围的重定向脚本。

Your redirect script would most likely track the outgoing link and then redirect to the provided url.

您的重定向脚本很可能会跟踪外发链接,然后重定向到提供的网址。

Pros:

  1. No Javascript required
  2. 不需要Javascript

  3. Does NOT require Google Analytics
  4. 不需要Google Analytics

  5. Does NOT interfere with the normal link behavior
  6. 不会干扰正常的链接行为

Cons:

  1. Harder to trigger Google Analytics Events
  2. 更难以触发Google Analytics事件

  3. Links do not link to their original URL. Which may have negative SEO implications.
  4. 链接不会链接到其原始URL。这可能会对SEO产生负面影响。

#5


1  

On one system I've worked on, we ended up storing redirects in a database table and creating a redirect page that takes an id as an input. On our content pages, we link to the redirect page with an unique id from this table. Once the redirect page looks up the url via the id from the table, it then sends the client a redirect response, sending them to the ending page.

在我工作的一个系统上,我们最终将重定向存储在数据库表中,并创建一个以id作为输入的重定向页面。在我们的内容页面上,我们链接到具有此表中唯一ID的重定向页面。一旦重定向页面通过表中的id查找URL,它就会向客户端发送重定向响应,并将它们发送到结束页面。

This does give us logging of external links, and as an added bonus, it makes mass changes to external urls a bit easier in some cases.

这确实为我们提供了外部链接的记录,并且作为额外的奖励,它在某些情况下使外部URL的大量更改变得更容易。