Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 设计一个简单的系统来跟踪链接被点击的次数_Javascript_Meteor - Fatal编程技术网

Javascript 设计一个简单的系统来跟踪链接被点击的次数

Javascript 设计一个简单的系统来跟踪链接被点击的次数,javascript,meteor,Javascript,Meteor,我一直在思考如何在我的Meteor应用程序中跟踪和计算点击次数 我有一个指向外部网站的链接列表,我想计算一下它们被点击的次数。链接应该在模式/iframe中打开,这样用户就不会重定向到外部站点。我将在模式上创建一个选项,以便在新窗口/选项卡中打开页面 到目前为止,我提出的唯一解决方案是使用一个包含hashid hashid=sdfkljn24krj23n的链接,对照数据库检查hashid,并从数据库返回相应的URL,然后在modal/iframe中打开该URL 为了创建我想使用的hashid 我

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

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

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

为了创建我想使用的hashid

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

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

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


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

这种方法听起来合适吗?

使用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
  };
});

根据您的应用程序,编写适当的getUser、parseHashId、getServerURL和updateClickCounts函数。

Google Analytics会提供您所需的数据吗?可能会,但我想实时向用户显示他们访问了多少链接。因此,一旦外部站点加载完毕,就将这个数字增加1。看起来你可以向你的外发链接添加onclick操作,并对你的应用程序进行ajax调用以跟踪点击。为此干杯。。。。。我需要好好读一读。目前只需要一个简单的解决方案。我建议结合使用“target”属性和“onclick”事件,因为notgoogle.com?hashid=dlsfjdks>Google看起来像是钓鱼。