Is the info Top Referred Topics/ Top Traffic Sources stored in a table in the database?

对于流量来源,请尝试运行此查询。

该查询将返回流量来源的域名、在指定时间段内来自该来源的点击次数,以及从该来源链接到的不同主题的数量。结果按点击数降序排列。运行此查询需要设置 start_dateend_date 参数。日期格式应为 ‘yyyy-mm-dd’,例如 2020-01-09

该查询默认限制返回结果数量为 100。如需更改,请调整查询中的 LIMIT 值。

--[params]
-- date :start_date
-- date :end_date

WITH links AS (
SELECT
ind.name,
t.id AS topic_id
FROM incoming_links il
JOIN posts p
ON p.id = il.post_id
JOIN topics t
ON t.id = p.topic_id
JOIN incoming_referers ir
ON ir.id = il.incoming_referer_id
JOIN incoming_domains ind
ON ind.id = ir.incoming_domain_id
WHERE t.archetype = 'regular'
AND il.created_at::date BETWEEN :start_date::date AND :end_date::date
)
SELECT
name,
COUNT(name) AS clicks,
COUNT(DISTINCT topic_id) AS topics
FROM links
GROUP BY name
ORDER BY clicks DESC
LIMIT 100
7 个赞