-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Channels: backfill utm_medium based on click_param_id (#4833)
* Backfill utm_medium Follow-up to #4817 * Update backfill
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
priv/ingest_repo/migrations/20241118112238_backfill_utm_medium_click_id_param.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Plausible.IngestRepo.Migrations.BackfillUtmMediumClickIdParam do | ||
@moduledoc """ | ||
Backfills utm_medium based on referrer_source and click_id_param | ||
""" | ||
use Ecto.Migration | ||
|
||
def up do | ||
execute(fn -> repo().query!(update_query("events_v2")) end) | ||
execute(fn -> repo().query!(update_query("sessions_v2")) end) | ||
end | ||
|
||
def down do | ||
raise "irreversible" | ||
end | ||
|
||
defp update_query(table) do | ||
""" | ||
ALTER TABLE #{table} | ||
UPDATE utm_medium = multiIf( | ||
referrer_source = 'Google' AND click_id_param = 'gclid', '(gclid)', | ||
referrer_source = 'Bing' AND click_id_param = 'msclkid', '(msclkid)', | ||
utm_medium | ||
) | ||
WHERE empty(utm_medium) AND NOT empty(click_id_param) | ||
""" | ||
end | ||
end |