# hk2/marketing-analytics

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

`composer require hk2/marketing-analytics`

Canonical URL: https://packagento.com/hk2/marketing-analytics

## At a glance

- **Vendor**: hk2 (https://packagento.com/hk2.md)
- **Latest version**: 1.0.0 — released 2026-05-11
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/hk2/marketing-analytics and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require hk2/marketing-analytics:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

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

## README

<img src="https://img.shields.io/badge/version-2.0.0-blue?style=flat-square" alt="Version">
<img src="https://img.shields.io/badge/Magento-2.4.x-f97316?style=flat-square&logo=magento&logoColor=white" alt="Magento">
<img src="https://img.shields.io/badge/PHP-8.2%2B-7c3aed?style=flat-square&logo=php&logoColor=white" alt="PHP">
<img src="https://img.shields.io/badge/license-OSL--3.0-green?style=flat-square" alt="License">

<a href="https://packagist.org/packages/hk2/module-marketing-analytics">
    <img src="https://img.shields.io/packagist/dt/hk2/module-marketing-analytics?style=flat-square" alt="Packagist">
</a>

<a href="https://www.basantmandal.in">
    <img src="https://img.shields.io/badge/Website-000?style=flat-square&logo=ko-fi&logoColor=white" alt="Website">
</a>
<a href="https://www.linkedin.com/in/basantmandal/">
    <img src="https://img.shields.io/badge/LinkedIn-0A66C2?style=flat-square&logo=linkedin&logoColor=white" alt="LinkedIn">
</a>
<a href="mailto:support@basantmandal.in">
    <img src="https://img.shields.io/badge/Email-support%40basantmandal.in-blue?style=flat-square&logo=gmail" alt="Email">
</a>

---

### 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](docs/installation.md) for detailed instructions.

```bash
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](docs/usage.md).

### Documentation

- [Installation Guide](docs/installation.md)
- [Usage Guide](docs/usage.md)
- [Compatibility](docs/compatibility.md)

### 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 [support@basantmandal.in](mailto:support@basantmandal.in) — see [SECURITY.md](SECURITY.md) for details.

### License

This module is licensed under the Open Software License 3.0 (OSL-3.0). See [LICENSE.txt](LICENSE.txt).

### Disclaimer

_(README truncated for .md surface. Full README on https://packagento.com/hk2/marketing-analytics.)_

## Changelog

#### ✨ Features

* add bug report and pull request templates for improved issue tracking ([d492ef6](https://github.com/basantmandal/magento2-marketing-analytics-module/commit/d492ef616fc11358d19a5878ed13da0acddbc3cc))
* implement HK2 Marketing Analytics module with Google Analytics and Facebook Pixel integration ([7e8971e](https://github.com/basantmandal/magento2-marketing-analytics-module/commit/7e8971e85720adc25016a4476d63b6d958768e07))

#### 📝 Documentation

* update README with detailed module overview, features, installation, and configuration instructions ([2123f42](https://github.com/basantmandal/magento2-marketing-analytics-module/commit/2123f42131e6afe259de1f55ead4e13d0bf43ac0))

## Recent Versions

| Version | Released |
|---|---|
| 1.0.0 | 2026-05-11 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| hk2/core | ^1.0 |
| magento/framework | ^103.0.0 |
| php | ^8.1 \|\| ^8.2 \|\| ^8.3 \|\| ^8.4 |

## Quality

Latest release (1.0.0) passes the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| 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. Never affect the Compatibility verdict — 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.

| 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 against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| 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 per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### 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

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["hk2/marketing-analytics"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

hk2 is a Magento 2 vendor on Packagento. See https://packagento.com/hk2.md for their full catalogue.

