Install the Google Analytics contributed module. It provides a clean interface for adding your tracking ID and configuring various options like which roles to track, which pages to exclude, and which events to capture.
Configure the module under Configuration then Google Analytics. Enter your GA4 measurement ID, then fine tune settings like whether to track admin pages, whether to anonymise IP addresses for privacy, and which links should be tracked as downloads.
The module handles the JavaScript snippet placement and keeps it updated as Google’s tracking code evolves. For GDPR compliance, combine it with the EU Cookie Compliance module to get user consent before loading trackers. Many sites are moving away from Google Analytics towards privacy focused alternatives like Matomo or Plausible. Drupal has contrib modules for both, offering the same level of integration polish.