What steps can be taken to ensure accurate tracking of website visits when using Google Analytics code in PHP include files?

To ensure accurate tracking of website visits when using Google Analytics code in PHP include files, it is important to include the Google Analytics tracking code in the header section of each page. This ensures that the tracking code is loaded before any content is displayed to the user, allowing for accurate tracking of page views and other metrics.

<?php
// Include this code snippet in the header section of each PHP file to ensure accurate tracking with Google Analytics

// Google Analytics tracking code
echo "<script async src='https://www.googletagmanager.com/gtag/js?id=YOUR_GA_TRACKING_ID'></script>";
echo "<script>";
echo "  window.dataLayer = window.dataLayer || [];";
echo "  function gtag(){dataLayer.push(arguments);}";
echo "  gtag('js', new Date());";
echo "  gtag('config', 'YOUR_GA_TRACKING_ID');";
echo "</script>";
?>