A WordPress plugin that seamlessly integrates WordPress and WooCommerce events with Google Analytics using Google Tag Manager (GTM) for robust event tracking.
The Google Analytics WP Integration plugin enables WordPress and WooCommerce site owners to track user interactions by mapping WordPress hooks to Google Analytics events via Google Tag Manager. It provides a user-friendly admin interface to configure event mappings, supports WooCommerce e-commerce tracking, and includes default mappings for common events.
- Google Tag Manager Integration: Inject GTM code with a simple container ID setup.
- Flexible Event Mapping: Map WordPress and WooCommerce hooks to Google Analytics events with customizable parameters.
- WooCommerce Support: Track e-commerce events like
add_to_cart
,purchase
,view_item
, and more. - Admin Interface: Intuitive settings page with live preview, preset loading, and event management.
- Default Mappings: Predefined mappings for WordPress and WooCommerce events.
- Custom Parameters: Define sources and patterns for event parameters.
- RTL Support: Full compatibility with right-to-left languages in the admin UI.
- Debug Mode: Debug output for administrators to verify event data.
- Translation-Ready: Supports localization with a dedicated text domain (
ga-wp-integration
).
-
Download the Plugin:
- Clone this repository:
git clone https://github.com/ildrm/ga-wp-integration.git
- Or download the ZIP file from the Releases page.
- Clone this repository:
-
Install the Plugin:
- Upload the
ga-wp-integration
folder to the/wp-content/plugins/
directory of your WordPress installation. - Alternatively, upload the ZIP file via Plugins > Add New > Upload Plugin in the WordPress admin dashboard.
- Upload the
-
Activate the Plugin:
- Go to Plugins in the WordPress admin dashboard and activate Google Analytics WP Integration.
-
Configure Settings:
- Navigate to GA Integration in the WordPress admin menu.
- Enter your Google Tag Manager container ID (e.g.,
GTM-XXXXXX
). - Configure event mappings or use the default mappings provided.
-
Test the Setup:
- Save your settings and verify GTM code injection in the
<head>
and<body>
sections. - Use Google Tag Manager’s Preview mode or enable debug mode by adding
?ga_debug=1
to any URL (admin-only) to test event tracking.
- Save your settings and verify GTM code injection in the
-
Configure GTM:
- Enter your GTM container ID in the plugin’s settings page under GA Integration > Settings.
- The plugin automatically injects GTM scripts and noscript iframes.
-
Manage Event Mappings:
- Add, edit, or remove event mappings in the settings page.
- Map WordPress/WooCommerce hooks (e.g.,
wp_login
,woocommerce_add_to_cart
) to Google Analytics events (e.g.,login
,add_to_cart
). - Customize parameters using sources (e.g.,
product_id
,order_total
) and patterns (e.g.,{product_id}-{variation_id}
).
-
Debugging:
- Enable debug mode by appending
?ga_debug=1
to any URL (visible to admins only) to view event data. - Use Google Tag Manager’s Preview mode to monitor
dataLayer
events.
- Enable debug mode by appending
-
WooCommerce Tracking:
- The plugin automatically detects WooCommerce and provides mappings for e-commerce events.
- Track product views, cart actions, checkouts, purchases, and refunds with minimal setup.
- Settings Page: Configure GTM container ID and manage event mappings.
- Event Mapping Interface: Add or edit mappings with a live JSON preview.
- Help & Documentation: Built-in tabs explaining hooks, sources, and patterns.
- WordPress: Version 5.0 or higher
- PHP: Version 7.4 or higher
- WooCommerce: Optional, for e-commerce tracking (version 3.0 or higher recommended)
- Google Tag Manager: A valid GTM container ID
ga-wp-integration/
├── ga-wp-integration.php
├── LICENSE
├── readme.txt
└── README.md
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m 'Add your feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a Pull Request.
Please ensure your code follows WordPress coding standards and includes appropriate documentation.
- Update the version number in
ga-wp-integration.php
and this README. - Test thoroughly on a WordPress installation with and without WooCommerce.
- Create a ZIP file for distribution:
zip -r ga-wp-integration.zip ga-wp-integration/ -x "*.git*"
.
- Initial release with GTM integration, event mapping, and WooCommerce support.
This plugin is licensed under the GNU General Public License v2 or later.
- Author: Shahin Ilderemi (ildrm.com)
- Contributors: Open to contributions via GitHub.
- Thanks: To the WordPress and WooCommerce communities for their resources and support.
For issues, feature requests, or questions:
- Open an issue on the GitHub Issues page.
- Contact the author via ildrm.com.