How to get the number of views for a web page?

xuanbao · · 474 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I would like to get the no of views for a web page, similar to how stackoverflow gets the no of views for a post. I am using Golang. I am considering the following approach</p> <ul> <li>Take the ip address from the http request and increase the view count by one for unique ip addresses.</li> <li>And maintain an LRU/MRU cache with the ip address as the key with the TTL as one day. So the next day if we get a request from same address it will be counted.</li> </ul> <p>I have the following questions</p> <ul> <li>Is this the right approach or is there any other ways to achieve this using sessions etc.</li> <li>any improvements required on this approach?</li> <li>Does ip address makes the request unique for some amount of time?</li> <li>Is TTL one day ok? or should i reduce to few hours?</li> </ul> <p>Any suggestions would be really helpful.</p> <hr/>**评论:**<br/><br/>slimsag: <pre><p>Beware that counting based on IP means that multiple users under the same IP will not be counted. For example, hundreds of students inside a school computer center would be under the same IP.</p> <p>An alternative is to perform this based on sessions, i.e. a browser cookie (lookup how sessions work, you&#39;ll find a better description there than what I can give you).</p> <p>TTL of one day is also probably too stark. What if I come back and view the page within 10 minutes? I think the only thing you are probably trying to prevent is users who accidentally reload the page several times etc. I would use 5 mins.</p></pre>dineshappavoo: <pre><p>Thank you for the response. I will definitely check the google analytics which uses cookie. Yeah you are right I should consider about using unique ip and TTL. Thank you for all your comments. </p></pre>escape_goat: <pre><p>This is not actually much of a language issue, it is more of a common web development issue. As such, this is not the best forum to seek advice if your objective is &#34;count the unique page-views of a web page&#34; rather than &#34;count the unique page-views of a web page in my school/hobby golang project.&#34;</p> <p>If this <em>is</em> a hobby project, then the best approach would be to rely on a <a href="https://en.wikipedia.org/wiki/HTTP_cookie" rel="nofollow">cookie</a>, which I believe is covered by the godocs.</p></pre>slimsag: <pre><p>I definitely agree that checking some other generic programming forums would be great too. But, just for the record, I think we should also openly encourage asking questions like these in <a href="/r/golang" rel="nofollow">/r/golang</a> and in the Go community in general. We&#39;re all here to learn things about programming, too, not <em>just Go</em>, otherwise this forum would have very little to no content at all. I think you probably share this sentiment anyway, but just wanted to raise for others looking and misinterpreting your comment. :)</p></pre>escape_goat: <pre><p>I thought that the question was tending towards the low-effort end of the spectrum, but I generally share your sentiment with regards to what a suitable question would be. </p> <p>In this case, it&#39;s not so much that the answer could be found in some other programming forum, it&#39;s that the answer with regards to the best practices for this is in the domain of <em>web development</em> rather than <em>programming</em>; OP would probably be better served by a third-party analytics service than by rolling his own in any particular language. If he&#39;s building something to learn from, then trying to solve the unique hits problem in Go is perfectly warranted. Otherwise, though, things get more complicated.</p></pre>FIuffyRabbit: <pre><p>Generally (since the last time I checked), it is determined by ip address and a cookie. </p></pre>phlogisticfugu: <pre><p>build the system that records raw page loads and cookies separate from the deduping analysis. that way you can refine your deduping separate from the data.</p> <p>or, Google Analytics and it&#39;s cookies may be good enough</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

474 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传