Skip to content

Commit a76f8f7

Browse files
authored
Add files via upload
1 parent 248562c commit a76f8f7

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

dashboard_ENG.sql

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
--Dashbord : https://6c897994.us2a.app.preset.io/superset/dashboard/10/?native_filters_key=QY18IDYWkpHS3GEJC5Oz0IwFR_HpISJrRv3HS-y3crQdrgmjpqxOp4gyXeUYb9au
2+
-- Number of visitors
3+
select COUNT(distinct visitor_id)
4+
from sessions s
5+
where visitor_id is not null;
6+
7+
-- Most popular channel
8+
select source, count(source)
9+
from sessions
10+
group by source
11+
order by count(source) desc
12+
limit 1;
13+
14+
-- Most popular course
15+
select campaign, count(campaign)
16+
from sessions
17+
group by campaign
18+
order by count(campaign) desc
19+
limit 1;
20+
21+
-- Visitors by channel and date
22+
select date(visit_date), source, count(source)
23+
from sessions
24+
group by 1, 2
25+
order by 3 desc;
26+
27+
-- Pie chart by channels
28+
select source, count(source)
29+
from sessions
30+
group by 1
31+
order by 2 desc;
32+
33+
-- Pie chart by medium
34+
select medium, count(medium)
35+
from sessions
36+
group by 1
37+
order by 2 desc;
38+
39+
-- Pie chart by courses
40+
select campaign, count(campaign)
41+
from sessions
42+
group by 1
43+
order by 2 desc;
44+
45+
-- Mediums by date
46+
select date(visit_date), medium, count(medium)
47+
from sessions
48+
group by 1, 2
49+
order by 3 desc;
50+
51+
-- Courses by date
52+
select date(visit_date), campaign, count(campaign)
53+
from sessions
54+
group by 1, 2
55+
order by 3 desc;
56+
57+
-- Conversion from click to lead
58+
with l_c as (
59+
select date(created_at) as d, count(lead_id) as c
60+
from leads l
61+
group by 1
62+
),
63+
v_c as (
64+
select date(s.visit_date) as d, count(distinct s.visitor_id) as c
65+
from sessions s
66+
group by 1
67+
)
68+
select v_c.d as date, round((l_c.c * 1.00 / v_c.c) * 100, 3) as conversion
69+
from v_c
70+
inner join l_c on l_c.d = v_c.d;
71+
72+
-- Conversion from lead to deal by Last Paid Click
73+
select visit_date, (leads_count * 1.00 / purchase_count) * 100
74+
from aggregate_last_paid_click;
75+
76+
-- Advertising costs by channel
77+
select visit_date, utm_source, total_coast
78+
from aggregate_last_paid_click;
79+
80+
-- Advertising costs by courses
81+
select utm_campaign, total_coast
82+
from aggregate_last_paid_click;
83+
84+
-- Advertising return on investment
85+
select utm_campaign, revenue - total_coast
86+
from aggregate_last_paid_click
87+
group by 1;
88+
89+
-- Advertising return on investment
90+
select utm_source, revenue - total_coast
91+
from aggregate_last_paid_click
92+
group by 1;
93+
94+
-- Metrics
95+
select utm_source, utm_medium, utm_campaign, visit_date,
96+
total_cost / visitors_count as cpu,
97+
total_cost / leads_count as cpl,
98+
total_cost / purchases_count as cppu,
99+
(revenue - total_cost) / total_cost * 100 as roi
100+
from aggregate_last_paid_click;
101+
102+
-- Organic correlation by date
103+
select date(visit_date), medium, count(medium)
104+
from sessions
105+
group by 1, 2
106+
having medium = 'organic'
107+
order by 1;

0 commit comments

Comments
 (0)