【问题标题】:Designing a simple system to track the number of times links have been clicked设计一个简单的系统来跟踪链接被点击的次数
【发布时间】:2014-09-11 20:24:46
【问题描述】:

我一直在思考如何在 Meteor 应用程序中跟踪和计算点击次数。

我有一个指向外部网站的链接列表,我想计算它们被点击的次数。该链接应该在模态/ iframe 中打开,这样用户就不会被重定向到外部站点。我会在模式上创建一个选项,以便在新窗口/选项卡中打开页面。

到目前为止,我想出的唯一解决方案是使用包含 hashid hashid=sdfkljn24krj23n 的链接,根据 db 检查 hashid 并从 db 返回相应的 URL,然后在 modal/iframe 中打开该 URL。

为了创建我想使用 hashids.node.js 的哈希值

我可以看到这样做可能会在数据库上变得复杂,因为我需要存储用户 ID、每个网站的点击次数、哈希值。我可能有多个哈希 id 到一个 url,所以我可以跟踪多个用户的点击。

我只想创建一个包含简单数据的基本报告:

user | number of clicks 
a    |        1
b    |        5
c    |        3


Total number of users | Total number of clicks
        3             |           9

这种方法听起来好吗?

【问题讨论】:

  • Google Analytics (google.com/analytics) 能否为您提供所需的数据?
  • 这可能很好,但我想实时向用户显示他们访问了多少链接。因此,一旦外部网站加载完毕,就将数字加一。
  • 看起来您可以将 onclick 操作添加到您的传出链接,并对您的应用进行 ajax 调用以跟踪点击。 (support.google.com/analytics/answer/1136920?hl=en)
  • 为此干杯.....我需要好好阅读它。暂时只想要一个简单的解决方案。
  • 我建议结合使用 'target' 属性和 'onclick' 事件,因为“notgoogle.com?hashid=dlsfjdks">Google</a>" 看起来像是网络钓鱼。

标签: javascript meteor


【解决方案1】:

使用 jQuery 的简单解决方案:

$('a').onclick(function (event) {

  // Get the current user, however you’re currently tracking that:
  var user = App.getUser();

  // Get the URL of the link that was clicked, by parsing your HashId:
  var url = App.parseHashId(event.target.href);

  // Update the UI with the new click counts:
  App.updateClickCounts( user, url );

  // Save this information to the server:
  $.post(App.getServerURL(), { user: user, url: url }, function ( data ) {
    // Optional: do something on success
  };
});

根据您的应用,酌情编写getUserparseHashIdgetServerURLupdateClickCounts 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    • 2013-07-23
    • 1970-01-01
    相关资源
    最近更新 更多