Skip to content

Commit

Permalink
Add conversion rate column
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeelaudibert committed Dec 3, 2024
1 parent 1e8365e commit 451eb19
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions posthog/hogql_queries/web_analytics/stats_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,23 @@ def calculate(self):
else response.columns
)

# Add last conversion rate column
if self.query.conversionGoal is not None:
for result in results_mapped:
unique_visitors = result[1]
unique_conversions = result[-1]

# Keep them in the same tuple format we already have
result.append(
(
unique_conversions[0] / unique_visitors[0] if unique_visitors[0] != 0 else None,
unique_conversions[1] / unique_visitors[1] if unique_visitors[1] != 0 else None,
)
)

# Guarantee new column exists
columns.append("context.columns.conversion_rate")

return WebStatsTableQueryResponse(
columns=columns,
results=results_mapped,
Expand Down

0 comments on commit 451eb19

Please sign in to comment.