# WPAC Integration for Google Analytics

A simple and effective Google Analytics integration plugin for WordPress with Universal Analytics, GA4, and flexible code placement.

## Description

WPAC Integration for Google Analytics is a lightweight WordPress plugin that seamlessly integrates Google Analytics into your website. It supports multiple tracking methods including Universal Analytics (analytics.js, gtag.js) and Google Analytics 4 (GA4), with flexible code placement options and a comprehensive setup guide.

## Features

### Core Features
- ✅ **Multiple Tracking Methods**: Support for analytics.js, gtag.js, and GA4
- ✅ **Flexible Code Placement**: Choose between head and footer placement
- ✅ **Easy Configuration**: Simple admin interface with clear options
- ✅ **Real-time Preview**: See your tracking code before it goes live
- ✅ **Comprehensive Setup Guide**: Step-by-step instructions for beginners
- ✅ **WordPress Standards**: Follows WordPress coding standards and best practices
- ✅ **Secure Implementation**: Proper sanitization and validation
- ✅ **Lightweight**: Minimal impact on site performance

### Tracking Methods Supported
1. **Analytics.js (Universal Analytics)**: Classic Google Analytics tracking
2. **Gtag.js (Universal Analytics)**: Modern Universal Analytics implementation
3. **GA4 (Google Analytics 4)**: Latest Google Analytics platform

### Code Placement Options
- **Head**: Tracks page views immediately when the page loads
- **Footer**: May miss some early page interactions but loads faster

## Installation

### Method 1: Upload via WordPress Admin
1. Download the plugin ZIP file
2. Go to **WordPress Admin → Plugins → Add New**
3. Click **Upload Plugin**
4. Choose the ZIP file and click **Install Now**
5. Activate the plugin

### Method 2: Manual Installation
1. Extract the plugin files
2. Upload the `wp-google-analytics.php` file to `/wp-content/plugins/wpac-integration-for-google-analytics/`
3. Go to **WordPress Admin → Plugins**
4. Find "WPAC Integration for Google Analytics" and click **Activate**

## Configuration

### Step 1: Access Plugin Settings
1. Go to **WordPress Admin → Google Analytics**
2. You'll see two tabs: **Settings** and **Setup Guide**

### Step 2: Follow the Setup Guide
1. Click on the **Setup Guide** tab
2. Follow the step-by-step instructions to:
   - Create a Google Analytics account
   - Set up your property
   - Get your tracking ID
   - Configure the plugin
   - Verify your setup

### Step 3: Configure Settings
1. Go to the **Settings** tab
2. Check **Enable Google Analytics tracking**
3. Enter your **Tracking ID** (e.g., G-XXXXXXXXXX for GA4 or UA-12345678-9 for Universal Analytics)
4. Select your **Tracking Method**:
   - **GA4**: Recommended for new websites
   - **Gtag.js**: Universal Analytics with gtag
   - **Analytics.js**: Universal Analytics with analytics.js
5. Choose **Code Placement** (Head or Footer)
6. Click **Save Changes**

## Usage

### Basic Usage
Once configured, the plugin will automatically:
- Insert the appropriate Google Analytics tracking code
- Track page views and user interactions
- Send data to your Google Analytics account

### Tracking Code Preview
After saving your settings, you'll see a preview of the tracking code that will be inserted on your website. This helps verify that the correct code is being generated.

### Verification
1. Visit your website in a new browser window
2. Go to **Google Analytics → Real-time → Overview**
3. You should see your visit in the real-time data
4. Wait 24-48 hours for regular reports to populate

## Tracking Methods Explained

### GA4 (Google Analytics 4)
- **Recommended for**: New websites and fresh setups
- **Features**: Enhanced measurement, better privacy controls, future-proof
- **Tracking ID Format**: G-XXXXXXXXXX

### Universal Analytics (Gtag.js)
- **Recommended for**: Existing Universal Analytics setups
- **Features**: Modern implementation, good performance
- **Tracking ID Format**: UA-12345678-9

### Universal Analytics (Analytics.js)
- **Recommended for**: Legacy setups requiring analytics.js
- **Features**: Classic implementation, widely supported
- **Tracking ID Format**: UA-12345678-9

## Troubleshooting

### Common Issues

#### No Data Appearing
- **Solution**: Wait 24-48 hours for data to appear in regular reports
- **Check**: Real-time reports should show data immediately

#### Real-time Not Working
- **Check**: Your tracking ID is correct
- **Verify**: Tracking is enabled in plugin settings
- **Test**: Visit your site in incognito mode

#### Ad Blockers
- **Issue**: Some ad blockers may prevent tracking
- **Solution**: Test in incognito mode or disable ad blockers temporarily

#### GDPR Compliance
- **Consider**: Adding a cookie consent banner for EU visitors
- **Note**: The plugin doesn't include GDPR compliance features by default

## Technical Details

### Requirements
- **WordPress**: 5.0 or higher
- **PHP**: 8.0 or higher
- **Tested up to**: WordPress 6.8

### File Structure
```
wpac-integration-for-google-analytics/
├── wpac-integration-for-google-analytics.php (Main plugin file)
└── README.md
└── assets/
    └── screenshot-1.png
    └── screenshot-2.png
    └── assets/css/admin.css
```
### Screenshots

- Plugin settings page for WPAC Integration for Google Analytics.

### Hooks and Filters
The plugin uses standard WordPress hooks:
- `admin_menu`: Adds admin menu
- `admin_init`: Registers settings
- `wp_head`: Outputs tracking code in head
- `wp_footer`: Outputs tracking code in footer

### Security Features
- Input sanitization using `sanitize_text_field()`
- Output escaping using `esc_attr()` and `esc_js()`
- Capability checks for admin access
- Nonce verification for forms

## Support

### Documentation
- **Setup Guide**: Built into the plugin admin interface
- **Google Analytics Help**: [https://support.google.com/analytics/](https://support.google.com/analytics/)
- **GA4 Setup Guide**: [https://support.google.com/analytics/answer/10089681](https://support.google.com/analytics/answer/10089681)

### Useful Links
- [Google Analytics](https://analytics.google.com/)
- [Google Analytics Help Center](https://support.google.com/analytics/)
- [Analytics Developer Guide](https://developers.google.com/analytics)

## Changelog

### Version 1.1.4
- Added comprehensive Setup Guide tab
- Improved admin interface styling
- Enhanced tracking code preview
- Better error handling and compatibility

### Version 1.1.2
- Added comprehensive Setup Guide tab
- Improved admin interface styling
- Enhanced tracking code preview
- Better error handling and compatibility

### Version 1.1.1
- Added comprehensive Setup Guide tab
- Improved admin interface styling
- Enhanced tracking code preview
- Better error handling and compatibility
- Updated for WordPress 6.8 compatibility

### Version 1.0.0
- Initial release
- Basic Google Analytics integration
- Multiple tracking methods support
- Flexible code placement options

## Contributing

We welcome contributions! Please feel free to submit issues and pull requests.

## License

This plugin is licensed under the GPL v2 or later.

## Credits

- **Author**: WP Agency Care
- **Author URI**: https://wpagencycare.com/
- **License**: GPL v2 or later
- **Text Domain**: wpac-integration-for-google-analytics

## Disclaimer

This plugin is not affiliated with Google. Google Analytics is a trademark of Google LLC. The plugin simply provides an easy way to integrate Google Analytics into WordPress websites.

---

**Need help?** Check the Setup Guide tab in your WordPress admin or visit the Google Analytics Help Center for detailed documentation. 