← Problems60. Normalize campaign tracking parametersEasyPython
00:00 / 20:00

Normalize campaign tracking parameters

EasyNot attempted yetAsked at Adobe

Landing page hits arrive with campaign tracking parameters bolted onto the URL by whoever built the link, so the same campaign appears under a dozen spellings. Normalize them before they reach the warehouse.

Input schema

solve(urls: list[str]) -> list[dict]

Return one dict per URL, in the order given, with keys in this order:

url, source, medium, campaign

Constraints

  • Read utm_source, utm_medium and utm_campaign; parameter names match case-insensitively
  • Values are percent-decoded, + means a space, then trimmed and lowercased
  • A parameter that is absent, or present with an empty value, is None
  • If a parameter appears more than once, the first occurrence wins
  • url is returned exactly as it was given, unchanged
  • Ignore every other parameter, and anything after a # fragment
  • Up to 2,000,000 URLs

Example 1a plain link and one with no parameters

Input · urls
[
  "https://example.com/pricing?utm_source=Newsletter&utm_medium=Email&utm_campaign=Spring_Launch",
  "https://example.com/pricing"
]
Output
urlsourcemediumcampaign
https://example.com/pricing?utm_source=Newsletter&utm_medium=Email&utm_campaign=Spring_Launchnewsletteremailspring_launch
https://example.com/pricingnullnullnull

Example 2encoded spaces and an empty value

Input · urls
[
  "https://example.com/a?utm_source=Paid%20Search&utm_medium=&utm_campaign=q1+push"
]
Output
urlsourcemediumcampaign
https://example.com/a?utm_source=Paid%20Search&utm_medium=&utm_campaign=q1+pushpaid searchnullq1 push

Topics

string aggregationdata quality

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.py
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8⌘↵ run ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.