Migrate virtual pageviews from UA to GA4

If your website loads page content dynamically and updates the document's URL, you'll usually want to send additional pageviews to measure these "virtual pageviews".

Comparison of UA and GA4 virtual pageviews

For Universal Analytics, you measure "virtual pageviews" by sending additional commands when content changes, as described in Tracking virtual pageviews.

For Google Analytics 4, you can rely on Enhanced measurement or manually send Page views in code. In most cases, enhanced measurement will be sufficient to measure page views and your code related to UA virtual pageviews can be removed. To learn more see Measure virtual pageviews in GA4.

Example of UA and GA4 virtual pageviews

If you Measure virtual pageviews in GA4, the following example compares a virtual pageview for a Universal Analytics and Google Analytics 4 property. The primary difference is the page_path vs page_location parameter.

// Universal Analytics property.
gtag('config', 'UA-XXXXX-YY', {
  page_title: 'My Profile',
  page_path: '/me'

// Google Analytics 4 property.
gtag('config', 'TAG_ID', {
  page_title: 'My Profile',
  page_location: 'https://example.com/me'  // Full URL is required.