Question from Reddit:
I am looking to track for a segment of users that have submitted a lead form on my website, what was the first page they visited in that session and the last page they visited before submitting the form. Is this possible on GA4 – I’ve tried using path exploration and free form exploration, but neither seem to be offering accurate results?
Here’s what I did:
I created a custom event on GA4 to track form submissions (it’s currently an event that tracks when a user reaches the thank you page after submitting the form).
I then created 2 separate Free Form Explorations:
1) Tracking First Page – I’m using the “Landing page + query string” dimension and tracking “Total users” as the value
2) Tracking Last Page – I’m using the “Page referrer” dimension and tracking “Total users” as the value. I’ve also got this filtered to only show “page_view” events and page titles that contain the form I’m interested in
For both of these explorations, I’ve also added a segment with the following conditions:
– Form submission event count is greater than or equal to 1 -AND- Session medium is equal to organic (we’re only looking to track organic traffic at the moment)
(Condition scoping is set to “Within same session”)
Has anyone tried anything similar and seen results? Or, have any ideas how to achieve this? Would appreciate any help. Thanks!
P.S. I also tried Path Exploration – it seems to work reasonably well for last page visited, but I can’t figure out how to get the first page visited (considering there could be a large number of pages visited in between first and last page for any given user).
Answer from Nabil:
The short answer is:
What you are trying to achieve is possible in GA4, but your current method using Page referrer
for the last page and a standard Free Form Exploration for the first page is running into issues because these dimensions aren’t designed to pinpoint the exact first and last page within a specific segmented session path.
The most reliable and direct way to get the first page and last page before a conversion is to use the Path Exploration report and set your form submission (or the corresponding page_view
on the thank you page) as the End Point of the path.
To get the first page, set the first step of the path as the Landing page + query string
dimension and let the rest of the path funnel naturally to your conversion end point.
For a more robust solution that allows you to easily analyze this data with other metrics, you should use the Google Analytics Data API to extract the raw event data, process it in a cloud environment, and visualize it using the Looker Studio API.
The long answer is:
Your setup is quite close, but the reason your results feel inaccurate stems from a misunderstanding of how GA4’s native dimensions and reports work for this specific use case.
For your first page, using the Landing page + query string
dimension with a session segment based on the form submission event is the correct approach to see where those converting sessions began.
However, for the last page visited before the form submission, the Page referrer
dimension is incorrect because it only captures the previous page viewed, which will be the page before the thank you page, but only if the user navigated to it directly.
If the user clicked a button or had a complex process, the referrer can be unreliable.
Furthermore, Page referrer
only tracks one step back, which isn’t what you need.
The Path Exploration report is the superior tool here.
To get the first page, start the Path Exploration with the Landing page + query string
dimension.
To get the last page before submission, you need to reverse the path exploration.
Set the form submission event’s page_view
(the thank you page) as the End Point.
Then, for the step immediately preceding the end point, you will see all the pages that led directly to that conversion page.
This is the most accurate last page in a single session before conversion.
Since you are only interested in organic traffic, you’d apply your session-scoped segment for Session medium is equal to organic
to the exploration.
If you find the native GA4 explorations restrictive, especially when trying to slice this data with other dimensions, the most powerful and scalable solution is to leverage the Google Analytics Data API.
You can use the Data API to extract the specific event stream data, including the page_location
and session_id
, for all users who completed the conversion event.
You can then use a server-side environment like Google Cloud Platform or a tool like Stape to process this data.
The script would look for the session_start
event to identify the first page and then iterate backward from the form_submission
event to find the last page_view
that occurred before the conversion event within the same session_id
.
This processed, clean data can then be connected to and visualized using the Looker Studio API.
This approach completely separates your data collection from your analysis, giving you the flexibility to create custom metrics and visualizations that are simply not possible with the fixed structure of GA4’s default reports.