Scroll Height In GTM With A Custom JavaScript Variable in Google Tag Manager

Last Updated: September 8, 2023

Use Data As Your Competitive Advantage

Learn exactly how VisionLabs can fix your data setup, improve tracking, and build a measurement plan based on your goals.

Table of Contents

When looking at a scroll report for a web page, have you ever thought to yourself “I wonder how tall this page actually is?”

As we all know, running 20% of a marathon is a lot different than running 20% around my street block.

Use this Custom JavaScript Variable within Google Tag Manager to display the scrollable height of a web page giving you context for how far someone has traveled towards your offer!

The Code

For those of you who know what to do, here is the code for you.

function () {
  var height =document.body.scrollHeight;
  return height;
}

What It Does

For the rest of us who don’t just know what the above script does. It is looking for the possible scrollable height in pixels of the <body> tag (where all the content is) of a page.

How to use this – Create a custom JavaScript Variable

Create a new variable, select custom java script variable, paste the above code, you are good to go!

Once you create your new custom JavaScript Variable, just paste in the above code

When you go to preview GTM, it should display the height in pixels.

This is what your returned value will look like ????

Hope this helps you in all your measurement missions!

Have a question, do not hesitate to reach out to hello(@)visionlabs.com

Build The Perfect Dashboard Every Time

Get your teams, designs & reports standardized across your organization & clients.Β 

Related Article

Keep the learning going with our recommended related articles on similar topics.

πŸ“… Free Live Workshop Live now β–· Replay available

The framework we use to drive revenue using data

Turn your data patterns into revenue. Less reporting on what happened, more action on what to do next.

$1M Challenger brands
$1B Category leaders

The same framework works at every revenue scale β€” the data problem doesn't change.

Enter your email above to save your free spot Β· June 17, 2026, 3:00 PM

Insight Engineering: Driving Revenue First β€” we're live now.

Missed it live? The full replay is playing above.

00
Days
00
Hours
00
Minutes
00
Seconds
until we go live
JJ Reynolds
Hosted by JJ Reynolds
Sharing the exact data framework his team runs with growth clients
  • In this session you'll leave with
  • A way to tell which numbers actually drive revenue, and which ones you can stop reporting.
    The framework for turning one data pattern into a revenue experiment you can ship this week.
    A repeatable system, so acting on insight stops depending on who has time to dig through dashboards.

Trusted by teams at

Days
Hours
Minutes
Seconds

Black Friday OfferπŸ”₯ Get your data audit. Normally $2,500β€”this week only $97. We’ll audit your GA4 stack and jump on a live session to prioritize fixes.