Skip to content

Commit

Permalink
Channels: backfill utm_medium based on click_param_id (#4833)
Browse files Browse the repository at this point in the history
* Backfill utm_medium

Follow-up to #4817

* Update backfill
  • Loading branch information
macobo authored Nov 19, 2024
1 parent 7316677 commit 9af4988
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.

### Added
- Dashboard shows comparisons for all reports
- UTM Medium report and API shows (gclid) and (msclkid) for paid searches when no explicit utm medium present.

### Removed
### Changed
Expand Down
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

0 comments on commit 9af4988

Please sign in to comment.