What does a typical "track the contact form" setup actually send to Google Analytics? On a lot of sites, more than anyone intended: form field values pushed into the data layer, a thank-you URL with ?name= in it, a site search parameter containing someone's surname.
On most websites that is sloppy. On a law firm's website it is a real problem. People describe divorces, arrests, injuries and immigration status in enquiry forms. That information should go to the firm's case management system and nowhere else.
This post walks through a GA4 setup that measures enquiries by practice area and office without letting personal data leak into analytics. The examples use gtag.js and a plain data layer, and translate directly to Google Tag Manager.
The rules you are designing around
Google's policy is blunt. The Analytics help page on avoiding PII says no data should be passed to Google that Google could use or recognise as personally identifiable information. It names email addresses and personal mobile numbers as examples, and states that both the URL path and its parameters must be free of PII. It also warns that visitors sometimes type PII into search boxes and form fields, and that you should remove it from user-entered information before it is sent.
For a law firm, add a second layer. Even data that is not strictly identifying on its own, such as the free-text description of a matter, can be sensitive when combined with other signals. The safest design principle is an allow-list: decide in advance the handful of values analytics is allowed to receive, and send nothing else.
The values we want are:
-
practice_area: for examplefamily,conveyancing,employment -
office: the office the enquiry relates to -
form_id: which form was used -
lead_source: a fixed label such aswebsite_formorphone_link
None of these describe a person. All of them are enough to answer the questions a firm actually asks: which practice areas generate enquiries, from which pages and which channels.
Step 1: Put the metadata on the form, not in the fields
Instead of reading values out of form inputs, put the analytics metadata on the form element itself. The developer controls these values; the visitor never types them.
<form id="enquiry-family" action="/api/enquiry" method="post"
data-practice-area="family"
data-office="leeds">
<!-- name, contact details, matter description: never read by analytics -->
<button type="submit">Send enquiry</button>
</form>
If one form serves several practice areas through a dropdown, map the selected option to a fixed list of slugs in code, and fall back to other for anything unexpected. Never pass the raw option text.
Step 2: Fire the event only after the server accepts the enquiry
Click-based form tracking counts attempts, including failed validation and spam. Fire the event after the server responds successfully instead.
const ALLOWED_AREAS = new Set(['family', 'conveyancing', 'employment', 'immigration', 'probate', 'other']);
document.querySelectorAll('form[data-practice-area]').forEach((form) => {
form.addEventListener('submit', async (event) => {
event.preventDefault();
const response = await fetch(form.action, { method: 'POST', body: new FormData(form) });
if (!response.ok) return; // show your own error state here
const area = ALLOWED_AREAS.has(form.dataset.practiceArea) ? form.dataset.practiceArea : 'other';
gtag('event', 'generate_lead', {
lead_source: 'website_form',
practice_area: area,
office: form.dataset.office || 'unknown',
form_id: form.id
});
window.location.assign('/enquiry-received/'); // a clean URL with no query string
});
});
generate_lead is one of Google's recommended events, described as measuring when a lead has been generated, for example through a form. Its documented parameters are currency, value and lead_source. Leave value out unless the firm has an agreed, meaningful figure; a made-up value distorts reporting. The practice_area, office and form_id parameters are custom, so register them as event-scoped custom dimensions in GA4 Admin before you expect to see them in reports.
If you use Google Tag Manager, push the same object to window.dataLayer with an event key instead, and map the data layer variables to a GA4 event tag.
Step 3: Clean every URL before it is sent
Thank-you pages, CRM redirects and booking widgets love to append query strings. Some of them contain names or email addresses. Two layers of defence work better than one.
Layer one: an allow-list in your own code. Override page_location so only known parameters survive.
const ALLOWED_PARAMS = new Set([
'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'gclid'
]);
function cleanUrl(href) {
const url = new URL(href);
for (const key of [...url.searchParams.keys()]) {
if (!ALLOWED_PARAMS.has(key)) url.searchParams.delete(key);
}
return url.toString();
}
gtag('config', 'G-XXXXXXXXXX', {
page_location: cleanUrl(window.location.href),
page_referrer: document.referrer ? cleanUrl(document.referrer) : ''
});
In Tag Manager, the same function can live in a Custom JavaScript variable that you set as the page_location field on your Google tag.
Layer two: GA4 data redaction. GA4 has a built-in data redaction feature for web data streams. It runs client-side and can remove email addresses and the query parameters you list before events are collected. Query-parameter redaction applies to page_location, page_referrer, page_path, link_url, video_url and form_destination. Email redaction is on by default for new properties; older properties need it switching on under Admin, Data streams, your web stream, then Redact data in the Events section.
Know its limits. Google's documentation says redaction does not evaluate HTTP header values and will not stop PII arriving through the Measurement Protocol or Data Import. That is why the allow-list in your own code still matters.
Add site search parameters to the redaction list too. People search law firm websites for their own names, the other party's name and case references more often than you might expect.
Step 4: Track phone clicks without logging numbers
Many legal enquiries start with a call. A click on a tel: link is a useful signal, and the number belongs to the firm, but there is no need to send it. Send the office and the placement instead.
document.addEventListener('click', (event) => {
const link = event.target.closest('a[href^="tel:"]');
if (!link) return;
gtag('event', 'phone_click', {
lead_source: 'phone_link',
office: link.dataset.office || 'unknown',
placement: link.dataset.placement || 'body'
});
});
A click is not a call, and a call is not a qualified enquiry. Treat phone_click as an intent signal and label it that way in reports.
Step 5: Turn events into qualified-enquiry reporting
Mark generate_lead as a key event in GA4. Then build an exploration with practice_area and office as dimensions alongside landing page and session source or medium. That answers the questions partners ask: which pages and channels bring family enquiries to the Leeds office, and how that changes over time.
Qualification itself happens in the firm, not in GA4. The intake team decides whether an enquiry fits the firm's work. Resist the temptation to send that judgement back to analytics at the level of an individual. Compare at aggregate level instead: weekly or monthly counts of qualified enquiries by practice area from the case management system, set against GA4's enquiries by the same practice area. The ratio between them is your quality signal, and no personal data crosses between systems.
Edge cases: embedded forms, chat widgets and multi-step flows
Not every enquiry runs through a form you control.
Third-party embedded forms. Many case management and intake tools offer an embeddable form in an iframe. You usually cannot attach listeners inside it. Check whether the vendor emits a postMessage event on successful submission; if it does, listen for it on the parent page, check event.origin against the vendor's domain, and fire generate_lead with your own fixed metadata. If it does not, track the redirect to a clean confirmation page you host instead.
Live chat. Chat widgets often have their own analytics integrations that forward transcripts or visitor names as event parameters. Switch those integrations off and send a single chat_started event with the page's practice area.
Multi-step forms. Track step completion with a step number only. Never send the answer chosen at each step if the options describe the person's circumstances, such as "I have been arrested" or "my partner has left".
Pre-launch checklist
Before shipping, run through this list:
- Open GA4 DebugView and submit a test enquiry. Confirm the event carries only the allow-listed parameters.
- Inspect the outgoing collect request in the browser's network tab. Search the payload for your test name and email; neither should appear.
- Visit the thank-you page with a fake
?email=parameter and confirm it is stripped. - Run a site search for a test surname and check what arrives in GA4.
- Confirm tags respect the choices recorded by your consent banner.
- Document the allow-list so the next developer does not quietly widen it.
Why this matters beyond compliance
A clean setup is also a more useful one. Reports built on a short list of agreed dimensions are easier to read, harder to misinterpret and easier to keep consistent when the site changes. If you want the marketing context for these numbers, the measurement section of our law firm local search guide explains why qualified enquiries matter more than raw traffic for legal practices.
Prox Digital Agency builds and measures websites for service businesses; this pattern is one we would recommend to any site that handles sensitive enquiries.
This post was drafted with AI assistance.
Top comments (0)