top of page

Mastering Lead Scoring: A Comprehensive Guide to Marketing Qualified Leads (MQL)

  • Writer: John Brown
    John Brown
  • Oct 1
  • 3 min read

Updated: Nov 4

When it comes to CRM and marketing automation, one of the biggest challenges is separating curious browsers from conversion-ready prospects. That’s where lead scoring comes in. By defining what makes a Marketing Qualified Lead (MQL) and applying consistent scoring rules, marketing and sales teams can focus on the people most likely to convert.


In this post, we’ll show you how to:

  • Define a clear MQL rule (valid email + at least one open event).

  • Write SQL queries (Postgres + BigQuery) to score leads in your database.

  • Use a Python script to score and aggregate leads directly from CSV exports.

  • Break down MQL performance by UTM source and lead creation date.


This is a step-by-step, practical guide you can drop into your workflow today.



What Is a Marketing Qualified Lead (MQL)?


An MQL is a lead that’s more likely to become a customer based on engagement signals. While definitions vary across organizations, our simple rule is:


✅ The lead’s email is valid (i.e., not bounced).

✅ The lead has at least one email open event recorded.


This makes the scoring model straightforward, measurable, and easy to implement across CRM systems.


Why Break Down by UTM Source and Creation Date?


If you’re spending money on multiple marketing channels, you need to know:

  • Which UTM sources (Google Ads, Facebook, Newsletter, etc.) deliver the highest-quality leads.

  • How lead quality changes over time — for example, did a new campaign last month drive more MQLs than the month before?


By grouping MQL data by UTM source and lead creation date, you gain visibility into campaign effectiveness and ROI.



SQL for Lead Scoring


If you have a relational database, you can identify MQLs and roll up stats with a single query. Below are two versions: one for Postgres, one for BigQuery.


Postgres Example


```sql

SELECT

lead_id,

email,

COUNT(open_event) AS open_events

FROM

leads

WHERE

email IS NOT NULL

GROUP BY

lead_id

HAVING

COUNT(open_event) > 0;

```


BigQuery Example


```sql

SELECT

lead_id,

email,

COUNT(open_event) AS open_events

FROM

`project.dataset.leads`

WHERE

email IS NOT NULL

GROUP BY

lead_id

HAVING

COUNT(open_event) > 0;

```


Python Script for CSV Data


If you export your leads and events as CSVs, a lightweight Python (pandas) script works perfectly.


Run it locally to score each lead and generate two reports:


  1. lead_scores.csv – every lead with its MQL score.

  2. mql_breakdown.csv – grouped by UTM source and created date.


👉 See the full script here: score_leads.py


Example Input & Output


Leads CSV


| lead_id | email |

|---------|----------------|

| 1 | example1@test.com |

| 2 | example2@test.com |


Events CSV


| event_id | lead_id | event_type | timestamp |

|----------|---------|------------|----------------------|

| 1 | 1 | open | 2025-07-01 10:00:00 |

| 2 | 2 | open | 2025-07-01 11:00:00 |


Breakdown Output

utm_source

created_date

leads

mqls

mql_rate

total_score

google

2025-07-01

1

1

1.0

100

facebook

2025-07-01

1

0

0.0

0

newsletter

2025-07-02

1

1

1.0

100


Why This Approach Works


  • Simplicity: Only two conditions define MQLs.

  • Flexibility: You can add more signals later (clicks, form fills, webinar signups).

  • Attribution-friendly: Breaking down by UTM source tells you which campaigns actually deliver quality leads.

  • Actionable: You can push these scores into your CRM or marketing automation platform for nurturing workflows.


Next Steps


  • Add scoring for email clicks, form completions, or demo requests.

  • Normalize UTM values (e.g., fb → facebook).

  • Automate nightly scoring with Airflow, dbt, or Prefect.

  • Build dashboards in Looker, Tableau, or Metabase.


Final Thoughts


Lead scoring doesn’t have to be complicated. By defining a simple MQL rule and tracking performance by UTM source and creation date, you create a scalable foundation for better marketing attribution and smarter sales handoffs.


If you’d like to try it, the full repo is here: GitHub: Lead MQL Scoring

 
 
 

Recent Posts

See All

Comments


bottom of page