contacts_per_domain_cap

Copy Markdown View Source

Elixir library and Mix task. Give it a CSV of contact ids and email addresses and a cap. In input order, the first cap contacts of each email domain are marked keep and every later one is marked over cap. It reports the number of contacts and domains, the domains over the cap and the contacts over the cap with their share, and lists the first 20 domains over the cap with their contact ids.

The domain is the text after the last @, trimmed and lower-cased. An email with no @, an empty local part, an empty domain or a space inside is an error that names the row. --cap is a whole number of 1 or more; the default is 3 and the value is set by you. A domain with exactly cap contacts is not over the cap. Domains over the cap are sorted by contact count, highest first, then by domain, and each line shows all the ids of that domain in input order. Percentages have 1 decimal, rounded half up. Extra columns are ignored.

With --out FILE the task writes contact_id, email, domain and decision (keep or over cap) for every row in input order, creates the folder if needed and says where the file went. The sample command below writes to tmp/, which is ignored by git. Duplicate contact ids (trimmed, case-insensitive) are an error that names the id. Exit code 2 means the input could not be read or the arguments are wrong: a bad --cap, an unknown option, a missing column, no rows or a missing file.

What it does not do: every domain is counted the same, including a domain that belongs to a mailbox provider rather than a company; you decide what to do with those. It does not check that an address exists, does not change your file and reads no outside data.

Part of the OneGTMLab free GTM tools. Background on the idea: ZoomInfo.

Install

{:contacts_per_domain_cap, "~> 1.0"}   # in mix.exs deps

Use

CSV columns: contact_id, email. The sample has 13 contacts on 4 domains: example.com has 6 (3 over the cap of 3), example.org has 4 (1 over), example.net has 2 and example.io has 1. That is 4 of 13 contacts over the cap (30.8%).

$ mix contacts_per_domain_cap sample.csv --cap 3 --out tmp/kept.csv
contacts: 13
domains: 4
cap: 3 contacts per domain (set by you)
domains over the cap: 2
contacts over the cap: 4 (30.8% of contacts)
domains over the cap (count desc, then domain):
  example.com: 6 contacts: c01, c02, c03, c04, c08, c12
  example.org: 4 contacts: c05, c06, c09, c10
wrote 13 rows to tmp/kept.csv

Test

mix test

Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.