tourze / wechat-mini-program-stats-bundle
微信小程序数据统计和分析bundle,提供用户访问、性能指标、留存分析等统计功能
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/wechat-mini-program-stats-bundle
Requires
- php: ^8.1
- doctrine/collections: ^2.3
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- monolog/monolog: ^3.1
- nesbot/carbon: ^2.72 || ^3
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/event-dispatcher-contracts: ^2.5 | ^3
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/security-core: ^6.4
- symfony/serializer: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/arrayable: 0.0.*
- tourze/doctrine-snowflake-bundle: 0.1.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/doctrine-upsert-bundle: 0.1.*
- tourze/enum-extra: 0.1.*
- tourze/json-rpc-cache-bundle: 0.1.*
- tourze/json-rpc-core: 0.0.*
- tourze/json-rpc-log-bundle: 0.1.*
- tourze/symfony-cron-job-bundle: 0.1.*
- tourze/symfony-lock-command-bundle: 0.0.*
- tourze/wechat-mini-program-bundle: 0.1.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-11-01 19:31:20 UTC
README
This bundle provides comprehensive statistics collection and analysis for WeChat Mini Programs using the WeChat official API.
Table of Contents
- Installation
- Requirements
- Features
- Configuration
- Quick Start
- Available Commands
- JSON-RPC Procedures
- Entity Overview
- Usage Examples
- Advanced Usage
- Testing
- Security
- Contributing
- Changelog
- License
Installation
composer require tourze/wechat-mini-program-stats-bundle
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
- WeChat Mini Program API access
Features
- Data Collection: Automated collection of WeChat Mini Program statistics data
- Visit Analysis: Daily, weekly, and monthly visit trend analysis
- Performance Monitoring: Performance data collection and analysis
- User Analytics: User portrait and access behavior analysis
- Retention Analysis: User retention tracking and analysis
- Scheduled Tasks: Automated data collection via cron jobs
Configuration
1. Enable the Bundle
Add the bundle to your config/bundles.php:
return [ // ... WechatMiniProgramStatsBundle\WechatMiniProgramStatsBundle::class => ['all' => true], ];
2. Configure Database
Run the migrations to create the required tables:
php bin/console doctrine:migrations:migrate
3. WeChat API Configuration
Ensure you have configured the WeChat Mini Program API credentials in your main application configuration.
Quick Start
Set Up Cron Jobs
The bundle includes automated data collection commands that can be scheduled:
# Daily statistics collection php bin/console wechat-mini-program:get-daily-summary php bin/console wechat-mini-program:get-daily-visit-trend php bin/console wechat-mini-program:get-daily-retain # Weekly and monthly trends php bin/console wechat-mini-program:get-weekly-visit-trend php bin/console wechat-mini-program:get-monthly-visit-trend # Performance monitoring php bin/console wechat-mini-program:performance-data:get php bin/console wechat-mini-program:operation-performance:sync
Available Commands
Data Collection Commands
wechat-mini-program:get-daily-summary- Collect daily summary statisticswechat-mini-program:get-daily-visit-trend- Collect daily visit trend datawechat-mini-program:get-weekly-visit-trend- Collect weekly visit trend datawechat-mini-program:get-monthly-visit-trend- Collect monthly visit trend datawechat-mini-program:get-daily-retain- Collect daily retention data
User Analytics Commands
wechat-mini-program:user-portrait:get- Collect user portrait datawechat-mini-program:user-accesses:week-data:get- Collect weekly user access datawechat-mini-program:user-accesses:month-data:get- Collect monthly user access datawechat-mini-program:visit-distribution:get- Collect visit distribution data
Performance Commands
wechat-mini-program:performance-data:get- Collect performance datawechat-mini-program:operation-performance:sync- Sync operation performance datawechat-mini-program:check-performance- Check performance metrics
Page Analytics Commands
wechat-mini-program:get-wechat-user-access-page-data- Collect page access datawechat-mini-program:count-daily-page-visit-data- Count daily page visitswechat-mini-program:count-daily-new-user-visit-data- Count daily new user visitswechat-mini-program:count-wechat-hour-visit-data- Count hourly visit data
JSON-RPC Procedures
The bundle provides several JSON-RPC procedures for accessing statistics data:
Visit Trend Procedures
GetWechatMiniProgramDailyVisitTrendData- Get daily visit trend dataGetWechatMiniProgramDailyVisitTrendDataByDateRange- Get daily visit trend data by date rangeGetWechatMiniProgramDailyVisitTrendDataTotalByDateRange- Get aggregated daily visit trend dataGetWechatMiniProgramVisitTotalUser- Get total visit usersGetWechatMiniProgramVisitUvAverage- Get average unique visitors
User Analytics Procedures
GetWechatMiniProgramUserPortraitAge- Get user age demographicsGetWechatMiniProgramUserPortraitGender- Get user gender demographicsGetWechatMiniProgramUserPortraitGenderByDateRange- Get user gender demographics by date rangeGetWechatMiniProgramUserPortraitProvince- Get user province distribution
Page & Retention Procedures
GetWechatMiniProgramPageVisitTotalDataByDate- Get page visit data by specific dateGetWechatMiniProgramPageVisitTotalDataByDateRange- Get page visit data by date rangeGetWechatMiniProgramRetainUserByDate- Get user retention data by dateGetWechatMiniProgramNewUserVisitByDate- Get new user visits by date
Entity Overview
The bundle provides the following entities for data storage:
- DailyPageVisitData: Daily page visit statistics
- MonthlyVisitTrend: Monthly visit trend data
- WeeklyVisitTrend: Weekly visit trend data
- Performance: Performance monitoring data
- PerformanceAttribute: Performance attribute details
- OperationPerformance: Operation performance metrics
Usage Examples
Collecting Daily Statistics
use Symfony\Component\Console\Application; use WechatMiniProgramStatsBundle\Command\DataCube\GetDailySummaryCommand; // Run daily summary collection $application = new Application(); $command = $container->get(GetDailySummaryCommand::class); $application->add($command); $application->run();
Accessing Statistics Data
use WechatMiniProgramStatsBundle\Repository\DailyPageVisitDataRepository; // Get daily page visit data $repository = $entityManager->getRepository(DailyPageVisitData::class); $data = $repository->findBy(['date' => new \DateTime('2024-01-01')]);
Advanced Usage
Custom Data Processing
You can extend the bundle's functionality by creating custom commands or services that utilize the existing repositories and entities. The bundle is designed to be flexible and extensible.
Performance Monitoring
The bundle includes comprehensive performance monitoring capabilities that can help you track and optimize your WeChat Mini Program's performance metrics.
Testing
This bundle includes comprehensive test coverage with both unit and integration tests.
Running Tests
# Run all tests ./vendor/bin/phpunit packages/wechat-mini-program-stats-bundle/tests # Run tests with coverage php -d memory_limit=2G ./vendor/bin/phpunit packages/wechat-mini-program-stats-bundle/tests --coverage-html coverage # Run PHPStan analysis php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/wechat-mini-program-stats-bundle
Test Structure
- Unit Tests: Entity and Enum tests that verify basic functionality
- Integration Tests: Repository and Service tests that require database connection
- Command Tests: Console command tests for data collection functionality
All tests follow the PSR standards and include comprehensive assertions for both happy path and edge cases.
Security
- API Security: All WeChat API communications are secured with proper authentication
- Data Validation: Input data is validated before processing and storage
- SQL Injection Prevention: All database queries use parameterized statements
- Access Control: Commands and services respect application security policies
If you discover any security vulnerabilities, please report them via GitHub Issues.
Contributing
We welcome contributions! Here's how you can help:
Reporting Issues
- Use GitHub Issues to report bugs
- Include PHP version, Symfony version, and detailed error messages
- Provide minimal code examples that reproduce the issue
Submitting Pull Requests
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Make your changes with appropriate tests
- Ensure all tests pass:
./vendor/bin/phpunit packages/wechat-mini-program-stats-bundle/tests - Run PHPStan analysis:
php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/wechat-mini-program-stats-bundle - Submit a pull request with clear description
Code Standards
- Follow PSR-12 coding standards
- Write comprehensive tests for new features
- Update documentation for any new functionality
- Use meaningful commit messages
Changelog
Version 0.1.x
- Initial release with core statistics collection functionality
- Support for daily, weekly, and monthly visit trend analysis
- User portrait and behavior analytics
- Performance monitoring capabilities
- Comprehensive JSON-RPC API procedures
License
This bundle is released under the MIT license. See the included LICENSE file for more information.