A comprehensive Google Tag Manager (GTM) template for implementing Meta Pixel tracking with advanced features for 2025 and beyond.
- Complete Meta Pixel Implementation - Support for all standard Meta events
- Advanced Matching - Automatic SHA-256 hashing of user data for improved match rates
- Consent Mode Integration - Full GTM consent mode support for GDPR/CCPA compliance
- CAPI Readiness - Built-in support for Conversions API event deduplication
- Cookie Handling - Automatic _fbp and _fbc cookie management
- PageView - Track page views
- ViewContent - Track content views with product data
- AddToCart - Track items added to cart
- AddToWishlist - Track wishlist additions
- InitiateCheckout - Track checkout initiation
- AddPaymentInfo - Track payment information addition
- Purchase - Track completed purchases with transaction data
- Lead - Track lead generation events
- CompleteRegistration - Track account registrations
- Search - Track site searches
- Contact - Track contact form submissions
- Subscribe - Track subscription events
- CustomizeProduct - Track product customization
- FindLocation - Track location searches
- Schedule - Track appointment scheduling
- StartTrial - Track trial starts
- SubmitApplication - Track application submissions
- Donate - Track donation events
- CustomEvent - Support for custom events
- GTM Consent Mode - Respects user consent preferences
- Advanced Matching Controls - Toggleable PII hashing
- Regional Compliance - Built for GDPR, CCPA, and DMA requirements
- Test Mode Support - Meta Events Manager integration for testing
- Debug Support - Test Event Code integration
- Parameter Validation - Built-in field validation
- Error Handling - Comprehensive error logging
- Documentation - Extensive inline documentation
- Download the template file (
template.tpl) - Import into Google Tag Manager:
- Go to Templates → Tag Templates
- Click "New" → "Import"
- Select the template file
- Save and publish
- Pixel ID - Your Meta Pixel ID (e.g., "123456789012345")
- Event Name - Select from standard events or enter custom event
Configure event-specific parameters:
- Event ID - Unique identifier for CAPI deduplication
- Value - Transaction value (for purchase events)
- Currency - ISO currency code (e.g., "USD")
- Content IDs - Product/content identifiers
- Content Type - Product category or content type
- Num Items - Number of items in the event
Enable advanced matching to improve attribution:
- Email - User's email address
- Phone - Phone number in E.164 format
- First Name - User's first name
- Last Name - User's last name
- City - User's city
- State - User's state/province
- ZIP Code - User's postal code
- Country - User's country (ISO code)
- External ID - Your internal user identifier
All PII data is automatically hashed with SHA-256 before transmission.
- FBP Cookie - First-party cookie (_fbp) automatically included
- FBC Cookie - Click ID cookie (_fbc) automatically generated from fbclid
- User Agent - Client user agent for better matching
- Custom FBP - Override automatic _fbp value
- Custom FBC - Override automatic _fbc value
- Ad Storage Consent - Respects
ad_storageconsent state - Analytics Storage Consent - Respects
analytics_storageconsent state - Consent Listener - Automatically updates on consent changes
- Granted - Full pixel functionality with all parameters
- Denied - Minimal pixel functionality (configurable)
- Unspecified - Configurable default behavior
Prepare events for Conversions API coordination:
- Event Source URL - Page URL for server events
- Action Source - Always set to "website"
- Event ID - Shared with browser events for deduplication
- Server Event Time - Unix timestamp for server events
- Test Event Code - Connect to Meta Events Manager for testing
- Event Validation - Real-time event validation
- Parameter Debugging - Detailed parameter inspection
- Console Logging - Detailed console logs in debug mode
- Parameter Validation - Field-level validation and warnings
- Error Reporting - Comprehensive error handling
// GTM Data Layer Push
dataLayer.push({
'event': 'meta_purchase',
'meta_event_id': 'purchase_' + Date.now(),
'meta_value': 99.99,
'meta_currency': 'USD',
'meta_content_ids': ['SKU123', 'SKU456'],
'meta_content_type': 'product',
'meta_num_items': 2
});// GTM Data Layer Push
dataLayer.push({
'event': 'meta_lead',
'meta_event_id': 'lead_' + Date.now(),
'meta_email': 'user@example.com', // Will be SHA-256 hashed
'meta_phone': '+1234567890' // Will be SHA-256 hashed
});For server-side implementation, ensure event deduplication:
// Generate unique event ID
const eventId = 'event_' + Date.now() + '_' + Math.random();
// Send to Meta Pixel (this template handles)
dataLayer.push({
'event': 'meta_purchase',
'meta_event_id': eventId,
// ... other parameters
});// Use same event ID for deduplication
const serverEvent = {
event_name: 'Purchase',
event_id: eventId, // Same ID as client-side
action_source: 'website',
event_source_url: 'https://yoursite.com/checkout',
// ... other server parameters
};- Use standard Meta event names when possible
- Keep custom event names descriptive and consistent
- Avoid special characters in event names
- Always include
event_idfor CAPI coordination - Use consistent
content_idsformat across events - Include
valueandcurrencyfor commerce events
- Enable consent mode for EU traffic
- Configure appropriate consent behavior
- Document data collection in privacy policy
- Use Test Event Code during development
- Validate events in Meta Events Manager
- Test consent mode behavior
- Verify CAPI deduplication
Starting April 10, 2025, Google Tag Manager containers with Google Ads and Floodlight tags will automatically load a Google tag first before sending events. This may affect:
- Meta Pixel loading order
- Event timing and sequence
- Page load performance
Recommended Actions:
- Test your implementation before April 2025
- Monitor Meta Events Manager for any data discrepancies
- Consider adjusting tag firing priorities if needed
- Use the GTM Debug Mode to verify proper sequencing
The template now properly implements event deduplication for CAPI:
- Event ID is sent as the 4th parameter (
{eventID: 'id'}) to Meta Pixel - This format is required for proper browser-server deduplication
- Meta keeps browser events when duplicates are detected within 5 minutes
Validation Steps:
- Go to Meta Events Manager → Your Pixel → Select Event → View Details
- Check the deduplication percentage (typically 10-15% server events)
- Ensure browser and server event graphs look similar
- Check GTM triggers
- Verify Pixel ID format
- Review consent mode settings
- Check browser console for errors
- Verify PII data format
- Check SHA-256 hashing
- Review user data availability
- Verify consent mode setup in GTM
- Check consent state values
- Review consent listener configuration
- Ensure identical
event_idvalues - Check server-side implementation uses
event_id(noteventID) - Verify timing between client/server events (within 5 minutes)
- Confirm eventID is passed as 4th parameter in browser pixel
- Template automatically formats to E.164 standard
- US numbers: 10 digits → +1XXXXXXXXXX
- International: Include country code with +
- Remove all formatting characters (spaces, dashes, parentheses)
- Template now sends
fbq('consent', 'grant'/'revoke')commands - Check Meta Events Manager for consent status
- Verify GTM consent state with
isConsentGranted('ad_storage') - Test consent changes trigger proper Meta updates
- Template tracks initialized pixels to prevent duplicates
- Each Pixel ID only initialized once per page
- Check browser console for "Pixel already initialized" messages
- Meta Pixel Helper - Browser extension for pixel validation
- Meta Events Manager - Server-side event validation
- GTM Debug Mode - Tag firing validation
- Browser Console - Error and debug logging
- Template structure completely rebuilt
- New field naming convention
- Enhanced consent mode integration
- Updated permission requirements
- Export current tag configuration
- Install new template version
- Recreate tags using new template
- Update triggers and variables as needed
- Test thoroughly before publishing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the Apache License 2.0. See LICENSE for details.
- GitHub Issues - Report bugs and feature requests
- Documentation - This README and inline template documentation
- Meta Developer Docs - Official Meta Pixel Documentation
Just Meta - Streamlined Meta Pixel tracking for the modern web.