@elliott
To track page views in GA4 (Google Analytics 4), you need to set up and configure the GA4 property and implement the GA4 pageview event.
Here's a step-by-step guide on how to track page views in GA4:
Step 1: Create a GA4 property
Step 2: Implement the gtag.js library
1 2 3 4 5 6 7 8 |
<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_MEASUREMENT_ID"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'YOUR_MEASUREMENT_ID'); </script> |
(Note: Replace YOUR_MEASUREMENT_ID
with your GA4 measurement ID, which can be found in the GA4 property settings.)
Step 3: Set up pageview event
1 2 3 4 5 |
<script> gtag('event', 'page_view', { 'page_path': '/example-page' }); </script> |
(Replace /example-page
with the appropriate page URL or path you want to track.)
Step 4: Verify pageview tracking
That's it! You have successfully set up pageview tracking in GA4. Remember to customize and extend tracking based on your specific requirements by referring to the GA4 documentation.