A lightweight WordPress plugin that automatically sends successful WPForms submissions to Google Tag Manager via dataLayer for enhanced tracking and analytics.
- Automatic Integration - Works seamlessly with WPForms without any configuration
- Google Tag Manager Ready - Sends data directly to GTM's dataLayer
- Privacy Focused - Automatically excludes sensitive fields (customizable via filters)
- AJAX Compatible - Works with both AJAX and traditional form submissions
- Field Normalization - Automatically normalizes field names for consistency
- Developer Friendly - Includes filter hooks for customization
- Lightweight - Minimal performance impact on your site
When a form is submitted, the following data is pushed to the dataLayer:
{
"event": "wpforms_submission",
"form_id": 123,
"form_name": "Contact Form",
"form_data": {
"name": "John Doe",
"message": "Hello world"
},
"entry_id": 456
}
By default, these fields are excluded:
email
telefono
correo_electrΓ³nico
phone_number
email_address
You can customize which fields are excluded using the filter hook:
add_filter('wpforms_datalayer_excluded_fields', function($fields) {
// Add more sensitive fields
$fields[] = 'password';
$fields[] = 'credit_card';
$fields[] = 'ssn';
return $fields;
});
You can modify the complete data before it's sent to the dataLayer:
add_filter('wpforms_datalayer_data', function($data, $form_data, $entry_id) {
// Add custom data
$data['custom_field'] = 'custom_value';
// Modify existing data
$data['form_name'] = 'Custom: ' . $data['form_name'];
return $data;
}, 10, 3);
- WordPress 5.0 or higher
- PHP 7.4 or higher
- WPForms plugin (free or pro version)
- Google Tag Manager configured on your site
- Download the plugin zip file
- Go to
Plugins > Add New
in your WordPress admin - Click
Upload Plugin
and select the zip file - Install and activate the plugin
- Download and extract the plugin files
- Upload the
wpforms-datalayer-tracker
folder to/wp-content/plugins/
- Activate the plugin through the 'Plugins' menu in WordPress
bash
git clone https://github.com/nxssie/wpforms-datalayer-tracker.git
cd wpforms-datalayer-tracker
# Copy to your WordPress plugins directory
No configuration needed! The plugin works automatically once activated. Just ensure you have:
- β WPForms installed and active
- β Google Tag Manager properly configured on your site
- β Forms created in WPForms
Hook | Description | Parameters |
---|---|---|
wpforms_datalayer_excluded_fields |
Modify excluded field names | $fields (array) |
wpforms_datalayer_data |
Modify complete dataLayer data | $data , $form_data , $entry_id |
wpforms-datalayer-tracker/
βββ wpforms-datalayer-tracker.php # Main plugin file
βββ readme.txt # WordPress plugin readme
βββ README.md # This file
βββ LICENSE # GPL v3+ license
- Clone the repository
- Copy to your local WordPress plugins directory
- Activate in WordPress admin
- Test with WPForms and Google Tag Manager
The plugin includes console logging for debugging. Open your browser's developer tools to see:
- Form submission detection
- DataLayer push confirmations
- Error messages if any issues occur
Q: Do I need to configure anything after installation?
A: No, the plugin works automatically once activated.
Q: Is it compatible with AJAX forms?
A: Yes, it's optimized for WPForms AJAX submissions and also works with traditional submissions.
Q: Can I customize which fields are excluded?
A: Yes! Use the wpforms_datalayer_excluded_fields
filter to customize the exclusion list.
Q: How do I add custom excluded fields?
A: Add the filter hook to your theme's functions.php or a custom plugin as shown in the Customization section.
Q: Does it affect site performance?
A: No, the plugin is very lightweight and only executes when forms are submitted.
This plugin:
- β Does not store any personal data
- β Does not send data to external servers
- β Only pushes data to the browser's dataLayer
- β Excludes sensitive fields by default
- β Provides hooks for additional privacy customization
- β Respects user privacy
Note: It's your responsibility to configure Google Tag Manager in accordance with applicable privacy regulations (GDPR, CCPA, etc.).
- Fix bug where dataLayer push did not occur for non-AJAX form submissions
- Initial release
- Basic WPForms integration
- Automatic dataLayer sending
- Sensitive field exclusion with filter hooks
- Support for AJAX and traditional submissions
- Developer-friendly customization options
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the GPL v3+ License - see the LICENSE file for details.
nxssie
If you find this plugin helpful, please consider:
- β Starring this repository
- π Reporting issues
- π‘ Suggesting new features
- π Contributing to the code
Made with β€οΈ for the WordPress community