Measuring How Far Readers Get on Long Charge Pages With GA4
Charge pages on criminal defense sites are long. A good one covers what the charge means, possible penalties, the court process, general defenses and a set of questions. Writers and site owners want to know how much of t
Charge pages on criminal defense sites are long. A good one covers what the charge means, possible penalties, the court process, general defenses and a set of questions. Writers and site owners want to know how much of that gets read, and the default analytics setup barely answers the question.
This post shows a simple way to record which sections of a long page visitors actually reach, using GA4 and a few lines of JavaScript. It is written for developers and technical marketers who build or maintain law firm sites.
Why the built-in scroll event falls short
GA4 can record a scroll event automatically when a visitor reaches about 90 percent of the page depth. That single threshold tells you who reached the bottom. It doesn't tell you where everyone else stopped.
On a charge page, the interesting question is section by section. Did readers reach the penalties section? Did they get past it to the process section? Did anyone see the questions at the end? Percent-based depth also shifts meaning as the page changes, since 50 percent of the page lands somewhere different every time content is added.
Tracking by section heading avoids both problems. The event says which section was seen, whatever the page length.
Firing an event when a section heading appears
The approach uses IntersectionObserver to watch each h2 in the article body and send one event per section per page view. It assumes headings have id attributes, which most templates add for anchor links anyway.
const seen = new Set();
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
const id = entry.target.id;
if (seen.has(id)) return;
seen.add(id);
gtag('event', 'section_view', {
section_id: id,
page_type: document.body.dataset.pageType || 'unknown'
});
});
}, { rootMargin: '0px 0px -40% 0px' });
document.querySelectorAll('article h2[id]').forEach((h) => observer.observe(h));
The rootMargin setting means a heading counts as seen once it moves into the upper part of the viewport, rather than the moment its top edge appears at the bottom of the screen. Adjust it after watching how the page behaves on a phone.
If the site uses Google Tag Manager, push the same data to the dataLayer and build the GA4 event tag there instead of calling gtag directly.
Registering the parameters
GA4 doesn't show custom event parameters in standard reports until they are registered. In the admin area, add section_id and page_type as event-scoped custom dimensions. Data collected before registration won't appear in those dimensions, so do this before the code goes live.
Page type should come from the template, not from parsing URLs in the browser. A data attribute on the body set by the CMS, with values such as charge, court or process, keeps the grouping stable when URL patterns change.
Reading the results
Build an exploration in GA4 with page path and section_id as rows and event count as the value. For each charge page, compare the count for the first section with each later one. The drop between sections shows where readers leave.
A few patterns to watch for:
- A sharp drop right after the penalties section often means readers got what they came for and either called or left.
- A drop before the penalties section suggests the introduction is too long.
- Very low counts on the questions section may mean it sits too far down or repeats earlier sections.
Pair the section data with contact events. If readers who reach the process section call at a higher rate, that section may deserve a higher position. For layout ideas once you know where readers drop off, this guide to laying out a long charge page so readers can find their answer is a useful companion.
Privacy and performance notes
Defense sites have visitors who may be under investigation. The events above carry no personal data, and they should stay that way. Never put form inputs, names or phone numbers into event parameters. Respect your consent setup so the events only fire when analytics is allowed.
On performance, a single IntersectionObserver watching a handful of headings is cheap. Avoid scroll listeners that run on every scroll tick, which can make long pages feel sluggish on older phones.
Testing before trusting the numbers
Use GA4's DebugView, with debug mode turned on or through Tag Assistant, to confirm that each heading fires once and only once. Test on a real phone as well as a desktop browser. Sticky headers can cover headings at the top of the viewport and change when the observer fires.
Give the data a few weeks before drawing conclusions, especially on low-traffic pages. For more on legal marketing analytics and search data, the data library for defense firm marketing collects related articles.
Questions about section tracking
Will this count a section if the reader jumps to it from a table of contents?
Yes. Jumping to an anchor brings that heading into view, so the event fires. Sections skipped by the jump won't fire unless they pass through the viewport later.
Does this replace the built-in scroll event?
You can keep both. The built-in event is a rough completion signal, and the section events add the detail.
Can I use the same code on court and process pages?
Yes. As long as headings have ids and the page type attribute is set, the same script works across templates.
SBD Marketing works only with criminal defense law firms, one firm per city. It builds websites for defense practices and handles SEO for the charges they defend, along with AI search visibility and SEO audits.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.