Engineering & AI
Standardizing website measurement with GTM, GA4 and ad pixels: a dev log from hubcom.tech
Dev log of rebuilding GTM, GA4, Meta and TikTok Pixel: one generate_lead event, a UTM convention, a source code carried to chat, consent denied by default.
Summary
- The website only pushes events to the dataLayer; GTM decides whether they go to GA4, Meta or TikTok.
- One generate_lead event covers every contact channel, recognized by the link's address.
- A public UTM convention, plus a short source code that follows the visitor into WhatsApp, Zalo and email.
- Consent is denied by default; Meta and TikTok Pixel load only after the visitor accepts.

You post on several channels and are about to run ads, yet GA4 cannot tell you which channel brings in people who get in touch. This post records how we rebuilt measurement for hubcom.tech on 19–20 November 2026, so we can reuse it as the template for other brands' websites.
A HubCom dev log. The site is a statically exported Next.js app; the approach works for any website running Google Tag Manager.
Situation
- The site already had GTM, GA4 and Meta Pixel. The container was last edited about eight months before our audit.
- Visitors get in touch through Zalo, WhatsApp, phone, email and chat, not through a form.
- Meta and TikTok ads are coming, so the platforms need one correctly counted conversion to optimize for.
- Goal: know which channel produces leads, and which post each lead came from.
1. Meta reports almost as many "Leads" as page views
Problem
Over four weeks, Meta recorded 412 Lead events against 616 PageViews. No service business converts like that.
Evaluate
- Fix the old tags one by one: fast, but you never learn which other tags still miscount.
- Audit the whole container before adding anything: costs an extra half day, but tells you how far the old data can be trusted.
Solution
- List every tag, trigger and the events they send. The WhatsApp and Email click tags fired Lead on almost every link click; a
form_submittag ran on a site with no form. - The pixel also received events from localhost whenever a developer ran the site locally.
- Delete the old click tags and
form_submit. Note the date of the change: data before it is not comparable. - Verify the domain in Meta and let the pixel accept events from the real domain only.
- Check: run the site on localhost and click a contact link; Events Manager receives nothing.
2. Every new contact button needs another tag
Problem
Click triggers match a CSS selector or the button text. Change the layout or add a button and the count silently drops.
Evaluate
- Click triggers in GTM: no code changes, but tied tightly to the interface.
- The website pushes its own events to the
dataLayer: one code change, after which GTM only needs the event name. Adding an ad platform later never touches the code.
Solution
- One listener for the whole site recognizes contact links by address:
zalo.me,wa.me,tel:,mailto:. New buttons are counted automatically. - Push
generate_lead, GA4's recommended lead event, withmethod(zalo, whatsapp, phone, email, chat) andpage. - A chat counts as a lead when the visitor sends the first message in a page visit, not when the chat window opens.
- Add engagement events:
view_service,view_project, andread_articlewhen the visitor scrolls 60% of a post, once per post. - In GTM: a Data Layer variable per parameter, a Custom Event trigger, and one tag per destination: GA4
generate_lead, MetaLead, TikTokContact. - In GA4: mark
generate_leadas a key event and create a custom dimension per parameter. Without dimensions, reports cannot filter by channel or service. - Check: click each channel once; the
dataLayerholds exactly onegenerate_leadwith the rightmethod. An ordinary link adds none.
3. Visitors from Zalo and Messenger show up as "Direct"
Problem
Zalo, Messenger and LinkedIn open links in their in-app browsers and often send no referrer. GA4 records those visitors as direct traffic.
Evaluate
- Let GA4 work out the source: no effort, but most social traffic is lost.
- Tag links with UTM by a shared convention: everyone who posts has to follow it, so it must be short and easy to find.
Solution
- Write the convention on one page and publish it at hubcom.tech/utm.md, for people and for automated posting tools alike.
- Lowercase, no accents:
utm_sourceis the platform;utm_mediumis the channel type (social,paid_social,cpc,email,referral,maps);utm_campaignfollowsYYYYMM-topic. - A fixed link per profile (bio, about section, Google Maps) uses
utm_campaign=always-on. - Never put UTM on internal links. It starts a new session and erases the visitor's real source.
- GTM loads after the first interaction so the page renders fast. Visits carrying UTM or a click ID (
gclid,fbclid,ttclid) load it immediately; otherwise a visitor who clicks through before GA4 records the first page view loses the UTM. - Check: open a UTM link and immediately click to another page; GA4 Realtime still shows the right source and medium.
4. A lead messages on Zalo, and nobody knows which post they came from
Problem
Once a visitor taps Zalo or calls, the conversation leaves the website. GA4 knows there was a lead, but sales cannot match it to the person messaging.
Evaluate
- Ask "how did you hear about us?": easy to forget, and visitors often misremember.
- Send the source along with the message: requires storing the source in the visitor's browser, without sending data to third parties.
Solution
- Store the first and the most recent source (UTM, click ID, landing page) in the visitor's browser for 90 days.
- Generate a short source code,
HC-<channel>-<4 characters>, for exampleHC-FB-7Q2K. It reaches HubCom only when the visitor sends it. - Add the code to prefilled content: the WhatsApp message, the email subject, the first chat message.
- Zalo cannot prefill a message, so the contact page shows "Your code" next to the Zalo button and phone number, with a copy button.
- If the browser blocks storage, contact buttons still work, just without a code.
- Check: arrive from a Facebook link with UTM, come back the next day by typing the domain, then tap WhatsApp; the prefilled message carries a code starting with
HC-FB-.
5. Ad pixels run before the visitor consents
Problem
Meta and TikTok Pixel set cookies as soon as the page loads. Vietnam's Decree 13/2023 on personal data protection does not treat silence as consent.
Evaluate
- A banner with only an "Accept" button: the visitor has no real choice.
- Measure nothing when the visitor declines: you lose even aggregate data.
- Google Consent Mode v2: GA4 still sends cookieless signals when consent is denied; ad pixels load only after consent.
Solution
- Set the default in
<head>, before GTM:ad_storage,analytics_storage,ad_user_dataandad_personalizationalldenied. - Two equal buttons, "Accept" and "Decline". The choice is kept for 180 days and can be changed from "Cookie settings" in the footer.
- When the visitor chooses: call
gtag('consent', 'update', …), then push aconsent_updateevent. - Meta and TikTok tags require
ad_storageand fire on both Initialization andconsent_update, so the pixel loads on the current page. - Set the pixel tags to "Once per event". With "Once per page", GTM counts the blocked Initialization attempt, and the pixel never fires after the visitor clicks "Accept".
- Check: after declining, no request goes to Facebook or TikTok; after accepting, requests go out at once, without a reload.
6. No way to confirm a new container version before publishing
Problem
Tag Assistant opens a separate window, which a browser driven by an AI agent usually cannot operate.
Evaluate
- Publish and watch the live site: if something is wrong, the data is already dirty.
- Load the draft in an ordinary tab with preview parameters: no Tag Assistant needed; read the requests to GA4 and the pixels directly.
Solution
- Create a version (Submit → Create Version) without publishing it.
- Load
gtm.jswith the preview environment'sgtm_auth,gtm_previewandgtm_cookies_win=xinto a tab showing the website. - Read the outgoing requests: GA4 beacon bodies and requests to
facebook.com/tr. - Delete the
__TAG_ASSISTANTcookie when done; while it exists, GTM stays in debug mode. - Check: each scenario (each channel, decline, accept) sends exactly the expected requests before you publish.
Preparing the AI agent
- The site's contact channels and the link address of each.
- The IDs of the GTM container, GA4 stream, Meta Pixel and TikTok Pixel, with edit access to each.
- An event table: name, parameters, when it fires, how many times.
- The UTM convention and the fixed link for each profile.
- Consent rules: denied by default, and which tag needs which consent type.
- What a person does: sign-ins, verification codes sent by email, and the Publish button.
Out of scope
A CRM that tracks leads through to contracts, sending offline conversions back to GA4, Meta and TikTok, server-side tagging and a Looker Studio dashboard. These are the next stages of our measurement plan. The list of profiles to create on social networks and directories is in a separate post.
Terms in this article (8)
- Google Tag Manager
- A tool for managing measurement snippets (tags) on a website, so tags can be added or changed without code changes.
- GA4
- Google Analytics 4, Google's analytics tool that records page views and events on a website.
- dataLayer
- A JavaScript array on the page where the website pushes events for Google Tag Manager to read.
- Key event
- An event marked as a main conversion in GA4, previously called a conversion.
- Meta Pixel, TikTok Pixel
- Ad platform snippets that send website events to Meta or TikTok to measure and optimize ads.
- UTM
- Parameters added to a link so analytics tools know the visitor's source, channel and campaign.
- Click ID
- An ID ad platforms add to links (gclid, fbclid, ttclid) to tie an ad click to a conversion.
- Consent Mode v2
- Google's mechanism for tags to follow the visitor's cookie choice; v2 adds the ad_user_data and ad_personalization consent types.
Frequently asked questions
Why not use GTM click triggers for contact buttons?
Click triggers depend on the interface, so they undercount when buttons change. The website recognizes contact links by address and pushes one event, so new buttons are counted automatically.
What does GA4 still record when a visitor declines cookies?
With Consent Mode, GA4 still receives cookieless signals for page views and generate_lead. Meta and TikTok Pixel do not load.
Does the HC-… source code send visitor data to third parties?
No. The code is stored in the visitor's browser and reaches HubCom only when the visitor sends it in a message or email.
Sources
- Set up consent mode on websites, Google for Developers
- Recommended events, Google for Developers
- URL builders: Collect campaign data with custom URLs, Google Analytics Help
- Specifications for Meta Pixel Standard Events, Meta Business Help Center
- Standard Events and Parameters, TikTok Ads Manager
- Decree 13/2023/ND-CP on personal data protection, Government of Vietnam
- UTM convention for links to hubcom.tech, HubCom