
Dynamic variables of the Meta Ads for UTMs: model and test
Copy two UTM templates to Facebook and Instagram Ads. Here's how to use {{campaign.id}}, {{ad.id}} and {{placement}} and test the link in the Meta Ads.
You have set up UTMs in your ads from the Meta Ads. Great. But do you know exactly what each dynamic variable returns? You know the difference between `{{campaign.id}}` and `{{campaign.name}}`? Do you know why `{{ad.name}}` can you fool yourself if you rename the ad after posting?
Most tutorials teach you how to paste a ready-made URL and move on. Here I will explain the most useful dynamic variables of the Meta Ads, show two URL templates and indicate how to check if the parameters arrive correctly at their base.
What are dynamic variables of the Meta Ads
Dynamic variables are placeholders in the format `{{nome.da.variavel}}` that you enter in the destination URL of your ads. When someone clicks on the ad, Meta replaces those placeholders with real values — the campaign ID, the set name, the positioning where the ad appeared, etc.
This is the first step of first-party data collection: receive in the URL the source of the click. To have your own data intelligence, you still need to capture and store these parameters on your base.
The UTMs show the origin of the visit, but do not guarantee, by themselves, that the sale is correctly allocated. The first-party data collection depends on capturing and storing this data; the conversion tracking happens when you inform the events and identifiers to the traffic platform.
Useful dynamic variables of the Meta Ads
The Meta Ads offers dynamic campaign parameters, set, advertisement, origin and positioning. The examples below show how to combine readable names with stable IDs. Check in the Ads Manager the parameters available for your configuration.
ID Variables (Immutable)
These return the unique numeric identifier of each level of the campaign structure. The ID It never changes — even if you rename the campaign, the adset or the ad.
`{{campaign.id}}`
Returns the numerical ID of the campaign. Example: `23845917166800246`.
This number is the same as in the Ads Manager URL when you open the campaign. It’s the most reliable variable for assignment because it doesn’t depend on how you named things.
When to use: Always. It's the basis of the assignment. Cross this ID with a API of Meta or with its database to know exactly which campaign generated the conversion.
`{{adset.id}}`
Returns the numeric ID of the ad set. Example: `23845917166800312`.
Each set has a unique ID. Useful to know which segmentation, budget or schedule generated the click.
When to use: When you need granularity below the campaign — especially if you run multiple sets with different segmentations.
`{{ad.id}}`
Returns the numeric ID of the individual ad. Example: `23845917166800451`.
The most granular level. Every creative, every copy variation, every image + text combination has its own ID.
When to use: When you want to know which specific creative performed best. Essential for A/B testing.
Name variables (beware!)
These return the name you gave the campaign, the whole or the announcement. It sounds more readable, but it has an important trap.
`{{campaign.name}}`
Returns the name of the campaign at the time it was published. Example: `vendas-blackfriday-2026`.
The trap: If you publish the campaign with the name "sales-bf" and then rename to "sales-blackfriday-2026", the dynamic variable Keep returning "bf sales" For those who clicked before the change. What about for new clicks after the change? Behavior is not guaranteed—in many cases, The old name persists until you republish the ad.
When to use: For readability in the dashboard, as long as you set the names before you publish and never change.
`{{adset.name}}`
Same logic as `{{campaign.name}}`, but for the set of ads.
Example: `lookalike-compradores-30d`.
Same trap: Rename after publishing does not update the returned value.
`{{ad.name}}`
Same logic, but for individual announcement.
Example: `carrossel-depoimentos-v2`.
Same trap. And here it’s even more dangerous because ads are renamed more often than campaigns.
Positioning variables
These are the most valuable for media optimization, they tell you where the ad was shown when the click happened.
`{{placement}}`
Returns the exact positioning. It’s not generic — it’s specific. Possible values:
- `Facebook_Desktop_Feed`
- `Facebook_Mobile_Feed`
- `Facebook_Marketplace`
- `Facebook_Right_Column`
- `Facebook_Stories`
- `Facebook_Instream_Video`
- `Facebook_Instant_Articles`
- `Instagram_Feed`
- `Instagram_Stories`
- `Instagram_Reels`
- `Instagram_Explore`
- `Instagram_Explore_Grid_Home`
- `Instagram_Profile_Feed`
- `Audience_Network`
- `Messenger_Inbox`
- `Others`
When to use: Always. This variable lets you know if the leads that convert come from the Feed of the Instagram, from Reels, Marketplace, or any other positioning. Without it, you go blind about where the money is being spent well.
`{{site_source_name}}`
Returns the platform (not the positioning) where the click came from. Possible values:
- `fb` — Facebook
- `ig` — Instagram
- `msg` — Messenger
- `an` — Audience Network
When to use: When you want to separate Facebook from Instagram of Messenger at the macro level, without entering the positioning detail. Ideal pro `utm_source`.
IDs vs Names: Which to Use?
The short answer: Use both together.
IDs are immutable and accurate — perfect for database assignment and cross-checking with a API of the Meta. Names are readable — perfect for viewing on dashboards and reports.
The most common mistake is to use only names. When you rename a campaign (and everyone renames it), you lose traceability.
The second most common mistake is to use only IDs. When you look at the dashboard and see `23845917166800246`, need to open the Manager to know what it is.
The solution is: IDs in the attribution parameters (which go to the bank), names in the readability parameters (which appear in the dashboard).
The structure I use
Compact model of URL parameters for an ad of the Meta Ads:
utm_source={{site_source_name}}&utm_medium=paid_{{placement}}&utm_campaign={{campaign.name}}&utm_content={{adset.name}}&utm_term={{ad.name}}|{{ad.id}}&utm_id={{campaign.id}}
Paste the sequence in the URL parameters field, without adding a second question if the Manager already includes it. Test the final link before publishing.
Let's unravel:
- `utm_source` = `{{site_source_name}}` → Separate Facebook from Instagram of Messenger. In Google Analytics, you see "fb", "ig", "msg" as distinct sources.
- `utm_medium` = prefix `paid_` +
{{placement}}→ Static + variable. The prefix 'paid_' differentiates paid traffic from organic. Some use "cpc" or "social_ads", but I prefer "paid" because it is universal (worth to Google Ads, Meta, TikTok, everything). The variable {{placement}} it brings us where the ad appeared. For positioning optimization. - `utm_campaign` = `{{campaign.name}}` → Readable in the dashboard. You see "campaign-sales-blackfriday-2026" instead of a number.
- `utm_content` = `{{adset.name}}` → Identifies the set (segmentation). Useful to know which audience is converting best.
- `utm_term` =
{{ad.name}}|{{ad.id}}→ The ad.name variable identifies the name of the creative. Which image, video or copy generated the click. Ad.id is the most important parameter of all. It is an immutable umID of the ad. For more precise attribution of all. - `utm_id` = `{{campaign.id}}` → Immutable campaign ID. To cross with API and database.
“In this model, ad.id identifies the advertisement in a stable manner. I also included campaign.id in utm_id to facilitate crossover with the campaign in Analytics and on the basis itself. Other IDs can be added when they make sense for analysis.
If you want even more complete and unraveled as well as in some projects:
utm_source={{site_source_name}}&utm_medium=paid&utm_campaign={{campaign.name}}&utm_content={{adset.name}}&utm_term={{ad.name}}&utm_id={{campaign.id}}&ad_id={{ad.id}}&adset_id={{adset.id}}&placement={{placement}}
This model separates the IDs and positioning into their own parameters. Confirm that the tool that receives the URL also stores the custom parameters.
Let's unravel:
- `utm_source` = `{{site_source_name}}` → Separate Facebook from Instagram of Messenger. In Google Analytics, you see "fb", "ig", "msg" as distinct sources.
- `utm_medium` = `paid` → Static. Differentiate paid traffic from organic. Some use "cpc" or "social_ads", but I prefer "paid" because it is universal (it's worth to Google Ads, Meta, TikTok, everything).
- `utm_campaign` = `{{campaign.name}}` → Readable in the dashboard. You see "sales-blackfriday-2026" instead of a number.
- `utm_content` = `{{adset.name}}` → Identifies the set (segmentation). Useful to know which audience is converting best.
- `utm_term` = `{{ad.name}}` → Identifies the creative. Which image, video or copy generated the click.
- `utm_id` = `{{campaign.id}}` → Immutable campaign ID. To cross with API and database.
- `ad_id` = `{{ad.id}}` → Immutable ID of the advertisement. For precise assignment.
- `adset_id` = `{{adset.id}}` → Immutable ID of the set. For segmentation analysis.
- `placement` = `{{placement}}` → Where the ad appeared. For positioning optimization.
Why "paid" and not "cpc" in the utm_medium?
A lot of people use `cpc` as a medium because it is what the Google Ads uses by default. But no Meta Ads, not every click is CPC — you may be optimizing for CPM, for ThruPlay, for conversions.
Use `paid` how medium gives you a clean view: all traffic that came from investment in media, regardless of the billing model. In the dashboard, you filter `medium=paid` and sees all paid traffic from all platforms in one place.
If you need to differentiate the billing model, put this in the campaign name or set — not in the utm_medium.
The nomenclature convention matters
Before setting up the dynamic variables, set a Nomenclature Convention for campaigns, sets and ads. This is more important than it seems, because:
- `{{campaign.name}}` returns exactly What you typed. If the name has space, accent, or emoji, that’s what goes in the URL.
- Spaces have seen `%20` in the URL. Accents can break down into older systems. Emojis... I won't even comment.
- If each team person names it in a different way, their UTM data has seen chaos impossible to aggregate.
The convention I recommend:
Never use the vertical bar in nomenclatures "|"
- Use hyfens or underlines Instead of spaces: `vendas-blackfriday` or `vendas_blackfriday` instead of `vendas blackfriday`
- Use tiny Always: `ad_plataformify` instead of `AD PLATAFORMIFY`
- Include objective + temperature of the public + date in the name of the campaign: `vendas-quente-compradores-mar2026`
- Include segmentation in the name of the set: `interesse-marketing-digital-25-45`
- Include format + variation + hook in the name of the ad: `ad_v1_plataformify` indicates that it is static in its variation 1, `adv_plataformify` indicates that it is video, `adv_porque_vc_nao_deve_usar_plataformify` indicates that it is video and that the hook is the phrase "Because you should not use plataformify".
Where to set up in Ads Manager
At the level of announcement (Not from the campaign, not from the whole):
- Open the ad in the Ads Manager
- Scroll to the section of First-party data collection
- Open the field URL Parameters
- Paste the complete string with the dynamic variables
- Publish
The Meta will replace each `{{variavel}}` for the real value at the time of click.
Tip: You can configure this at the campaign level using the "ULUr Parameters" option in the campaign settings. Thus, all ads inherit the same parameters without having to copy in each one.
Common mistakes I see
1. Use only names and rename later
I’ve talked about it, but it’s worth reinforcing: if you use it `{{campaign.name}}` and then rename the campaign, the old data get the old name and the new ones with the new name (or not even that). Result: in your dashboard appears the same campaign with two different names.
2. Not including IDs
Campaign, set, and ad IDs allow you to relate the click to the corresponding data in the Meta Ads. For analytics by ad, keep {{ad.id}} or another stable identifier in the URL and save this value to its base. Without this connection, comparing cost and conversions per ad is less reliable.
3. Forget the `{{placement}}`
Without knowing the positioning, you can’t optimize where your ads appear. It may be spending 80% of the budget in the Audience Network (which usually has low quality) and not even know.
4. Duplicate parameters between platforms
If you use `utm_source=facebook` pro Meta Ads and `utm_source=facebook` for organic traffic from the Facebook page, you won’t be able to separate the two in the dashboard. Use `{{site_source_name}}` as source pro paid and set a different convention pro organic.
5. Do not test before climbing
Before placing heavy budget, click on the ad and make sure the destination URL is coming with the correct parameters. Open Developer Tools > Network > see the full URL. If any variable is coming as `{{campaign.name}}` instead of the real value, something is wrong in the configuration.
How does this connect with first-party data collection and conversion tracking
The dynamic variables are the starting point of the first-party data collection. They put the data in the URL. But the URL alone does nothing — you need to:
- Capture these parameters when the visitor arrives on your website (via JavaScript, GTM, or system like Rastracking)
- Store in database (first-party data collection — the data stays with you)
- Send the conversion events back to Meta via CAPI (conversion tracking — informs the platform for optimization)
If you stop at the Analytics view, you miss the chance to use the source of the visit on your own base. The first-party data collection stores the data; the conversion tracking informs the relevant signals to the traffic platform, respecting the rules of integration.
Want to see ad.id turn sale? Know the RastrackDash Info
With the ad.id in the URL, the next step is to save each click and cross with the sale. The RastrackDash Info does this in a facility of its own: a first-party script collects the origin of each visit, and the dashboard joins campaigns, events, leads, checkouts and each person's journey. More details in RastrackDash Info: which campaign brought the sale that went through the site?.
RastrackDash Info
From ad.id in the URL to the ad that opened and closed the sale
You already place the ad ID in UTM. A script of your website reads these parameters with each visit and saves each person’s journey. When the sale arrives, you see the first and last ad that passed through it.
- Day 1Clicked on ad A, didn't buyutm_content=ad.id A
- Day 4Clicked on ad Butm_content=ad.id B
- Day 6Bought by the bio linkutm_source=bio
Credit: the manager rule. The account account manager for sale according to the account assignment configuration, with the window and the model of it.
Illustration with fictional data
- First-party Script: UTMs, first and last tap, and platform click IDs
- Journey by person: first and last contact, identities and timeline
- Campaigns in the view of Meta or in vision RastrackDash, by first or last announcement
- Journeys, Campaigns, Creatives, Events, Leads and Sales in a single panel
- Data in a structure of yours, outside the manager
- Direct-to-the-point training to put the solution into use
Pre-sale group in the WhatsApp
Enter before launch
In the pre-sale group I send special offers before the official launch, with discounts for those who arrive before.
- 1Tap the button below
- 2Enter the group by WhatsApp
- 3Get the offers before the official launch
Open the WhatsApp in new tab
Conclusion
Dynamic variables help to identify the source of clicks. Combine readable names, stable IDs, and a real URL test. Then check if the data has reached its base and the reports used in the analysis.
- Always include IDs for precise attribution
- Use names for readability, but define before publishing
- Include `{{placement}}` to know where the money is being spent
- Include `{{site_source_name}}` to separate platforms
- Standardize nomenclature before you start
- Connect first-party data collection and conversion tracking to close the full cycle
If you want to understand how to close this cycle — capture those parameters, store in a bank, and send conversions back — read the Guide of first-party data collection WhatsApp with N8N that I posted here on the blog.