-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
212 lines (184 loc) · 6.11 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# app.py
import streamlit as st
import plotly.express as px
import plotly.graph_objects as go
from mock_data import MockDataGenerator
def render_overview_tab(mock_data):
col1, col2 = st.columns(2)
# Daily trends chart
daily_data = mock_data.generate_daily_data()
with col1:
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=daily_data['date'],
y=daily_data['impressions'],
name='Impressions',
line=dict(color='blue')
)
)
fig.add_trace(
go.Scatter(
x=daily_data['date'],
y=daily_data['clicks'],
name='Clicks',
line=dict(color='green'),
yaxis='y2'
)
)
fig.update_layout(
title='Daily Performance Trends',
yaxis=dict(title='Impressions'),
yaxis2=dict(title='Clicks', overlaying='y', side='right')
)
st.plotly_chart(fig, use_container_width=True)
# Campaign performance chart
with col2:
campaign_data = mock_data.generate_campaign_data()
fig = px.bar(
campaign_data,
x='campaign_name',
y=['clicks', 'conversions'],
title='Campaign Performance Overview',
barmode='group'
)
st.plotly_chart(fig, use_container_width=True)
def render_keywords_tab(mock_data):
keyword_data = mock_data.generate_keyword_data()
# Keyword performance chart
fig = px.scatter(
keyword_data,
x='impressions',
y='clicks',
size='conversions',
color='quality_score',
hover_data=['keyword', 'match_type', 'ctr'],
title='Keyword Performance'
)
st.plotly_chart(fig, use_container_width=True)
# Keyword table
st.dataframe(keyword_data)
def render_ads_tab(mock_data):
ad_data = mock_data.generate_ad_data()
# Ad performance chart
fig = go.Figure(data=[
go.Bar(name='Clicks', x=ad_data['headline'], y=ad_data['clicks']),
go.Bar(name='Conversions', x=ad_data['headline'], y=ad_data['conversions'])
])
fig.update_layout(title='Ad Performance', barmode='group')
st.plotly_chart(fig, use_container_width=True)
# Ad details
for _, row in ad_data.iterrows():
with st.expander(row['headline']):
col1, col2 = st.columns(2)
with col1:
st.metric("CTR", f"{row['ctr']}%")
st.metric("Clicks", row['clicks'])
with col2:
st.metric("Conversions", row['conversions'])
st.metric("Status", row['status'])
def render_audiences_tab(mock_data):
audience_data = mock_data.generate_audience_data()
# Audience size bubble chart
fig = px.scatter(
audience_data,
x='impressions',
y='conversions',
size='size',
color='clicks',
hover_data=['audience', 'cost'],
title='Audience Performance'
)
st.plotly_chart(fig, use_container_width=True)
# Audience metrics
st.dataframe(audience_data)
def render_benchmarks_tab(mock_data):
benchmark_data = mock_data.generate_benchmark_data()
# Benchmark comparison chart
fig = go.Figure()
for col in ['account_value', 'industry_avg', 'top_performer']:
fig.add_trace(go.Bar(
name=col.replace('_', ' ').title(),
x=benchmark_data['metric'],
y=benchmark_data[col]
))
fig.update_layout(title='Performance Benchmarks', barmode='group')
st.plotly_chart(fig, use_container_width=True)
def render_campaign_tab(mock_data):
campaign_data = mock_data.generate_campaign_data()
# Campaign scatter plot
fig = px.scatter(
campaign_data,
x='cost',
y='conversions',
size='clicks',
color='quality_score',
hover_data=['campaign_name', 'ctr', 'conv_rate'],
title='Campaign Performance Matrix'
)
st.plotly_chart(fig, use_container_width=True)
# Campaign metrics table
st.dataframe(campaign_data)
def render_competitor_tab(mock_data):
competitor_data = mock_data.generate_competitor_data()
fig = px.scatter(
competitor_data,
x='overlap_rate',
y='outranking_share',
size='top_of_page_rate',
color='position_above_rate',
hover_data=['competitor'],
title='Competitor Analysis'
)
st.plotly_chart(fig, use_container_width=True)
def render_recommendations_tab(mock_data):
recommendations = mock_data.generate_recommendations()
for rec in recommendations:
with st.expander(f"{rec['priority']} Priority - {rec['category']}"):
st.write(f"Description: {rec['description']}")
st.write(f"Potential Impact: {rec['impact']}")
st.write(f"Status: {rec['status']}")
def main():
st.set_page_config(page_title="Google Ads Account Audit Demo", layout="wide")
mock_data = MockDataGenerator()
st.title("Google Ads Account Audit Demo")
st.subheader("Account: Demo Account - Last 30 Days")
# Metrics row
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Total Spend", "$12,345", "+10%")
with col2:
st.metric("Conversions", "456", "+15%")
with col3:
st.metric("CTR", "2.4%", "-1%")
with col4:
st.metric("Quality Score", "7.5", "+0.5")
# All tabs
tabs = st.tabs([
"Overview",
"Campaigns",
"Keywords",
"Ads",
"Audiences",
"Competitors",
"Benchmarks",
"Recommendations"
])
with tabs[0]:
render_overview_tab(mock_data)
with tabs[1]:
render_campaign_tab(mock_data)
with tabs[2]:
render_keywords_tab(mock_data)
with tabs[3]:
render_ads_tab(mock_data)
with tabs[4]:
render_audiences_tab(mock_data)
with tabs[5]:
render_competitor_tab(mock_data)
with tabs[6]:
render_benchmarks_tab(mock_data)
with tabs[7]:
render_recommendations_tab(mock_data)
if __name__ == "__main__":
main()