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.
--[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 ofYYYY-MM-DD
. - Data Selection: It selects two columns,
date
and the sum ofcount
, which is aliased aspageviews
. Thecount
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 typepage_view_anon
(req_type = 8
) and fall within the specified date range. - Aggregation: The
GROUP BY
clause groups the results by thedate
column, which allows theSUM
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:
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