Ghost/ghost/tinybird/pipes/trend.pipe
Hannah Wolfe 7c465a5fb5 Updated token handling to be in code
- When I went off, I quickly recreated all our endpoints with some new functionality
- However, I forgot that I was manually managing tokens, this meant the UI for stats broke with a token error
- Adding the tokens to the endpoint definitions should prevent this happening again, by automating the management of the token scopes
2024-09-19 11:32:49 +01:00

41 lines
1.2 KiB
Plaintext

DESCRIPTION >
Visits trend over time for the last 30 minutes, filling the blanks.
Works great for the realtime chart.
TOKEN "dashboard" READ
TOKEN "stats page" READ
NODE timeseries
DESCRIPTION >
Generate a timeseries for the last 30 minutes, so we call fill empty data points
SQL >
with (now() - interval 30 minute) as start
select addMinutes(toStartOfMinute(start), number) as t
from (select arrayJoin(range(1, 31)) as number)
NODE hits
DESCRIPTION >
Get last 30 minutes metrics gropued by minute
SQL >
%
select toStartOfMinute(timestamp) as t, uniq(session_id) as visits
from analytics_hits
where
site_uuid = {{String(site_uuid, 'mock_site_uuid', description="Tenant ID", required=True)}}
{% if defined(member_status) %}
and member_status IN {{ Array(member_status,'String') }}
{% end %}
and timestamp >= (now() - interval 30 minute)
group by toStartOfMinute(timestamp)
order by toStartOfMinute(timestamp)
NODE endpoint
DESCRIPTION >
Join and generate timeseries with metrics for the last 30 minutes
SQL >
select a.t, b.visits from timeseries a left join hits b on a.t = b.t order by a.t