Conversions, from the code to the sales
Chapter 1
How it works
A dynamic link tells you someone clicked. Conversions tell you what they did next on your site, such as buying, booking or signing up, and tie it back to the link, QR code or campaign that brought them.
- 1 · clickA customer clicks a link or scans a QR codeA dynamic link, or a button on a link page
- 2 · redirectThe click’s code is added to the URL
bansuan.coffee/menu?utm_source=qr&mt_cid=Xk2…A new random code for every click, naming no one - 3 · pixelThe code on your site keeps itA first-party
_mt_cidcookie for 28 days, once the visitor consents - 4 · eventYour site sends an event when they buy
mt('track', 'Purchase', { value: 590 }) - 5 · countEvents that match a rule count as conversionsOn the summary, and sent on to Facebook or TikTok if you like
Pixel
One piece of code per website, with a public id starting px_. It goes in your HTML; it isn’t a secret.
Event
What your site sends when a customer does something: views a page, adds to cart, buys. Every event that passes the checks is kept for 90 days.
Conversion
A rule you set for which events count as a result, like “every Purchase” or “a PageView of /thank-you”. One event can match several conversions.
Two pages in the app
A project’s Conversions menu has the summary, to see results and manage conversions, and Install on your site, to set up pixels.
Who can do what
Owners and admins create, change and delete pixels, server keys and ad platform destinations. Every member can create, change and delete conversions.
When a link gets mt_cid
Whenever its destination is on a domain of a pixel that’s on, with nothing to set per link. Clicks by bots or prefetching, and links that open an app (deep links), don’t get one.
Chapter 2
Make a pixel
The first time you open Conversions, it asks you to install the code first. Install on your site takes you to the pixel setup.
- 1
Open Conversions and click Install on your site.
- 2
Click New pixel and name it, after the website for example (up to 100 characters).
- 3
Click Create pixel. Your project’s domain is added as its first domain, and it shows “Waiting for its first event” until your site sends one.
- 4
The ⋯ menu by the pixel’s name renames it, switches it off (its events are dropped as “Pixel switched off”) or deletes it, with all of its conversions and counts.
Chapter 3
Tell it which sites may send events
Domains do two things: only sites on the list can send events, and links to them get mt_cid added. With no domain, no events are kept yet.
- 1
Type a domain and press Enter, or paste a whole URL:
https://, the path, the port andwww.are taken off. - 2
example.comincludeswww.example.com.*.example.comis that domain and every subdomain. - 3
Click Save domains. Up to 20 domains per pixel.
Chapter 4
Put the code on every page
One snippet per pixel, in the head of every page, or through Google Tag Manager as Custom HTML. Below is an example; your pixel’s own code is on the setup page.
<!-- MetricTree -->
<script>
!(function (w, d, u) {
if (w.mt) return;
var m = (w.mt = function () {
m.q.push(arguments);
});
m.q = [];
var s = d.createElement('script');
s.async = true;
s.src = u;
d.head.appendChild(s);
})(window, document, 'https://metrictree.app/js/mt.js');
mt('init', 'px_k3m9a2x7q1wz');
</script>Doesn’t slow pages down
mt.js loads async, and mt(...) calls made before it loads wait in a queue.
Counts page views for you
Sends PageView on every page, single-page apps (React, Vue, Next) included. Turn it off with autoPageView: false.
Never breaks your site
Every command is wrapped in try/catch: if something goes wrong on our side, your site carries on.
Debug
Add ?mt_debug=1 to the URL, or call mt('set', 'debug', true), to see logs in the browser console.
Pages whose path names someone
Such as /orders/8812: call mt('set', 'path', '/orders/:id') and that path is kept instead. Parts of a path that read as an email address or a number of 9 digits or more become :redacted on their own.
Chapter 5
Send an event when a customer does what counts
Call it after the code in chapter 4: on the thank-you page after a purchase, say, or when a form is sent. Standard events go with track, your own names with trackCustom.
A purchase with its value (order_id keeps a reload from counting twice)
mt('track', 'Purchase', { value: 590, currency: 'THB', order_id: 'A1024' })A contact form sent
mt('track', 'Lead')An event of your own
mt('trackCustom', 'BookTable', { plan: 'pro' })All 12 standard events, and when to send each
Named exactly as Meta Pixel’s. Pick the one that matches what the customer did, and add the parameters that make the number mean something.
Purchase
Purchase
When payment goes through. Send it from the confirmation page, with the value and the order number, every time.
- Goes on to
- Facebook (Meta)TikTok
- Parameters in the example
- valuecurrencyorder_idcontent_idscontent_type
Filled ones go on to your ad platforms. The rest stay in MetricTree, ready for rules.
mt('track', 'Purchase', { value: 160, currency: 'THB', order_id: 'A1024', content_ids: ['iced-latte', 'croissant'], content_type: 'product' })Your own event names
Start with a letter, use only A–Z, 0–9 and _, up to 40 characters, like BookTable. Not a standard name in other letter case, like purchase.
Parameters it knows
value and currency (the amount), order_id (so a reload doesn’t count twice) and content_ids (the products). Name any others yourself, up to 20 in all, and use them in conversion rules.
What goes on to Facebook and TikTok
value, currency, order_id, content_ids and content_type reach your ad platforms. search_string, num_items, predicted_ltv and any others stay in MetricTree, ready for conversion rules, and aren’t sent on.
Meta’s other events
Like AddToWishlist, Schedule or Donate: send them with trackCustom under the same name, as in mt('trackCustom', 'Schedule'). They go on to the platform with that name.
Lists of products
Use content_ids for product ids, up to 20. contents, with a quantity for each, isn’t supported yet; send the total as num_items instead.
order_id and content_ids are kept as sent, long numbers included, so never use a phone or ID card number as an order or product id, and don’t send anything that identifies a person in the first place.Chapter 6
Check that events arrive
Turn on Test events on the setup page for 30 minutes at a time. Meanwhile every event shows as it arrives, dropped ones with the reason, and localhost can send.
| Reason | What to do |
|---|---|
| Malformed | What was sent isn’t what the SDK sends. Use the latest code from the setup page. |
| Invalid event name | Start with a letter, use A–Z, 0–9 and _, up to 40 characters, and not a standard name in other letter case. |
| Domain not allowed | Add the domain in chapter 3 (localhost works only while Test events is on). |
| Bot | Crawlers and automated browsers aren’t counted. Nothing to do. |
| Too many | Check your code doesn’t call track in a loop. |
| Pixel switched off | Turn it back on from the pixel’s ⋯ menu. |
| Project locked | Pay the plan’s outstanding bill on the billing page. |
| Duplicate | That order_id was counted already. Duplicates are caught for you, as they should be. |
| Monthly quota reached | Upgrade the plan, or wait for next month. |
Matches n conversions
How many conversions’ rules this event matches.
From a link
The event carries an mt_cid, so it counts for that link.
Chapter 7
Decide what counts as a result
Back on Conversions, click New conversion (there once you have a pixel).
- 1
Pixel: chosen when it’s created only; it can’t change later.
- 2
Name: what your team sees on the card, like “Book a table”, up to 100 characters.
- 3
Event: names your site sent in the last 28 days come first with their counts, then the standard events, or type your own.
- 4
Rules: up to 5, all must match, on the page’s path, its domain or a parameter, ignoring letter case. “Greater than” and “less than” are for parameters only; “is one of” takes values separated by commas.
- 5
Value: the event’s
value, a fixed amount each time (a lead worth 300 baht, say), or none. - 6
Counting: “every time” suits purchases; “once per click” suits sign-ups and leads.
- 7
Credit links within 1, 7 or 28 days of the click (28 days on Growth and up). Later ones still count as conversions, but not for the link.
Rule changes count from then on
Change the event or the rules and the new rule applies to events from then on; past counts aren’t worked out again.
Chapter 8
Read the summary
Conversions shows each conversion as a card. Click one to see it alone, again to see them all. The numbers below follow the card you chose and the date range.
The big number
Conversions in the range. The arrow compares with the range before, of the same length; the corner shows the value (unless it’s set to none).
From your links
Conversions tied to a click within the window. The rest came from people who visited on their own.
In another currency
Events whose currency isn’t the project’s still count, but aren’t added to the value.
Rate
In the links table, conversions per click of the link in the same range; in the link pages table, per button press. Buttons that point to a dynamic link count in the links table.
Live
Matching events show up within 5 minutes, and the page refreshes its numbers when events arrive, with no reload.
How far back
Starter 30 days, Growth 90 days, Business 365 days. Campaign (UTM) and country breakdowns on Growth and up.
Chapter 9
Send conversions on to Facebook and TikTok
On Growth and up, conversions go from MetricTree’s servers to Facebook’s Conversions API or TikTok’s Events API every minute, so ads optimise on real results without another pixel. Owners and admins set this up.
- 1
On the setup page, click Add destination and choose Facebook (Meta) or TikTok.
- 2
Facebook: the Dataset ID (5–20 digits, in Events Manager > Data sources) and an access token (Events Manager > Settings > Conversions API > Generate access token).
- 3
TikTok: the pixel code (10–30 capital letters and digits, in Ads Manager > Events > Web events) and an access token from Settings > Events API.
- 4
Add a Test event code while testing: events then show on the platform’s test page instead of counting. Remove it when you’re ready.
- 5
Tick to confirm your site has a lawful basis (such as visitors’ consent), says so in its privacy notice, and that you accept the platform’s terms. Who confirmed and when is kept.
- 6
Once saved, the card shows how many were sent, the token’s last 4 characters and the last send. If the platform refuses, its error shows and it’s tried again every minute.
What’s sent
Only events that match a conversion, from when the destination was added. Platforms match them by the ad click id (fbclid, ttclid) and the click’s random code, never an email, phone number or IP. Events with neither aren’t sent.
Token
Kept encrypted and never shown again. When you edit later, leave the token empty to keep it. Up to 5 destinations per pixel.
Chapter 10
Send events from your backend
Straight from your site’s server: past ad blockers, and without Safari deleting the cookie within 7 days. Best for purchases confirmed on the server, after your payment gateway answers.
curl -X POST https://metrictree.app/e/px_k3m9a2x7q1wz/server \
-H "Authorization: Bearer $MT_SERVER_KEY" \
-H "Content-Type: application/json" \
-d '{
"events": [{
"event_id": "<uuid>",
"name": "Purchase",
"click_token": "<mt_cid>",
"params": { "value": 590, "currency": "THB", "order_id": "A1024" }
}]
}'- 1
An owner or admin clicks Create server key (signed in recently) and ticks to confirm the events your backend sends, ad click ids among them, have a lawful basis and identify no one.
- 2
The
mtsk_…key shows once. Keep it on your server or in a secret manager, never in a page or mobile app. - 3
When a customer arrives, keep the
mt_cidfrom the URL (or the_mt_cidcookie) with their order. - 4
When the purchase is confirmed, send
POST /e/:pixelId/serverwith theclick_token. The sameevent_idororder_idas the browser’s counts once. - 5
New key stops the old one at once (our other servers may take it for up to 30 seconds). Delete key stops your backend’s events; the browser’s go on as usual.
Chapter 11
Privacy and PDPA
You control the data on your site. The pixel waits for consent by default: it sends nothing and writes no cookie until your cookie banner calls grant.
// Once the visitor accepts on your cookie banner
mt('consent', 'grant')
// Or, if your site needs no consent, in the snippet in place of its init
mt('init', 'px_k3m9a2x7q1wz', { consent: 'granted' })What isn’t kept
IP addresses, user agents and page query strings. The country is read from the IP then, and the IP is dropped.
What’s stripped for you
Emails, phone numbers and card numbers in parameters and in the page’s path. Test events marks the events it was stripped from.
While waiting for consent
Events wait in the page’s memory (up to 20) and go once you call mt('consent', 'grant'). If the visitor withdraws, call mt('consent', 'revoke') and our cookie is removed.
Sites that need no consent
If your site has another lawful basis, set consent: 'granted' in the code’s init. That choice, and the responsibility for it, are yours.
Chapter 12
What each plan includes
At a limit, the create button becomes a locked one that says what the next plan allows.
| What each plan includes | Starter | Growth | Business |
|---|---|---|---|
| Pixels | 1 | 3 | 10 |
| Conversions | 3 | 20 | 100 |
| Events a month | 10,000 | 1,000,000 | 5,000,000 |
| 28-day link credit | Not included | Included | Included |
| Campaign (UTM) and country breakdowns | Not included | Included | Included |
| Funnels | Not included | Included | Included |
| Send to Facebook and TikTok | Not included | Included | Included |
| Summary history | 30 days | 90 days | 365 days |
Downgrading
Nothing is deleted for you: with more pixels, conversions or 28-day conversions than the new plan allows, remove some first. A conversion already set to 28 days can still be edited on a smaller plan, but can’t be newly set to 28 days.
Past the event quota
Events past the month’s quota are dropped as “Monthly quota reached” until the next billing period. Duplicates don’t count toward it.
Chapter 13