hk2 / marketing-analytics
Magento 2 Marketing Analytics: Google Analytics, Facebook Pixel, Product Feed & Conversion Tracking
HK2 Marketing Analytics
Overview
HK2 Marketing Analytics integrates Google Analytics 4 (GA4), Facebook (Meta) Pixel, and Google Product Feed generation into your Magento 2 store. It provides a centralized configuration panel for managing analytics and tracking settings without modifying theme templates.
Problem Statement
Magento store owners need to integrate multiple analytics and marketing tracking services to measure store performance, understand customer behavior, and optimize marketing campaigns. Manually editing templates for each service is error-prone, requires theme maintenance, and does not scale across multiple services.
Solution Approach
This module provides a unified configuration-driven integration for Google Analytics 4 and Facebook Pixel tracking. Tracking scripts are injected automatically on all frontend pages via a layout handle, with no template overrides required. A scheduled cron job generates the Google Product Feed for Merchant Center submissions.
Who is this for?
- Magento store owners who need Google Analytics 4 tracking
- Merchants running Facebook advertising campaigns
- Stores submitting product data to Google Merchant Center
- Developers who want a clean, configurable tracking solution without template modifications
Use Cases
- Track store traffic and user behavior with Google Analytics 4
- Measure Facebook ad performance with Meta Pixel PageView tracking
- Submit product catalog to Google Shopping via automated feed generation
- Manage all tracking configurations from a single admin panel
Key Features
- Google Analytics 4 Integration — Inject GA4 gtag.js with your Measurement ID on all pages
- Facebook (Meta) Pixel — Inject Facebook Pixel with automatic PageView event tracking
- Google Product Feed — Scheduled daily XML product feed generation for Google Merchant Center
- Centralized Configuration — Manage all tracking settings from a single admin panel
- Automatic Injection — Tracking scripts load automatically with no template edits
- ACL Protected — Granular admin permissions for configuration access
- Cron-Based Feed — Automated daily feed generation at 2:00 AM
System Requirements
- Magento 2.4.x (Open Source or Adobe Commerce)
- PHP 8.1, 8.2, 8.3, or 8.4
- Composer
hk2/coremodule (^1.0)
Installation
See Installation Guide for detailed instructions.
composer require hk2/module-marketing-analytics
bin/magento module:enable HK2_MarketingAnalytics
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush
Configuration
Navigate to Stores > Configuration > HK2 > Marketing Analytics in the Magento Admin Panel.
Available settings:
| Setting | Description |
|---|---|
| Enable Module | Toggle the module on/off |
| Google Analytics / GA4 Measurement ID | Your GA4 measurement ID (format: G-XXXXXXXXXX) |
| Facebook (Meta) Pixel ID | Your Facebook Pixel ID |
| Enable Google Product Feed | Enable daily product feed generation for Google Shopping |
Content Security Policy (CSP)
If you have Content Security Policy enabled in your Magento store, ensure the following external domains are whitelisted:
https://www.googletagmanager.com— Google Analyticshttps://connect.facebook.net— Facebook Pixelhttps://www.google-analytics.com— Google Analytics
Privacy & GDPR
When using Google Analytics and Facebook Pixel, ensure compliance with applicable privacy regulations:
- Configure your cookie consent mechanism before loading tracking scripts
- Update your privacy policy to disclose third-party tracking services
- Configure Google Analytics IP anonymization if required in your jurisdiction
- Provide opt-out mechanisms where required by law
For detailed usage instructions, refer to the Usage Guide.
Documentation
Known Limitations
- The Google Product Feed generation is scheduled for daily execution and cannot be triggered manually from the admin panel
- Product feed is generated as XML for Google Shopping; other feed formats are not supported
- The module requires the
hk2/coredependency for the HK2 admin tab and shared components
Contributing
Contributions are welcome. Please open an issue or pull request on the repository.
Report security vulnerabilities to [email protected] — see SECURITY.md for details.
License
This module is licensed under the Open Software License 3.0 (OSL-3.0). See LICENSE.txt.
Disclaimer
This module is provided "as is" without warranty of any kind. The authors are not responsible for any damages arising from its use. Ensure compliance with applicable laws and regulations when using tracking technologies.
1.0.0 (2026-05-11)
✨ Features
- add bug report and pull request templates for improved issue tracking (d492ef6)
- implement HK2 Marketing Analytics module with Google Analytics and Facebook Pixel integration (7e8971e)
📝 Documentation
- update README with detailed module overview, features, installation, and configuration instructions (2123f42)
Requires 3
| Package | Constraint |
|---|---|
| hk2/core | ^1.0 |
| magento/framework | ^103.0.0 |
| php | ^8.1 || ^8.2 || ^8.3 || ^8.4 |
Compatibility
Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.
Code Quality
Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.
Static analysis
Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.
PHPStan
Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.
Tests
Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.
Unit tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Integration tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Security
Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.
More from hk2
View vendorHK2 Core module - The foundational base module for all Magento 2 HK2 extensions.
Sanitizes Magento storefront search queries by removing suspicious SQL-related keywords and characters.
Magento 2 module to manage CSP whitelisted URLs
Turn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.