改进 Onebox 点击计数

If I put a link into my posts, I see how many people have clicked on the link. But if I put the link on one line, and it gets one-boxed, then I never see any count of the clicks.

This post describes the issue further:

There are two parts to the answer.

First, you must enable opening links in an external tab. (I don’t understand this, technically, as other links are counted without turning this option on.)

Second…

So, the main link people will click on will never be counted. Again, I don’t understand the technical difference between the links and why one would be counted and not the other.

Regardless of my lack of understanding of what’s going on technically, I’d love to see Onebox link clicks counted consistently.

6 个赞

I have gone through all the settings in my Dashboard and I have no check boxes to enable opening links in an external tab… but the links do open in another tab already.
We have tried clicking on both the title of an article and the link itself - no counter for either.
Here’s a stickler… for a day or two, the counter suddenly worked, then stopped again. Nothing was changed at all. I’ve also asked a mod and several users if they see any link counts next to the links posted. None have seen them so I know it’s not just me being an Admin.
Like you, I would like to see the Onebox link clicks counted consistently.

Edit: I should point out for link posted after a blank space (so they don’t get Oneboxed), the counter works… just not for Onebox.

2 个赞

I already enabled the setting last week, search for default other external links in new tab. This setting will be applied to all new users who have registered on your site after the site setting has been enabled. Old users can activate it from their profiles (in case we can bulk enable the setting even for old users via console).

I tried to click on the two oneboxes in the first two posts of this topic https://forum.nodders.net/t/2019-plastic-waste-and-recycling/167 and the count has increased from 0 to 1. It is possible that the user who did the test was an old user and did not enable the setting for external tab on the profile, or that the user tried to open the link in a new window directly by right-clicking on the link itself.

3 个赞

That’s what probably is happening. I’ll inform everyone that they will have to make the change in their profile… as I. :wink: Thank you.

Also note that clicking links in your own post will not increment the counters…

3 个赞

@dax, @codinghorror, I found out why the link counter was working for me and others on our forum. In _Preferences/Interface/Other, although I did have the Open all external links in another tab checked, I also had the Show counts on browser icon checked. Apparently the latter overrides the first box. I unchecked the Show counts on browser icon, saved, then checked a post… the counter showed up!

I also found one little nuance. When a user posts a link and OneBox tries and fails to OneBox it - leaving the link as is - the link click counter will not work if the link isn’t preceded with a blank space. I just edited a user’s post where this just occurred, adding the space, and the counter began showing. :wink:

2 个赞

@dax 对于为何此设置是显示 onebox 点击徽章的必要条件,您有什么看法吗?我可以为我的站点更改此设置,但若要使其发挥作用,我不得不批量更改 7400 多名用户的设置,而我并不想这么做,因为这只会引起混淆。

2 个赞

我也不明白你为何要费心,因为单盒点击量无论如何都不会被计入,除非是那些点击最不显眼链接的少数人。这意味着,你本可以选择不显示任何点击数据,却反而展示了错误的数据(人为偏低),在我看来,这要糟糕得多。

1 个赞

说得对——理想情况下,onebox 也应该统计其标题的点击次数。

4 个赞

我创建了一个主题组件,用于统计其标题的点击次数。

3 个赞

这以前确实有效。Onebox 点击量在我们网站上会被统计。但后来不知从何时起就不起作用了。我记不清确切时间,但我觉得已经不止一年了。我认为这是一个回归问题,而不是真正的功能请求。

@evantill,能否详细说明一下你的组件具体是做什么的?

1 个赞

这看起来是一小段 JavaScript,假设它能正常工作,可以直接添加到核心代码中。

只是一个简单的脚本,用于将点击 onebox 内部链接的操作替换为点击标题栏链接的操作。

    // 如果点击发生在 onebox 主体内部
    $('.onebox-body a').on('click.onebox-track-url', function(event) {      
      event.preventDefault(); // -> 忽略 onebox 内部的点击事件
      var headerUrl = $(event.target).closest('.onebox').find('header a'); // 选择标题栏链接
      // 改为点击标题栏链接以更新追踪计数器
      if (headerUrl.length > 0) {
        headerUrl[0].click(); // -> 模拟点击标题栏链接
      }
    });
</script>
1 个赞

看起来 onebox 主体内的链接未被追踪:

如果链接位于 .onebox-body 中,isValidLink() 会返回 false。

1 个赞

一个解决方案是在 onebox 中添加一个新设置,以启用对 onebox 内部链接的跟踪,并在该情况下为 onebox 内的链接添加 track-link 类?

1 个赞

从这个讨论串中,我不清楚停止追踪 onebox 点击是有意为之的决定,还是仅仅是一个可以提交拉取请求(pull request)来修复的 bug。

3 个赞

将拟议的修复方案描述为以下内容是否正确?

“如果链接位于 onebox 主体内,则查找该 onebox 的 URL。如果该 URL 与链接相同,则统计点击次数;否则忽略。”

4 个赞

Onebox 中除了被 oneboxed 的 URL 之外,还能包含其他链接吗?我原以为是不行的。

我在下方的提交中添加了此功能

5 个赞