Google Tag Manager, Analytics, & Search Console for Drupal 9
This guide works for Drupal 8 too!
Also works for Drupal 8! Installing Google Tag Manager to your Drupal site adds a layer of complexity, but it's far more flexible & powerful than Google Analytics alone.