utm-parameter-audit
Crystal command line tool and library. It reads a CSV of links (columns link_id and url, its own small CSV parser: double quotes, "" escapes, line breaks inside quoted cells) and checks the UTM parameters in the text of each link. It is pure string work with no network and no URI library: the fragment (everything from the first #) is ignored, the query is the text after the first ?, it is split on &, each pair is split on the first = and the names are compared in lower case. A pair with no = has an empty value, and empty segments are skipped. Checks per link: utm_source, utm_medium or utm_campaign missing (each counted on its own; utm_term and utm_content are optional and never required); a utm_ parameter with an empty value; a utm_ value containing an upper-case letter; a utm_ value containing %20, + or a space; the same utm_ name twice; and a link with no query string at all (no ?). A link with no query string reports only that check, not the three missing-parameter checks. Values are compared as written, with no decoding. Across links, for utm_source, utm_medium and utm_campaign, it lists the values that differ only by case (each group shows the spellings and how many times each appears, most frequent first, ties by spelling). The output has the number of links, links with no problem, per check the number of links and the first 10 link ids, and the case-variant groups. The exit code is 0 when no link has a problem and there is no case-variant group, 1 otherwise, and 2 when the file cannot be read or the input is invalid. It reads the text of the links you give; it does not open them and does not know which names your analytics tool expects.
Part of the OneGTMLab free GTM tools. Background on the idea: automated LinkedIn content distribution.
Install
shards build # then ./bin/utm-parameter-audit
Use
Input: CSV with the columns link_id and url, any order, header case does not matter. An empty url counts as a link with no query string. A duplicate link_id (the message names it), a missing column, an empty file, a file with no data rows, a missing file or an unknown option stops the run with a message and exit code 2. The cmd below also prints the exit code (1 here, because the sample has problems).
$ bin/utm-parameter-audit sample.csv; echo "exit code: $?"
links: 10
links with no problem: 2
links with a problem: 8
check links first link ids
missing utm_source 0 -
missing utm_medium 0 -
missing utm_campaign 1 L3
empty utm value 1 L4
upper-case letter in utm value 2 L2, L8
space, + or %20 in utm value 2 L5, L9
same utm parameter twice 1 L6
no query string 1 L7
case variants (values that differ only by case)
utm_source: alpha (6), Alpha (1)
utm_campaign: spring (5), Spring (1)
result: problems found (exit code 1)
exit code: 1
Test
crystal spec
Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.