A PHP-based integration system that bridges Action Network form submissions with Meta's Conversions API for enhanced advertising attribution and campaign optimization.
This system captures form submissions from Action Network and sends them to Meta's Conversions API, providing:
- Server-side tracking via webhooks for reliable data delivery
- Client-side tracking via JavaScript for enhanced browser data
- Automatic event type detection (Donate for donations, CompleteRegistration for other forms)
- Facebook Click ID (fbclid) capture for improved attribution
- Data deduplication to prevent double-counting
- Secure credential handling with AES-256-CBC encryption
webhook.php
- Main webhook endpoint for Action Network submissionsapi.php
- REST endpoint for JavaScript tracker datasetup.php
- Web-based configuration wizardcrypto.php
- Encryption system for secure credential storagefunctions.php
- Shared utilities for Meta API communicationtracker.js.php
- Dynamic JavaScript tracker generator
- User clicks Meta ad β lands on Action Network form
- Browser tracking script sends PageView event to Meta
- User submits form β Action Network sends webhook
- JavaScript tracker captures form submission with browser data
- Both webhook and browser data are sent to Meta with deduplication
- Meta receives complete attribution data for campaign optimization
- PHP 7.4+ with cURL support
- Web server (Apache/Nginx)
- Meta Business Manager account with admin access
- Action Network account
-
Clone the repository:
git clone https://github.com/yourusername/an-to-conversionsapi.git cd an-to-conversionsapi
-
Set up web server:
- Point your web server to the project directory
- Ensure PHP has write permissions to the
logs/
directory
-
Configure the system:
- Visit
/setup.php
in your browser - Follow the step-by-step wizard to configure your integration
- Visit
- Enter Meta Credentials - Pixel ID and Conversions API Access Token
- Configure Webhook - Copy the generated webhook URL to Action Network
- Test Webhook - Verify webhook connectivity
- Add Facebook Click ID Field - Add hidden fbclid field to forms
- Add Browser Tracking Script - Install JavaScript tracker
- Test Browser Tracking - Verify complete integration
- Complete Setup - Integration ready
- Go to Meta Events Manager
- Select your Pixel from Data Sources
- Find the Pixel ID in Settings
- In Meta Events Manager, select your Pixel
- Go to Settings β Conversions API
- Click "Generate Access Token"
- Copy the complete token (starts with EAA)
Important: You need Admin access to the Business Manager that owns the Pixel.
-
Add Webhook:
- Go to Start Organizing β Details β API & Sync β Webhooks
- Add the webhook URL from the setup wizard
- Select "All Actions" for events
- Set status to "Active"
-
Add fbclid Field to ALL forms:
- Edit your form β Settings β Custom Fields
- Add Field β Custom HTML
- Administrative title: "fbclid"
- Content:
<input type="hidden" name="fbclid" id="fbclid">
-
Add Tracking Script:
- Add the JavaScript code from setup wizard to your form's Custom HTML section
- AES-256-CBC encryption for credential storage
- HMAC integrity verification for encrypted data
- SHA256 hashing for all PII before transmission to Meta
- Timestamp-based expiration for encrypted credentials
- No plaintext credential storage
The system automatically detects and sends appropriate event types:
Donate
- For Action Network donation formsCompleteRegistration
- For petitions, signups, and other formsPageView
- When users visit form pages (via JavaScript)
- Spanish mobile numbers (9 digits starting with 6/7) get +34 country code
- All phones stripped of non-numeric characters and leading zeros
- Consistent Event IDs using SHA256 of
email + rounded_timestamp_to_60s
- Same algorithm in PHP and JavaScript prevents double-counting
- Automatically filters out Action Network test submissions
- Uses known test email patterns and UUIDs
βββ README.md # This file
βββ CLAUDE.md # Development guidance
βββ setup.php # Configuration wizard
βββ webhook.php # Main webhook endpoint
βββ api.php # JavaScript tracker endpoint
βββ tracker.js.php # Dynamic JavaScript generator
βββ functions.php # Shared utilities
βββ crypto.php # Encryption system
βββ verify.php # Credential verification
βββ generate_hash.php # Hash generation
βββ check_test.php # Webhook test checker
βββ check_script_test.php # Script test checker
βββ dashboard.php # Analytics dashboard
βββ dashboard_api.php # Dashboard data API
βββ debug_*.php # Debug utilities
βββ logs/ # Log files directory
logs/app.log
- General application logslogs/error.log
- Error logslogs/debug.log
- Debug informationlogs/webhooks.log
- Webhook-specific logs
debug_facebook_data.php
- Test Meta API connectivitydebug_meta_payload.php
- Inspect payload formatting
# Monitor logs in real-time
tail -f logs/app.log
# Test webhook connectivity
curl -X POST "https://yourdomain.com/webhook.php?id=YOUR_HASH" \
-H "Content-Type: application/json" \
-d '{"test": true}'
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Production Security: Change the
SECRET_KEY
incrypto.php
before production use - HTTPS Required: Meta Conversions API requires HTTPS endpoints
- Rate Limits: Be aware of Meta API rate limits for high-volume forms
- Data Retention: Configure appropriate log rotation for the
logs/
directory
If you encounter issues:
- Check the
logs/
directory for error messages - Verify your Meta credentials have proper permissions
- Ensure webhooks are receiving data in Action Network
- Test with the built-in debug tools
For additional help, please open an issue on GitHub.
Made with β€οΈ for better Meta advertising attribution