Skip to content

Commit

Permalink
fix(web-analytics): Make channel type comparison case-insensitive (#2…
Browse files Browse the repository at this point in the history
…3182)

* Make channel type comparison case-insensitive

* Add comment
  • Loading branch information
robbie-c authored and timgl committed Jun 27, 2024
1 parent 15c3ac0 commit a3797ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 9 additions & 3 deletions posthog/hogql/database/schema/channel_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def wrap_with_null_if_empty(expr: ast.Expr) -> ast.Expr:
args=[ast.Call(name="nullIf", args=[expr, ast.Constant(value="")]), ast.Constant(value="null")],
)

def wrap_with_lower(expr: ast.Expr) -> ast.Expr:
return ast.Call(
name="lower",
args=[expr],
)

# This logic is referenced in our docs https://posthog.com/docs/data/channel-type, be sure to update both if you
# update either.
return parse_expr(
Expand Down Expand Up @@ -131,9 +137,9 @@ def wrap_with_null_if_empty(expr: ast.Expr) -> ast.Expr:
)""",
start=None,
placeholders={
"campaign": wrap_with_null_if_empty(campaign),
"medium": wrap_with_null_if_empty(medium),
"source": wrap_with_null_if_empty(source),
"campaign": wrap_with_lower(wrap_with_null_if_empty(campaign)),
"medium": wrap_with_lower(wrap_with_null_if_empty(medium)),
"source": wrap_with_lower(wrap_with_null_if_empty(source)),
"referring_domain": referring_domain,
"gclid": wrap_with_null_if_empty(gclid),
"gad_source": wrap_with_null_if_empty(gad_source),
Expand Down
20 changes: 20 additions & 0 deletions posthog/hogql/database/schema/test/test_channel_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,23 @@ def test_duckduckgo_paid_click(self):
# "https://l.facebook.com/",
# ),
# )

def test_zendesk_ticket_14945(self):
# see https://posthoghelp.zendesk.com/agent/tickets/14945

# In this ticket, a customer's paid social traffic was incorrect tagged as organic social, because we
# didn't recognise the word "Paid" with an uppercase 'P' as a paid source. Really, this should have
# been case-insensitive, and that is what the fix was.
self.assertEqual(
"Paid Social",
self._get_session_channel_type(
{
"utm_source": "Facebook",
"utm_medium": "Paid",
"utm_campaign": "Foo",
"referring_domain": "l.facebook.com",
"gclid": "",
"gad_source": "",
}
),
)

0 comments on commit a3797ce

Please sign in to comment.