Skip to content

Commit

Permalink
feat(web-analytics): Display viewport-related statistics (#27078)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
rafaeelaudibert and github-actions[bot] authored Dec 26, 2024
1 parent 34a4f6b commit 79a1c30
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13267,6 +13267,7 @@
"InitialUTMSourceMediumCampaign",
"Browser",
"OS",
"Viewport",
"DeviceType",
"Country",
"Region",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ export enum WebStatsBreakdown {
InitialUTMSourceMediumCampaign = 'InitialUTMSourceMediumCampaign',
Browser = 'Browser',
OS = 'OS',
Viewport = 'Viewport',
DeviceType = 'DeviceType',
Country = 'Country',
Region = 'Region',
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ const BreakdownValueTitle: QueryContextColumnTitleComponent = (props) => {
return <>Browser</>
case WebStatsBreakdown.OS:
return <>OS</>
case WebStatsBreakdown.Viewport:
return <>Viewport</>
case WebStatsBreakdown.DeviceType:
return <>Device Type</>
case WebStatsBreakdown.Country:
Expand Down Expand Up @@ -173,6 +175,16 @@ const BreakdownValueCell: QueryContextColumnComponent = (props) => {
const { breakdownBy } = source

switch (breakdownBy) {
case WebStatsBreakdown.Viewport:
if (Array.isArray(value)) {
const [width, height] = value
return (
<>
{width}x{height}
</>
)
}
break
case WebStatsBreakdown.Country:
if (typeof value === 'string') {
const countryCode = value
Expand Down Expand Up @@ -264,6 +276,8 @@ export const webStatsBreakdownToPropertyName = (
return { key: '$browser', type: PropertyFilterType.Event }
case WebStatsBreakdown.OS:
return { key: '$os', type: PropertyFilterType.Event }
case WebStatsBreakdown.Viewport:
return { key: '$viewport', type: PropertyFilterType.Event }
case WebStatsBreakdown.DeviceType:
return { key: '$device_type', type: PropertyFilterType.Event }
case WebStatsBreakdown.Country:
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export enum DeviceTab {
BROWSER = 'BROWSER',
OS = 'OS',
DEVICE_TYPE = 'DEVICE_TYPE',
VIEWPORT = 'VIEWPORT',
}

export enum PathTab {
Expand Down Expand Up @@ -1120,6 +1121,13 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
WebStatsBreakdown.Browser
),
createTableTab(TileId.DEVICES, DeviceTab.OS, 'OS', 'OS', WebStatsBreakdown.OS),
createTableTab(
TileId.DEVICES,
DeviceTab.VIEWPORT,
'Viewports',
'Viewport',
WebStatsBreakdown.Viewport
),
],
},
shouldShowGeographyTile
Expand Down
11 changes: 11 additions & 0 deletions posthog/hogql_queries/web_analytics/stats_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ def _counts_breakdown_value(self):
return ast.Field(chain=["properties", "$browser"])
case WebStatsBreakdown.OS:
return ast.Field(chain=["properties", "$os"])
case WebStatsBreakdown.VIEWPORT:
return ast.Tuple(
exprs=[
ast.Field(chain=["properties", "$viewport_width"]),
ast.Field(chain=["properties", "$viewport_height"]),
]
)
case WebStatsBreakdown.DEVICE_TYPE:
return ast.Field(chain=["properties", "$device_type"])
case WebStatsBreakdown.COUNTRY:
Expand Down Expand Up @@ -555,6 +562,10 @@ def where_breakdown(self):
match self.query.breakdownBy:
case WebStatsBreakdown.REGION | WebStatsBreakdown.CITY:
return parse_expr("tupleElement(breakdown_value, 2) IS NOT NULL")
case WebStatsBreakdown.VIEWPORT:
return parse_expr(
"tupleElement(breakdown_value, 1) IS NOT NULL AND tupleElement(breakdown_value, 2) IS NOT NULL"
)
case (
WebStatsBreakdown.INITIAL_UTM_SOURCE
| WebStatsBreakdown.INITIAL_UTM_CAMPAIGN
Expand Down
1 change: 1 addition & 0 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ class WebStatsBreakdown(StrEnum):
INITIAL_UTM_SOURCE_MEDIUM_CAMPAIGN = "InitialUTMSourceMediumCampaign"
BROWSER = "Browser"
OS = "OS"
VIEWPORT = "Viewport"
DEVICE_TYPE = "DeviceType"
COUNTRY = "Country"
REGION = "Region"
Expand Down

0 comments on commit 79a1c30

Please sign in to comment.