---
id: agencias/origem-canal-do-lead
industry: Marketing agencies
usage: common
effort: medium
grain: One conversion event or one deal; client x channel x month for cost per lead
---

# Lead source and channel

One channel per lead for each client, decoded from a source that arrives in five formats, with each client's exceptions written down and a cost per lead by channel that adds up.

## Executive summary

**For:** Agencies that report leads and cost per lead by channel for clients with different RD Station setups, CRMs and forms.

**What it solves**

- Each lead has exactly one channel, with the rule that classified it next to it.
- Leads with no source become a visible row and an alert, not a generic channel that hides the problem.
- Cost per lead by channel divides spend by paid leads, not by the CRM total.

**Why it matters:** The client's most common question is where the leads came from, and the answer changes depending on the system queried. The source arrives encoded, empty or typed by hand, and integrations between systems generate events that look like conversions. Without a single cascade per client, budget follows the channel that shows up most, not the one that converts.

**Business questions it answers**

- Where did this month's leads come from, by client?
- How many leads were paid and how many organic?
- What is client X's cost per lead on Meta and on Google?
- Why does Google show more conversions than the CRM?
- How many leads had no source, and since when?

**What you need**

- RD Station Marketing and each client's CRM connected to Nekt
- The channel list and cascade order agreed with each client
- Each client's decisions on ambiguous sources, such as Desconhecido (Unknown)

**What you get**

- A lead table with channel, platform, applied rule and source format
- Cost per lead by channel and by platform using paid leads only
- An alert when the no-source share exceeds the client's limit
- An AI agent that explains the difference between platform, RD and CRM

## Detailed

### The problem

The lead source arrives in five formats in the same field: base64, query string, free text, app URL and empty. Integrations between the CRM and marketing automation write an event at every stage change, and base imports show up as conversions. Each client decides differently what to do with the Desconhecido (Unknown) source, and the platform, RD and GA4 count the same lead in different ways.

### Business rules

1. **Decode before concluding there is no source.** In RD Station, traffic_source may arrive as encoded_<base64>, holding a JSON of the first and last session; traffic_medium and traffic_campaign are almost always empty. Inside the JSON the source still shows up as UTMs, as the legacy __utmz cookie or as a raw URL. Classify each row by format and separate empty from unrecognized format: no source and a source we could not read are different states. (Avoid: Reading only utm_source and concluding there is no tracking.)
2. **Bulk loads and integrations are not conversions.** Exclude base import, CRM sync, integration, manual insert, mailing, blast, list and test events by event identifier. In real accounts, three quarters of conversion events were bulk loads, and a CRM to RD integration produced 9 out of 10 events. Use word boundaries: without them, a form called Fale com um Especialista (talk to a specialist) falls into the list filter. Flag the event as excluded instead of deleting it, so the difference can be explained. (Avoid: Counting every CONVERSION event_type.)
3. **The cascade belongs to each client and is data.** Each client has its own signal order: manual override, click identifier (gclid, gbraid, wbraid, fbclid, li_fat_id), paid UTM, UTM stored on the contact, session source, CRM Source field and, last, no source. Store the order and the terms of each channel in a per-client table, never copied from another client. Order changes the count: a short term like fb matches anywhere in the text. (Avoid: One cascade in code for the whole portfolio.)
4. **Store the rule that classified.** Each lead carries channel, platform, the rule that matched and the source format. When the client challenges a number, the answer shows why that lead is Meta and not organic, and a rule change becomes visible in the series. (Avoid: Only a channel column.)
5. **Unknown and no source are client decisions.** For one client, the Desconhecido (Unknown) source counts as digital, because almost all of those deals had a site conversion in the previous 30 days; (sem fonte) (no source) stays out, because it is sales creating deals by hand. For another client, Unknown does not count as paid. Record the decision, the date and the test that backed it. Test with a conversion in the 30 days before deal creation, not with the contact existing in the base, which absorbs almost everyone. (Avoid: Applying one client's decision to another.)
6. **No source is a row and an alert.** Unidentified never disguises itself as direct and is never prorated across channels. Show volume and share per month and alert when it passes the client's limit (15% and 25% were real limits). A jump from one week to the next is almost always broken tracking: a custom form that does not send source fields, a redirect that drops the query string or a chatbot with no UTM. (Avoid: Dumping no source into direct or other.)
7. **Native forms have a signature.** Lead Ads do not go through the site and arrive with no UTM. In RD, Meta native form conversions have an identifier ending in a hyphen and 9 or more digits, and forms with LINKEDIN in the name come from the LinkedIn native form. Classify by the signature before falling into no source. (Avoid: Leaving Lead Ads as no source.)
8. **Each system answers one question.** Lead, opportunity and sale by channel come from RD or the CRM, which tie the source to the person. Spend, clicks and platform conversions come from the platform, which credits on the click date and does not discount the other platform. Sessions and behavior come from GA4, which does not know the lead. GA4 channel and CRM channel are not summed or crossed. (Avoid: Adding Google and Meta conversions and calling it leads.)
9. **Cost per lead by channel with paid leads only.** Cost per lead = period spend / paid media leads created in the period. Cost per lead by platform = platform spend / that platform's leads. Organic, direct, chatbot with no source and Unknown stay out of the denominator. With no paid lead, cost per lead is null, not zero. Spend / all leads can appear alongside, labeled as a floor. (Avoid: Spend divided by every lead in the CRM.)
10. **Versioned manual overrides.** Leads confirmed by the team that have no UTM get their channel through a manual override, stored in a table with who, when and why, and applied at the top of the cascade. Never fix the channel directly in the output or in the report spreadsheet. (Avoid: Fixing the channel in the report spreadsheet.)

### Typical channel cascade

The first rule that matches wins. The order and the terms belong to each client.

- **Team manual override** → Channel entered (`override table`)
- **gclid, gbraid, wbraid, gad_source or google with cpc medium** → Google Ads
- **fbclid, or utm_source fb, ig, meta with a paid medium** → Meta Ads
- **li_fat_id or utm_source linkedin** → LinkedIn Ads
- **Identifier ending in -<9 or more digits>** → Meta native form
- **WhatsApp chatbot with no UTM and no medium** → WhatsApp with no source (`not paid`)
- **Social medium, no paid click** → Organic social
- **email medium or RD Station source** → Email
- **organic medium or search engine** → Organic search
- **Empty, direct or unrecognized format** → No source (`own row`)

### Definitions

| Metric | Definition |
|---|---|
| Lead | contact with its own conversion in the period (RD) or deal created in an in-scope pipeline (CRM), according to the client's declared lead source; bulk loads, integrations and tests excluded |
| Lead channel | channel of the lead's first own conversion in the period, through the client's cascade |
| Paid media lead | lead with at least one conversion in the period whose channel is Meta Ads, Google Ads or LinkedIn Ads |
| Cost per lead | period spend / paid media leads in the period; null with no paid lead |
| Cost per lead by platform | platform spend in the period / leads whose channel is that platform |
| Cost per lead floor | period spend / all leads; shown only labeled as a floor |
| No-source share | leads with no identified channel / total leads, by client and month |
| ID coverage | leads tied to a real campaign by ID (gad_campaignid, ad ID) / total leads |

### Pitfalls

- **A source that looked empty.** Medium and campaign fields were empty in almost every event and the team concluded there was no tracking. The source was in base64 inside traffic_source. How to avoid: Decode before classifying.
- **An integration became a channel.** An integration between the CRM and marketing automation wrote an event at every stage change and multiplied conversions by ten. How to avoid: Exclude by event identifier and show exclusions separately.
- **The filter that ate the best form.** A list filter without word boundaries removed the Meta native form that generated the most leads. How to avoid: Word boundaries on every short term.
- **A break with a date.** The share of conversions with no source jumped from under 10% to about half from one week to the next, after a change to the site form. How to avoid: Track the share weekly and treat it as instrumentation, not analysis.
- **Chatbot with no campaign.** The WhatsApp chatbot arrived with the vendor's name as source and no medium, and accounted for about a fifth of the month's leads. How to avoid: Label it WhatsApp with no source and ask the vendor to pass the UTM. Do not redistribute by estimate.
- **Client name as a key.** Matching client labels between Google Ads and RD by name got few pairs right and merged different brands. How to avoid: Use the campaign ID and the account to client registry.

### Acceptance test

- [ ] Every lead has exactly one channel and one applied rule, and the sum of leads by channel equals total leads.
- [ ] No import, integration, mailing or test event enters the count, and exclusions appear separately with their identifier.
- [ ] For one client and month, the sum of paid leads by platform equals paid media leads, and cost per lead equals spend / paid leads.
- [ ] Rows with an unrecognized source format stay below 1% of the rows that have a source.
- [ ] No source appears as its own row, and the alert fires when the share passes the client's limit.

### Context document

```text
Lead source and channel
- Leads and lead channel come from RD Station or the CRM. The ad platform is for spend, clicks and platform conversions. GA4 is for sessions. Do not add or cross the three.
- traffic_source with the encoded_ prefix is base64 holding a session JSON: decode before classifying. Empty and unrecognized format are different states.
- Exclude import, CRM sync, integration, manual insert, mailing, blast, list (with word boundaries) and test events.
- Channel = first rule that matches in the client's cascade: manual override, click ID, paid UTM, contact UTM, session source, CRM Source field, no source.
- Identifier ending in -<9 or more digits> = Meta native form (paid).
- No source never becomes direct and is never prorated. If the share passes the client's limit, warn and say since when.
- Cost per lead = spend / paid media leads. With no paid lead, cost per lead is null.
- The platform credits the conversion on the click date and does not discount the others. When platform and CRM disagree, explain both counts instead of choosing one.
- A sale conversion showing on the platform may have been sent by the agency: it is not independent measurement.
Per-client exceptions:
- <client>: source Desconhecido (Unknown) counts as digital but not as paid; (sem fonte) (no source) stays out. Decision from <date>.
- <client>: no-source alert above <x>% of the month's leads.
- <client>: chatbot <name> with no UTM becomes WhatsApp with no source and does not count as paid media.
```

### Variations

- **Funnel by channel:** Carry the lead channel through MQL, SQL and sale in each client's CRM.
- **First and last touch:** Store the source of the first and last conversion in separate columns and state which one the report uses.
- **Site channels:** The same logic over GA4 sessionSource and sessionMedium, without crossing it with the lead channel.
