# Dashboard Report - Anonymous

**URL:** https://meta.discourse.org/t/dashboard-report-anonymous/289114
**Category:** Data & reporting
**Tags:** sql-query, dashboard-reports, dashboard-sql
**Created:** [December 18, 2023, 10:55pm UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114 "2023-12-18T22:55:32Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![SaraDev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saradev/32/335139_2.png) [@SaraDev](https://meta.discourse.org/u/SaraDev)
#### Post date: [December 18, 2023, 10:55pm UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/1 "2023-12-18T22:55:32Z")

</div>

This is an SQL version of the Dashboard Report for Anonymous.

This report shows the number of pageviews a site has received each day from anonymous users (users who are not logged into an account) over a specified date range.

```sql
--[params]
-- date :start_date = 2023-12-01
-- date :end_date = 2024-01-01

SELECT 
    date, 
    SUM(count) AS pageviews
FROM
    application_requests
WHERE
    req_type = 8
    AND date BETWEEN :start_date AND :end_date
GROUP BY
    date
ORDER BY
     date

```

### SQL Query Explanation

- **Parameter Definition** : The query starts by defining two parameters, `:start_date` and `:end_date`, which are used to filter the data to the desired time frame. Both date parameters accept the date format of `YYYY-MM-DD` .
- **Data Selection** : It selects two columns, `date` and the sum of `count`, which is aliased as `pageviews`. The `count` represents the number of pageviews for each record.
- **Data Source** : The data is sourced from the `application_requests` table, which logs various types of requests made to the application.
- **Filtering** : The `WHERE` clause filters records to include only those that are of type `page_view_anon` (`req_type = 8`) and fall within the specified date range.
- **Aggregation** : The `GROUP BY` clause groups the results by the `date` column, which allows the `SUM` function to calculate the total pageviews for each date.
- **Sorting** : Finally, the results are ordered by the `date` in ascending order, providing a chronological view of the anonymous pageviews.

### Example Results

| date | pageviews |
| --- | --- |
| 2023-12-01 | 12345 |
| 2023-12-02 | 11346 |
| 2023-12-03 | 18344 |
| 2023-12-04 | 15344 |
| 2023-12-05 | 12890 |
| … | … |

### Notes on `req_type`

The `req_type` column in the `application_requests` table categorizes the type of request. In this query, we are interested in `req_type = 8` , which corresponds to anonymous pageviews.

Other `req_type` values represent different kinds of requests, such as crawler page views, logged in page views, and various HTTP response statuses.

_All `req_type` Values:_

```plaintext
0. http_total
1. http_2xx
2. http_background
3. http_3xx
4. http_4xx
5. http_5xx
6. page_view_crawler
7. page_view_logged_in
8. page_view_anon
9. page_view_logged_in_mobile
10. page_view_anon_mobile
11. api
12. user_api

```

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [December 18, 2023, 11:29pm UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/2 "2023-12-18T23:29:05Z")

</div>

Should this one be `req_type IN (8,10)` to include the mobile numbers too?

---

<div class="post-metadata">

### Author: ![SaraDev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saradev/32/335139_2.png) [@SaraDev](https://meta.discourse.org/u/SaraDev)
#### Post date: [December 18, 2023, 11:46pm UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/3 "2023-12-18T23:46:29Z")

</div>

I was originally considering that as well, but the admin dashboard report only includes `page_view_anon`, and not `page_view_anon_mobile`.

With the way this query is now, it is a true mirror of the dashboard report, and you can verify this by running the query and comparing against the dashboard report results.

Which does bring up a different, but related question - should the dashboard report include anonymous mobile pageviews?

Intuitively, I would think yes, but it would be interesting to hear other thoughts about this.

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [December 18, 2023, 11:56pm UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/4 "2023-12-18T23:56:53Z")

</div>

> [@SaraDev](#):
>
> should the dashboard report include anonymous mobile pageviews?

I can’t think of a reason not to include them.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [December 19, 2023, 12:11am UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/5 "2023-12-19T00:11:25Z")

</div>

> [@SaraDev](#):
>
> With the way this query is now, it is a true mirror of the dashboard report, and you can verify this by running the query and comparing against the dashboard report results.

Ah, sorry. I should’ve been more specific in my comment. I did clock that this one was an exact replica and I meant that the dashboard report itself should include it. 🙏

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [December 19, 2023, 7:30am UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/6 "2023-12-19T07:30:29Z")

</div>

Sorry, it’s morning here and I need more coffee, so I hit against language wall hard.

Are you thinking now should tot include mobiles too in the meaning mobiles are excluded now? Or should it show two metrics, actual total views AND mobile views?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [December 19, 2023, 8:46am UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/7 "2023-12-19T08:46:15Z")

</div>

At the moment, the dashboard report currently only seems to include the one req\_type (8) which means it’s only counting desktop anon views.

We’re wondering why it’s not counting the mobile data as well (either just as a total, or as two numbers so you can see it in more detail).

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [December 19, 2023, 8:57am UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/8 "2023-12-19T08:57:10Z")

</div>

It can’t be true or it counts bots too. By that I have around 1000 a day and that sounds right. But I know I have very small amount desktops. And situation where I would have 1000 deskstops and 9000 mobiles (yes, the ratio is that) it can’t be true.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [December 19, 2023, 1:08pm UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/9 "2023-12-19T13:08:11Z")

</div>

Hmm. I’m not sure. I think the code is here:

> <https://github.com/discourse/discourse/blob/main/lib/middleware/request_tracker.rb#L65-L82>

There’s a possibility that `page_view_anon_mobile` is a subset of `page_view_anon`. Hopefully someone who knows how to read this can chip in and advise. 🙂 🤞

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [December 21, 2023, 12:18am UTC](https://meta.discourse.org/t/dashboard-report-anonymous/289114/10 "2023-12-21T00:18:38Z")

</div>

> [@JammyDodger](#):
>
> ```plaintext
> elsif !SiteSetting.login_required
> ApplicationRequest.increment!(:page_view_anon)
> ApplicationRequest.increment!(:page_view_anon_mobile) if data[:is_mobile]
> end
> 
> ```

Huh. Yeah that logic would increment `page_view_anon` whether or not the page view is classified as from a mobile device. I think I need to update some queries . . .
