hk2 / marketing-analytics

hk2/marketing-analytics

Magento 2 Marketing Analytics: Google Analytics, Facebook Pixel, Product Feed & Conversion Tracking

magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Warning Tests: N/A Security: Pass OSL-3.0

Are you the maintainer of hk2?

Packagento pulls hk2's Composer packages from the public registry so buyers can find them here.

Claim the namespace to take ownership, publish new releases directly, and start charging for premium versions.

Claim this namespace →

HK2 Marketing Analytics

Version Magento PHP License Packagist Website LinkedIn Email

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/core module (^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 Analytics
  • https://connect.facebook.net — Facebook Pixel
  • https://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/core dependency 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)
Versions
Version Stability QA Status Compatibility Released
1.0.0 stable Pass Magento 2.4.7-2.4.9 Details 2026-05-11 15:30:22

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.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

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.

Static analysis results
Tool Status Findings Summary
PHPCS Warning 15 15 warnings (ruleset: Magento2), 6 auto-fixable with phpcbf
PHPMD Warning 3 3 rule violations (UnusedPrivateField:3)
Cpd Pass 0
Composer validate Info 1 valid; 1 advisory note (composer validate --strict)

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.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

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

Unit tests results by Magento and PHP version
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

Integration tests results by Magento and PHP version
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.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0
License
OSL-3.0
Authors

More from hk2

View vendor
Make it pay

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.