Steps to Integrate Google Analytics with Moodle

1. Create a Google Analytics Account (if you don’t have one)

  • Go to Google Analytics and create an account.
  • Set up a new property for your Moodle site, and Google will generate a tracking ID (format: UA-XXXXXX-Y) or Measurement ID (format: G-XXXXXXXXXX for GA4).

2. Add Google Analytics Tracking Code to Moodle

You’ll need to add the Google Analytics tracking code to Moodle’s theme.

Option 1: Add Tracking Code Directly in the Theme

If you have access to your Moodle theme files, you can manually add the Google Analytics tracking code to the HTML header.

  • Go to your Moodle site's theme settings:

    • Navigate to Site administration > Appearance > Themes > [Your current theme] (e.g., Moove, Boost, etc.).

    • Scroll down to Additional HTML.

    • Paste your Google Analytics tracking code in the Within HEAD section. It will look something like this:

      html
      Copy code
      <!-- Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-XXXXXXXXX-X'); // Replace with your tracking ID </script> <!-- End Google Analytics -->
  • Save the changes.