简体   繁体   English

如何可靠地计算链接的点击次数

[英]How to count clicks for links reliably

I have a REST API which has an endpoint for increasing click_count for a certain link. 我有一个REST API,该API的端点可以增加特定链接的click_count。 More precisely it is a python based django-rest-framework. 更确切地说,它是基于python的django-rest-framework。

In addition, I have a website which contains links. 另外,我有一个包含链接的网站。 I would like to count how many times a particular link has been visited (as clicks) from my site by a unique visitor. 我想计算唯一访问者从我的网站访问过特定链接(作为点击)的次数。

I would like to achieve this as reliable as possible. 我想做到这一点尽可能可靠。 If a single user clicks link multiple times, there would be only one (1) new click for that particular link. 如果单个用户多次单击链接,则该特定链接将只有一(1)次新点击。 So duplicates not allowed. 因此,不允许重复。 Website is done with angularjs and nodejs. 网站由angularjs和nodejs完成。

How do I make API endpoint available for only one increase operation by user and what would be the best practice for that? 如何使API端点仅可用于用户一次增加操作,最佳做法是什么?

If you're using a service between your controller and api you could just add a 'clicked' variable to the service and update it to true the first time you call the api to update the click count. 如果您在控制器和api之间使用服务,则可以在服务中添加一个“ clicked”变量,并在首次调用api来更新点击计数时将其更新为true。

If you have an log in, you could keep a dictionary on the api with the user ids as keys and a boolean for whether the user has incremented the click_count. 如果您已登录,则可以在api上保留一个词典,其中将用户ID作为键,并提供一个布尔值,用于表示用户是否增加了click_count。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM