In Universal Analytics, you can record a destination goal when a user lands on a specified page. A typical example of a destination goal is a "thank you" or "confirmation" page following a form submission.
As noted in Google Analytics 4 key events basics, Google Analytics 4 (GA4) properties don't send pageview hits. Instead, when a user visits a page on your website, GA4 sends a page_view
event (or if the user was on your app, a screen_view
event). The event has parameters that indicate the URL, page title, and so on.
To generate a key event for a specific pageview, you can take one of the following two approaches.
Option 1: Create a new key event via the user interface
As noted in Key events in Google Analytics 4, you can’t define a GA4 key event based on parameters other than event_name. The challenge for defining a key event based on a specific pageview is that every pageview is recorded with the same event name: page_view
. If you mark the default page_view
event as a key event, every pageview on your site will be counted as a key event.
The solution is to create a new event via the user interface that's triggered when the page_view event occurs on the desired page:
- In Admin under Data display, click Events, then click Create event.
- Choose a data stream.
- Click Create, then in the Create event panel:
- Enter a name for the new event.
Use one of the recommended events if you can. For example, submitting a "contact us" form could use the
generate_lead
event name. - For the first matching condition, specify event_name - equals - page_view
- For the second matching condition, specify a page_location (or potentially a page_title), such as page_location - equals - https://www.example.com/contact-us-submitted.
- If you want to copy a goal value from Universal Analytics, click the Add modification button and enter the Parameter value and for the New Value enter the value you used in the Universal Analytics goal (e.g. "10").
- Enter a name for the new event.
- Return to Admin, then under Property, click Key events.
- Click New key event.
- As the event name, enter the event configured in steps 1-4, for example,
generate_lead
.
While you cannot directly create a parameterized key event, you can use the Event Modification to create a new (admin-level) key event based on event name and one or more additional event parameters.
Option 2: Send a key event-specific event from your site code
If you can edit your site code or Tag Manager configuration, you can send an event whose only purpose is to indicate that a key event has occurred:
- On the /contact-us-submitted page, update your gtag code or configure Google Tag Manager to directly send a
generate_lead
event. - Mark the
generate_lead
event as a key event, as outlined in steps 4-6 in the preceding procedure.
Virtual pageviews
Sometimes, you might want to record a page_view
event even if a physical page load has not occurred, as can be the case for sites built with SPA (single-page application) or PWA (progressive web app) architectures, or for specific AJAX-like flows in your web experience.
Let’s say that your web developers have built a four-screen checkout experience to render in the browser without interceding page loads. In that case, only the first screen of the checkout process requires a physical page load and generates a Google Analytics pageview by default.
If a pageview is not generated by default for steps 2-4, how can you build a funnel and record a key event in Google Analytics?
In Universal Analytics, you can generate a "virtual pageview." Use your own gtag scripting or tags and triggers in Google Tag Manager to send the screen refresh as a pageview. You can also override the URL in the Page dimension to be whatever value you want (for example, /checkout-2, /checkout-3, and so on).
In GA4, you can take the same approach. The difference is you'll track a page_view
event, that is, an event with page_view (or a different name, such as virtual_page_view) as the event name, and specify your own page_location
parameter (https://www.example.com/checkout-2, https://www.example.com/checkout-3, and so on). It’s also a good idea to include a meaningful page_title
parameter, which appears by default in some Google Analytics reports and explorations (for example, the path exploration), instead of the page_location
parameter.
You can then create an event via the user interface as described above to generate a new event - for example, checkout_completed
-- for the final step of the checkout process.
You can also take the alternative approach outlined above: directly generate a checkout_completed
event through gtag or Google Tag Manager on the final checkout step.
Finally, mark your checkout_completed
event as a key event.