Skip to content

Qualified in 60 Seconds - Ranking B2B Leads with a Python Script

When you’re looking for business leads, the more the merrier— until it comes to making sense of them all. Figuring out which leads should be pursued and which ones should not can be a tedious task at high volumes, which is exactly the problem that a large B2B Gupta Media client had. 25,000 leads later, hand-picking the strong ones was no longer effective. We set out to develop a streamlined system that filters the leads more efficiently while also incorporating lead-quality analysis into our paid media reporting.

What is a Good Lead?

Before anything could be automated, we first had to define the criteria that comprised a qualified lead. In practice, this will differ significantly based on the business, the goal, the campaign, and so on. For this B2B client, we established the following:

Positive Indicators:

  • The subject worked at a company that is in a targeted field
  • The subject’s email domain matched or was similar to their company name, affirming legitimacy
  • The subject had a job title that was relevant

Negative Indicators:

  • The subject’s email ended in “.edu”, since we needed to exclude students
  • The subject’s email contained a generic domain name like “gmail”
  • The lead contained spam such as “The Boss” as a job title, or “My Business” as a company name

We assigned these rules to four different tiers, and, based on how many are met in each tier, a lead is categorized as a High, Medium, Low, or Worst. This system later served as the logic for our script’s automated sorting.

Bringing our Lead Scoring Machine to Life

Our raw data consisted of four separate CSV files, each stemming from a different lead source. Because the files were structured differently, we wrote a SQL script that extracted the necessary fields and combined the tables into one. This singular table detailed who submitted the lead, and also included other data points beyond what is needed to determine lead quality.

For example, we isolated the UTM Tags from the lead’s Source URL to tell us if the lead was driven by our paid media, and if so, which platform, campaign, and ad group it is attributed to. We also included the lead subject’s User IP, with the intent of performing geographic analysis on our dataset. 

With our raw data filtered and unified, it was imported into our Python script in which we brought our previously defined logic to life. We then defined various lists and functions used for the analysis, such as the names of the Top 2000 global companies, and a function that compares the similarity between two strings (for example, an email domain and a company name). Next, a function for each tier is defined, containing tests for each of that tier’s criteria, and returning a count and list of the all criteria met for that tier. After those have been defined, every lead is sent through a logic tree where it is tested against criteria in each tier and is assigned a quality level depending on the counts of criteria met within the different tiers. Finally, our dataset of leads and their newly assigned qualitative information gets formatted and exported back into our data warehouse as a new table.

The end result was a Python script that is able to ingest, rank, and export 25,000 leads in 60 seconds.

Implementing our Findings 

With the qualitative lead data in our data warehouse, it was imported into a data visualization dashboard, where we were able to explore high-level findings such as the percentage of “good” leads from a specific country. Or, using the UTM Tags that we extracted from the leads’ Source URLs, we could key our leads to ad group level platform spends and performance data, allowing us to calculate metrics such as Cost per Good Lead for a specific ad group, or optimize ad group bids based on how we know a specific ad group is converting.

When our client needed the ability to sift through their leads quickly, we not only helped them meet that need but also used the opportunity to make our reporting more powerful and our spending more efficient. Now, our client can filter through their leads by quality and ensure they are acting on the best leads possible. And, Gupta Media is able to enhance our lead-gen marketing strategies better than before.

We love a good challenge. Bring us yours.

Get in touch!