# Badge based on link stats?

**URL:** https://meta.discourse.org/t/badge-based-on-link-stats/29018
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [May 20, 2015, 2:56am UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018 "2015-05-20T02:56:16Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jesselperry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesselperry/32/119501_2.png) [@jesselperry](https://meta.discourse.org/u/jesselperry)
#### Post date: [May 20, 2015, 2:56am UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018/1 "2015-05-20T02:56:16Z")

</div>

Would there be any way to run a badge query on number of clicks on a link? I find that users will click a link and it will be really popular, but the topic originator never gets any likes to the post (or far less than the number of clicks to the website).

Any way to run a badge query on that?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [May 20, 2015, 3:22am UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018/2 "2015-05-20T03:22:49Z")

</div>

That is a very good idea for a badge. Maybe we can slot that for 1.4, as we like to add at least one useful (encourages “good” behavior) badge each release.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 20, 2015, 4:17am UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018/3 "2015-05-20T04:17:30Z")

</div>

[https://meta.discourse.org/badges/124/popular-link](https://meta.discourse.org/badges/124/popular-link)

SQL

```plaintext
select l.user_id, post_id, min(l.created_at) granted_at
from topic_links l
join posts p on p.id = post_id and p.deleted_at IS NULL
join topics t on t.id = p.topic_id and t.deleted_at IS NULL and t.archetype <> 'private_message'
where not internal and clicks >= 50
group by l.user_id, l.post_id

```

@codinghorror I don’t mind adding this in for current release … seems pretty simple, your call

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [May 20, 2015, 4:46am UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018/4 "2015-05-20T04:46:52Z")

</div>

It is fine to wait, no need to rush badges.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [May 20, 2015, 7:07am UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018/5 "2015-05-20T07:07:25Z")

</div>

> [@sam](#):
>
> min(l.created\_at) granted\_at

If the badge is bronze, nobody’s ever going to receive a notification for that; the granted\_at will be too old. You’re going to have to use row\_number() to get the correct date for the badge.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [August 27, 2015, 4:55pm UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018/6 "2015-08-27T16:55:25Z")

</div>

These badges are now officiel 🐄

[https://github.com/discourse/discourse/commit/d96531b1635b461b423a6a36a20299cf72ef0ed1](https://github.com/discourse/discourse/commit/d96531b1635b461b423a6a36a20299cf72ef0ed1)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 27, 2015, 7:46pm UTC](https://meta.discourse.org/t/badge-based-on-link-stats/29018/7 "2015-08-27T19:46:32Z")

</div>


