Elixir library and Mix task. Give it a CSV of ad campaign totals (impressions, clicks, spend, leads) and it prints, for every campaign and for the total, the click-through rate, cost per click, cost per thousand impressions, cost per lead and click-to-lead rate.
Formulas: CTR % = clicks / impressions 100, CPC = spend / clicks, CPM = spend / impressions 1000, CPL = spend / leads, click-to-lead % = leads / clicks * 100. Any ratio with a zero denominator prints n/a. Money (no currency symbol) and percentages are shown to 2 decimals, rounded half up; the arithmetic is exact, with no floating point drift. The total line sums the columns and then computes the ratios, it does not average the campaign ratios. Impressions, clicks and leads must be non-negative whole numbers and spend a non-negative number such as 480 or 480.50. A campaign with more clicks than impressions, a bad number, missing columns or a missing file stops the run with an error naming the line (and the campaign) and a non-zero exit.
Part of the OneGTMLab free GTM tools. Background on the idea: LinkedIn ads.
Install
{:linkedin_ad_metrics, "~> 1.0"} # in mix.exs depsUse
CSV columns: campaign, impressions, clicks, spend, leads.
$ mix linkedin_ad_metrics sample.csv
campaign impressions clicks spend leads CTR % CPC CPM CPL click-to-lead %
Campaign A 12000 96 480.00 6 0.80 5.00 40.00 80.00 6.25
Campaign B 8000 40 260.50 0 0.50 6.51 32.56 n/a 0.00
Campaign C 25000 300 1350.75 15 1.20 4.50 54.03 90.05 5.00
Campaign D 3000 0 45.00 0 0.00 n/a 15.00 n/a n/a
--------------------------------------------------------------------------------------------
Total 48000 436 2136.25 21 0.91 4.90 44.51 101.73 4.82
Test
mix testOffline, no network calls, no dependencies beyond the language runtime. MIT licensed.