# Using Google Analytics with Drupal

> Track visitor traffic on your Drupal site with Google Analytics, using the Google Analytics module or by editing your theme.

Source: https://helpcenter.ruachost.com/apps/drupal/using-google-analytics-with-drupal/

Google Analytics provides detailed statistics about visitor traffic to your site. Integrating it with Drupal allows you to track user behavior, measure performance, and optimize your content. On **ruachost.com**, you can enable Google Analytics in Drupal either by using a module or by editing your theme.

## Why Use Google Analytics?

- Monitor visitor traffic and engagement.
- Track conversions and goals.
- Identify popular content and user flow.
- Improve SEO and marketing strategies.

## Methods to Enable Google Analytics in Drupal

### Method 1: Use the Google Analytics Module

1. Sign up for a free account at Google Analytics and obtain your **Tracking ID**.
2. Download the Google Analytics module.
3. Log in to Drupal as an administrator.
4. Go to **Extend → Install new module**.
5. Upload the module `.zip` file and click **Install**.
6. Enable the module under **Extend → List → Statistics → Google Analytics**.
7. Go to **Configuration → System → Google Analytics**.
8. Enter your **Tracking ID** and configure additional settings (tracking scope, exclusions, etc.).
9. Click **Save configuration**.

✅ Google Analytics is now enabled for your Drupal site. *(Note: It may take up to 24 hours for Google Analytics to start receiving data.)*

### Method 2: Edit the Drupal Theme

1. Log in to your Google Analytics account.
2. Go to **Admin → Tracking Info → Tracking Code**.
3. Copy the entire JavaScript tracking snippet.
4. On your server, navigate to:

   ```
   ~/public_html/themes/theme_name/templates
   ```

   *(Replace* `theme_name` *with your active theme.)*
5. Open the `page.tpl.php` file in a text editor.
6. Paste the tracking code at the top of the file, including the `<script>` tags.
7. Save changes.

✅ Google Analytics will now track every page load.

## Important Notes

- Modules are easier to manage but add slight processing overhead.
- Editing the theme directly is lightweight but requires careful updates when changing themes.
- Always back up your site before making changes.
