Skip to main content
Please wait...
count page depth

Counting the page depth of a url in Google Data Studio

When you start analyzing your positioning on search engines, one interesting KPI to look at is the page depth of the landing page on which landed your traffic.

Unfortunately, it is not a default value provided by Google Analytics or Google Search Console so we will need to calculate it thanks to a calculated field.

Google Search Console

After you have imported the "Google Search Console - Url" data source to your report, create a new table containing only the "Landing page" dimension.

Click on the button "Add dimension", give a name to your dimension (ex "Page depth") and paste the below code:

CAST(
LENGTH(
REGEXP_REPLACE(Landing Page,"[^/]","")
)-2
AS TEXT)

This function will calculate the number of slashes in the url and decrease it by two (as the landing page is including the hostname, we remove the two slashes from https://), which will give us the page depth of the Landing page :)

Google Analytics

It is also possible to do the same calculation with information coming from Google Analytics data source. The only change compare to the previous function is the dimension name, which should be "Page" or "Landing page" instead of "Landing page".

CAST(
LENGTH(
REGEXP_REPLACE(Page,"[^/]","")
)-2
AS TEXT)

Caution: if you haven't setup Google Analytics to return the hostname at the beginning of the urls, then you don't need to decrease the result by 2, so only put:

CAST(
LENGTH(
REGEXP_REPLACE(Page,"[^/]","")
)
AS TEXT)

Blog

Our latest articles

Need help?

Let’s Get To Work Together