Marketing agencies · Attribution

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.

UsageCommon
EffortMedium
ForAgencies that report leads and cost per lead by channel for clients with different RD Station setups, CRMs and forms.
Source

RD events, CRM Source field and GA4

Rule

Decoding and per-client cascade

Outcome

One channel per lead and cost per lead by channel

Activation

Report, alert and AI agent

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.

Business questions it answers

Ask your agent these questions once the case is live.

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

Where to activate

Client report

Leads and cost per lead by channel, with the no-source share always visible.

Tracking alert

Warns when the no-source share jumps from one week to the next, naming the form that changed.

AI agent via MCP

Explains why Meta says 40 and the CRM says 27, without picking one number.

Ready to build?

Decoding is the same for everyone. The work is writing each client's cascade and exceptions and keeping them as data. The detailed view has the business rules, the pitfalls and the acceptance test. Or send everything straight to your agent with the Nekt MCP.

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.

How it is usually done, and the rule

Each row is a mistake that already happened in practice.

The common wayThe rule
01
Reading only utm_source and concluding there is no tracking.
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.

02
Counting every CONVERSION event_type.
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.

03
One cascade in code for the whole portfolio.
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.

04
Only a channel column.
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.

05
Applying one client's decision to another.
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.

06
Dumping no source into direct or other.
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.

07
Leaving Lead Ads as no source.
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.

08
Adding Google and Meta conversions and calling it leads.
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.

09
Spend divided by every lead in the CRM.
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.

10
Fixing the channel in the report spreadsheet.
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.

Typical channel cascade

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

Team manual overrideChannel enteredoverride table
gclid, gbraid, wbraid, gad_source or google with cpc mediumGoogle Ads
fbclid, or utm_source fb, ig, meta with a paid mediumMeta Ads
li_fat_id or utm_source linkedinLinkedIn Ads
Identifier ending in -<9 or more digits>Meta native form
WhatsApp chatbot with no UTM and no mediumWhatsApp with no sourcenot paid
Social medium, no paid clickOrganic social
email medium or RD Station sourceEmail
organic medium or search engineOrganic search
Empty, direct or unrecognized formatNo sourceown row

Definitions

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 that already happened

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.

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.

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.

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.

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.

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.

Use the campaign ID and the account to client registry.

Acceptance test

The case is done when every item passes.

Agent package

Paste into Claude, ChatGPT or any client with the Nekt MCP connected.

Full Markdown
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.