PHPackages                             tourze/user-track-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/user-track-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/user-track-bundle
========================

A Symfony bundle for tracking and recording user behavior across your application

1.0.2(5mo ago)018MITPHPCI passing

Since Apr 17Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/user-track-bundle)[ Packagist](https://packagist.org/packages/tourze/user-track-bundle)[ RSS](/packages/tourze-user-track-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (44)Versions (13)Used By (0)

UserTrackBundle
===============

[](#usertrackbundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/c50487843d2b3708a437d1596c505e55573c90dccb4a054e725fdba87b1975f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f757365722d747261636b2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/user-track-bundle)[![Total Downloads](https://camo.githubusercontent.com/ffd8be5470e3cc13543c18cc3273530f29db456effbcd0f491b0320cf2a8638b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f757365722d747261636b2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/user-track-bundle)[![PHP Version](https://camo.githubusercontent.com/f8925f21804573b07f1fb994e89f48d14044485ddf87db4104a7535636a3cacc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f757365722d747261636b2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/user-track-bundle)[![License](https://camo.githubusercontent.com/f983b097e846322bca902cca0ea8da7baafcd90ce56ef9110f82a597bf94a072/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f757365722d747261636b2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Code Coverage](https://camo.githubusercontent.com/7271c5e806190623066c0c9f47d08816592040cf4bd581c90fb08ebd68163c4d/68747470733a2f2f636f6465636f762e696f2f67682f746f75727a652f757365722d747261636b2d62756e646c652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/tourze/user-track-bundle)

A Symfony bundle for tracking and recording user behavior across your application. Provides automatic event tracking, manual tracking via JSON-RPC, and built-in log rotation.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Advanced Usage](#advanced-usage)
- [Configuration](#configuration)
- [JSON-RPC API Reference](#json-rpc-api-reference)
- [Use Cases](#use-cases)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [License](#license)

Features
--------

[](#features)

- **Automatic Event Tracking**: Automatically captures `UserInteractionEvent` events
- **Asynchronous Storage**: Uses async insertion to avoid impacting main business performance
- **JSON-RPC Interface**: Manual behavior tracking through RPC endpoint
- **Automatic Log Cleanup**: Built-in scheduled cleanup of expired logs (configurable retention period)
- **Customer Radar Support**: Provides data foundation for CRM customer radar functionality
- **Flexible Event Parameters**: Support for custom tracking parameters through interfaces
- **Distributed Lock Support**: Prevents duplicate submissions in distributed environments

Requirements
------------

[](#requirements)

- PHP 8.1+
- Symfony 6.4+
- tourze/user-event-bundle
- tourze/doctrine-snowflake-bundle
- tourze/doctrine-ip-bundle

Installation
------------

[](#installation)

```
composer require tourze/user-track-bundle
```

Quick Start
-----------

[](#quick-start)

### 1. Register the Bundle

[](#1-register-the-bundle)

```
// config/bundles.php
return [
    // ...
    Tourze\UserTrackBundle\UserTrackBundle::class => ['all' => true],
];
```

### 2. Automatic Event Tracking

[](#2-automatic-event-tracking)

Any `UserInteractionEvent` dispatched in your application will be automatically tracked:

```
use Tourze\UserEventBundle\Event\UserInteractionEvent;

// This event will be automatically recorded
$event = new UserInteractionEvent($sender, $systemUser, 'user.login');
$eventDispatcher->dispatch($event);
```

### 3. Manual Tracking via JSON-RPC

[](#3-manual-tracking-via-json-rpc)

```
// Frontend JavaScript
const response = await jsonRpcClient.call('SubmitCrmTrackLog', {
    event: 'page.view',
    params: {
        page: '/products/123',
        referrer: 'google.com',
        duration: 30
    }
});
// Response: { time: 1234567890 }

// Backend PHP
$result = $jsonRpcClient->call('SubmitCrmTrackLog', [
    'event' => 'order.completed',
    'params' => [
        'order_id' => '12345',
        'amount' => 99.99
    ]
]);
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Tracking Parameters

[](#custom-tracking-parameters)

Implement `TrackContextInterface` in your events to provide additional tracking parameters:

```
use Tourze\UserEventBundle\Event\UserInteractionEvent;
use Tourze\UserTrackBundle\Event\TrackContextInterface;

class ProductViewEvent extends UserInteractionEvent implements TrackContextInterface
{
    /** @var array */
    private array $trackParams = [];

    public function __construct($user, $product)
    {
        parent::__construct($user, $systemUser, 'product.view');

        $this->setTrackingParams([
            'product_id' => $product->getId(),
            'category' => $product->getCategory(),
            'price' => $product->getPrice()
        ]);
    }

    /**
     * @return array
     */
    public function getTrackingParams(): array
    {
        return $this->trackParams;
    }

    /**
     * @param array $params
     */
    public function setTrackingParams(array $params): void
    {
        $this->trackParams = $params;
    }
}
```

### Extending RPC Response

[](#extending-rpc-response)

Listen to `TrackLogReportEvent` to modify the RPC response:

```
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Tourze\UserTrackBundle\Event\TrackLogReportEvent;

class TrackLogResponseEnricher implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            TrackLogReportEvent::class => 'onTrackLogReport',
        ];
    }

    public function onTrackLogReport(TrackLogReportEvent $event)
    {
        $result = $event->getResult();
        $result['tracking_id'] = $event->getTrackLog()->getId();
        $event->setResult($result);
    }
}
```

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

```
# .env
# Number of days to keep track logs (default: 30)
CLEAN_TRACK_LOG_DAY_NUM=90
```

### Automatic Cleanup

[](#automatic-cleanup)

Logs are automatically cleaned up daily at 2:20 AM. The retention period can be configured via the `CLEAN_TRACK_LOG_DAY_NUM` environment variable.

JSON-RPC API Reference
----------------------

[](#json-rpc-api-reference)

### SubmitCrmTrackLog

[](#submitcrmtracklog)

Submit a user behavior tracking log.

**Parameters:**

- `event` (string, required): Event name (e.g., "page.view", "button.click")
- `params` (array, optional): Event parameters as key-value pairs

**Response:**

```
{
    "time": 1234567890
}
```

**Authentication:** Requires authenticated user (`IS_AUTHENTICATED`)

Use Cases
---------

[](#use-cases)

- **User Behavior Analytics**: Track page views, clicks, feature usage
- **Customer Radar**: Real-time customer activity tracking for CRM
- **Marketing Automation**: Trigger marketing campaigns based on user behavior
- **Security Auditing**: Record audit logs for sensitive operations
- **Product Optimization**: Analyze user behavior data to improve features

Testing
-------

[](#testing)

Run tests from the monorepo root:

```
# Run all tests
./vendor/bin/phpunit packages/user-track-bundle/tests

# Run specific test
./vendor/bin/phpunit packages/user-track-bundle/tests/Entity/TrackLogTest.php
```

### Test Coverage

[](#test-coverage)

- Entity tests - Complete coverage of TrackLog entity
- Event tests - TrackLogReportEvent and TrackContext interface
- Event Subscriber tests - UserTrackListener behavior
- RPC Procedure tests - SubmitCrmTrackLog endpoint
- DI Extension tests - Service registration and configuration
- Bundle tests - Bundle initialization

Security
--------

[](#security)

### Authentication

[](#authentication)

All JSON-RPC endpoints require authenticated users. User tracking data is stored with IP address information for security auditing purposes.

### Data Protection

[](#data-protection)

- User tracking data is automatically cleaned up based on configured retention period
- IP addresses are stored for security purposes and follow the same retention policy
- All user input is validated before storage

### Best Practices

[](#best-practices)

- Review tracking parameters to avoid storing sensitive information
- Use appropriate retention periods for compliance requirements
- Monitor tracking data for unusual patterns that might indicate security issues

Contributing
------------

[](#contributing)

Contributions are welcome! Please ensure:

- All tests pass
- Code follows PSR-12 standards
- New features include tests
- Documentation is updated

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance72

Regular maintenance activity

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Recently: every ~40 days

Total

12

Last Release

179d ago

Major Versions

0.1.6 → 1.0.02025-11-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-user-track-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-user-track-bundle/health.svg)](https://phpackages.com/packages/tourze-user-track-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
