Skip to content

Commit

Permalink
feat(web-analytics): Add new client session scoped props (#18357)
Browse files Browse the repository at this point in the history
Add new client session scoped props
  • Loading branch information
robbie-c authored Nov 2, 2023
1 parent e455481 commit 28c133d
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 22 deletions.
35 changes: 35 additions & 0 deletions frontend/src/lib/taxonomy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,41 @@ export const KEY_MAPPING: KeyMappingInterface = {
label: 'Exception',
description: 'Automatically captured exceptions from the client Sentry integration',
},
$client_session_initial_referring_host: {
label: 'Referrer Host',
description: 'Host that the user came from. (First-touch, session-scoped)',
examples: ['google.com', 'facebook.com'],
},
$client_session_initial_pathname: {
label: 'Initial Path',
description: 'Path that the user started their session on. (First-touch, session-scoped)',
examples: ['/register', '/some/landing/page'],
},
$client_session_initial_utm_source: {
label: 'Initial UTM Source',
description: 'UTM Source. (First-touch, session-scoped)',
examples: ['Google', 'Bing', 'Twitter', 'Facebook'],
},
$client_session_initial_utm_campaign: {
label: 'Initial UTM Campaign',
description: 'UTM Campaign. (First-touch, session-scoped)',
examples: ['feature launch', 'discount'],
},
$client_session_initial_utm_medium: {
label: 'Initial UTM Medium',
description: 'UTM Medium. (First-touch, session-scoped)',
examples: ['Social', 'Organic', 'Paid', 'Email'],
},
$client_session_initial_utm_content: {
label: 'Initial UTM Source',
description: 'UTM Source. (First-touch, session-scoped)',
examples: ['bottom link', 'second button'],
},
$client_session_initial_utm_term: {
label: 'Initial UTM Source',
description: 'UTM Source. (First-touch, session-scoped)',
examples: ['free goodies'],
},
},
element: {
tag_name: {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3174,6 +3174,9 @@
"InitialReferringDomain",
"InitialUTMSource",
"InitialUTMCampaign",
"InitialUTMMedium",
"InitialUTMTerm",
"InitialUTMContent",
"Browser",
"OS",
"DeviceType",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ export enum WebStatsBreakdown {
InitialReferringDomain = 'InitialReferringDomain',
InitialUTMSource = 'InitialUTMSource',
InitialUTMCampaign = 'InitialUTMCampaign',
InitialUTMMedium = 'InitialUTMMedium',
InitialUTMTerm = 'InitialUTMTerm',
InitialUTMContent = 'InitialUTMContent',
Browser = 'Browser',
OS = 'OS',
DeviceType = 'DeviceType',
Expand Down
20 changes: 16 additions & 4 deletions frontend/src/scenes/web-analytics/WebAnalyticsDataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const BreakdownValueTitle: QueryContextColumnTitleComponent = (props) => {
return <>UTM Source</>
case WebStatsBreakdown.InitialUTMCampaign:
return <>UTM Campaign</>
case WebStatsBreakdown.InitialUTMMedium:
return <>UTM Medium</>
case WebStatsBreakdown.InitialUTMTerm:
return <>UTM Term</>
case WebStatsBreakdown.InitialUTMContent:
return <>UTM Content</>
case WebStatsBreakdown.Browser:
return <>Browser</>
case WebStatsBreakdown.OS:
Expand Down Expand Up @@ -108,13 +114,19 @@ export const webStatsBreakdownToPropertyName = (breakdownBy: WebStatsBreakdown):
case WebStatsBreakdown.Page:
return '$pathname'
case WebStatsBreakdown.InitialPage:
return '$initial_pathname'
return '$client_session_initial_pathname'
case WebStatsBreakdown.InitialReferringDomain:
return '$initial_referrer'
return '$client_session_initial_referring_host'
case WebStatsBreakdown.InitialUTMSource:
return '$initial_utm_source'
return '$client_session_initial_utm_source'
case WebStatsBreakdown.InitialUTMCampaign:
return '$initial_utm_campaign'
return '$client_session_initial_utm_campaign'
case WebStatsBreakdown.InitialUTMMedium:
return '$client_session_initial_utm_medium'
case WebStatsBreakdown.InitialUTMContent:
return '$client_session_initial_utm_content'
case WebStatsBreakdown.InitialUTMTerm:
return '$client_session_initial_utm_term'
case WebStatsBreakdown.Browser:
return '$browser'
case WebStatsBreakdown.OS:
Expand Down
55 changes: 37 additions & 18 deletions posthog/hogql_queries/web_analytics/stats_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,29 @@ def calculate(self):
def counts_breakdown(self):
match self.query.breakdownBy:
case WebStatsBreakdown.Page:
return parse_expr("properties.$pathname")
return ast.Field(chain=["properties", "$pathname"])
case WebStatsBreakdown.InitialPage:
return parse_expr("properties.$set_once.$initial_pathname")
return ast.Field(chain=["properties", "$client_session_initial_pathname"])
case WebStatsBreakdown.InitialReferringDomain:
return parse_expr("properties.$set_once.$initial_referring_domain")
return ast.Field(chain=["properties", "$client_session_initial_referring_domain"])
case WebStatsBreakdown.InitialUTMSource:
return parse_expr("properties.$set_once.$initial_utm_source")
return ast.Field(chain=["properties", "$client_session_initial_utm_source"])
case WebStatsBreakdown.InitialUTMCampaign:
return parse_expr("properties.$set_once.$initial_utm_campaign")
return ast.Field(chain=["properties", "$client_session_initial_utm_campaign"])
case WebStatsBreakdown.InitialUTMMedium:
return ast.Field(chain=["properties", "$client_session_initial_utm_medium"])
case WebStatsBreakdown.InitialUTMTerm:
return ast.Field(chain=["properties", "$client_session_initial_utm_term"])
case WebStatsBreakdown.InitialUTMContent:
return ast.Field(chain=["properties", "$client_session_initial_utm_content"])
case WebStatsBreakdown.Browser:
return parse_expr("properties.$browser")
return ast.Field(chain=["properties", "$browser"])
case WebStatsBreakdown.OS:
return parse_expr("properties.$os")
return ast.Field(chain=["properties", "$os"])
case WebStatsBreakdown.DeviceType:
return parse_expr("properties.$device_type")
return ast.Field(chain=["properties", "$device_type"])
case WebStatsBreakdown.Country:
return parse_expr("properties.$geoip_country_code")
return ast.Field(chain=["properties", "$geoip_country_code"])
case WebStatsBreakdown.Region:
return parse_expr(
"tuple(properties.$geoip_country_code, properties.$geoip_subdivision_1_code, properties.$geoip_subdivision_1_name)"
Expand All @@ -119,23 +125,30 @@ def counts_breakdown(self):
def bounce_breakdown(self):
match self.query.breakdownBy:
case WebStatsBreakdown.Page:
return parse_expr("any(properties.$set_once.$initial_pathname)")
# use initial pathname for bounce rate
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$initial_pathname"])])
case WebStatsBreakdown.InitialPage:
return parse_expr("any(properties.$set_once.$initial_pathname)")
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$initial_pathname"])])
case WebStatsBreakdown.InitialReferringDomain:
return parse_expr("any(properties.$set_once.$initial_referring_domain)")
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$initial_referring_domain"])])
case WebStatsBreakdown.InitialUTMSource:
return parse_expr("any(properties.$set_once.$initial_utm_source)")
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$initial_utm_source"])])
case WebStatsBreakdown.InitialUTMCampaign:
return parse_expr("any(properties.$set_once.$initial_utm_campaign)")
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$initial_utm_campaign"])])
case WebStatsBreakdown.InitialUTMMedium:
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$initial_utm_medium"])])
case WebStatsBreakdown.InitialUTMTerm:
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$initial_utm_term"])])
case WebStatsBreakdown.InitialUTMContent:
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$initial_utm_content"])])
case WebStatsBreakdown.Browser:
return parse_expr("any(properties.$browser)")
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$browser"])])
case WebStatsBreakdown.OS:
return parse_expr("any(properties.$os)")
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$os"])])
case WebStatsBreakdown.DeviceType:
return parse_expr("any(properties.$device_type)")
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$device_type"])])
case WebStatsBreakdown.Country:
return parse_expr("any(properties.$geoip_country_code)")
return ast.Call(name="any", args=[ast.Field(chain=["properties", "$geoip_country_code"])])
case WebStatsBreakdown.Region:
return parse_expr(
"any(tuple(properties.$geoip_country_code, properties.$geoip_subdivision_1_code, properties.$geoip_subdivision_1_name))"
Expand All @@ -155,5 +168,11 @@ def where_breakdown(self):
return parse_expr("TRUE") # actually show null values
case WebStatsBreakdown.InitialUTMCampaign:
return parse_expr("TRUE") # actually show null values
case WebStatsBreakdown.InitialUTMMedium:
return parse_expr("TRUE") # actually show null values
case WebStatsBreakdown.InitialUTMTerm:
return parse_expr("TRUE") # actually show null values
case WebStatsBreakdown.InitialUTMContent:
return parse_expr("TRUE") # actually show null values
case _:
return parse_expr('"context.columns.breakdown_value" IS NOT NULL')
3 changes: 3 additions & 0 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ class WebStatsBreakdown(str, Enum):
InitialReferringDomain = "InitialReferringDomain"
InitialUTMSource = "InitialUTMSource"
InitialUTMCampaign = "InitialUTMCampaign"
InitialUTMMedium = "InitialUTMMedium"
InitialUTMTerm = "InitialUTMTerm"
InitialUTMContent = "InitialUTMContent"
Browser = "Browser"
OS = "OS"
DeviceType = "DeviceType"
Expand Down

0 comments on commit 28c133d

Please sign in to comment.