tourze / baidu-tongji-api-bundle
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/baidu-tongji-api-bundle
Requires
- doctrine/collections: ^2.3
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- monolog/monolog: ^3.1
- psr/log: ^3|^2|^1
- symfony/config: ^7.3
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/event-dispatcher: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-client: ^7.3
- symfony/http-client-contracts: ^3.6
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/validator: ^7.3
- symfony/yaml: ^7.3
- tourze/baidu-oauth2-integrate-bundle: 0.0.*
- tourze/bundle-dependency: 1.*
- tourze/doctrine-indexed-bundle: 1.0.*
- tourze/doctrine-timestamp-bundle: 1.1.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/symfony-dependency-service-loader: 1.0.*
Requires (Dev)
This package is auto-updated.
Last update: 2025-11-18 15:20:09 UTC
README
A Symfony bundle for integrating Baidu Tongji (Baidu Analytics) API into your application. This bundle provides comprehensive functionality to manage Baidu Tongji sites, retrieve analytics reports, and synchronize data with local storage.
Features
- Site Management: Sync and manage Baidu Tongji sites and subdirectories
- Report Retrieval: Access various types of analytics reports (trends, sources, visits, etc.)
- Data Storage: Store report data locally using Doctrine ORM entities
- CLI Commands: Convenient console commands for data synchronization
- Admin Interface: EasyAdmin integration for managing data
- OAuth2 Integration: Seamless integration with Baidu OAuth2 authentication
Requirements
- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM
tourze/baidu-oauth2-integrate-bundle- For Baidu OAuth2 authentication
Installation
Install the bundle using Composer:
composer require tourze/baidu-tongji-api-bundle
Configuration
Enable the bundle in your Symfony application:
// config/bundles.php return [ // ... Tourze\BaiduTongjiApiBundle\BaiduTongjiApiBundle::class => ['all' => true], ];
Console Commands
tongji:sync-sites
Synchronize Baidu Tongji sites for users.
Basic Usage
# Sync sites for all users php bin/console tongji:sync-sites # Sync sites for specific user php bin/console tongji:sync-sites --user-id=123 # Force sync, ignore token expiration php bin/console tongji:sync-sites --force
Options
--user-id, -u: Specific user ID to sync (syncs all users if not specified)--force, -f: Force sync, ignore token expiration check
Examples
# Sync all user sites php bin/console tongji:sync-sites # Sync specific user sites php bin/console tongji:sync-sites -u 12345 # Force sync sites and update tokens php bin/console tongji:sync-sites --force
tongji:sync-report
Synchronize Baidu Tongji analytics reports.
Basic Usage
# Sync trend report for all sites php bin/console tongji:sync-report trend/time/a --start-date=2024-01-01 --end-date=2024-01-31 # Sync report for specific site php bin/console tongji:sync-report trend/time/a --site-id=123456 --start-date=2024-01-01 --end-date=2024-01-31 # Force sync, ignore token expiration php bin/console tongji:sync-report trend/time/a --start-date=2024-01-01 --end-date=2024-01-31 --force
Parameters
Required Parameters:
method: Report method to retrieve (see table below)
Optional Parameters:
--site-id, -s: Specific site ID to sync (syncs all sites if not specified)--start-date: Start date in YYYY-MM-DD format--end-date: End date in YYYY-MM-DD format--params, -p: Additional parameters in JSON format, default:{}--force, -f: Force sync, ignore token expiration check
Available Report Methods
| Method | Description |
|---|---|
trend/time/a |
Trend Analysis |
trend/latest/a |
Real-time Visitors |
pro/product/a |
Promotion Methods |
pro/hour/a |
Baidu Promotion Trend |
source/all/a |
All Sources |
source/engine/a |
Search Engines |
source/searchword/a |
Search Words |
source/link/a |
External Links |
custom/media/a |
Custom Media Tracking |
visit/toppage/a |
Top Pages |
visit/landingpage/a |
Landing Pages |
visit/topdomain/a |
Top Domains |
visit/district/a |
Regional Distribution (China) |
visit/world/a |
World Regional Distribution |
overview/getTimeTrendRpt |
Site Overview (Trend Data) |
overview/getDistrictRpt |
Site Overview (Regional Distribution) |
overview/getCommonTrackRpt |
Site Overview (Common Tracks) |
Examples
# Sync trend report for all sites php bin/console tongji:sync-report trend/time/a --start-date=2024-01-01 --end-date=2024-01-31 # Sync search engine report for specific site php bin/console tongji:sync-report source/engine/a -s 123456 --start-date=2024-01-01 --end-date=2024-01-31 # Sync report with custom parameters php bin/console tongji:sync-report trend/time/a --start-date=2024-01-01 --end-date=2024-01-31 -p '{"gran":"day"}' # Force sync report and update tokens php bin/console tongji:sync-report trend/time/a --start-date=2024-01-01 --end-date=2024-01-31 --force
Entities
TongjiSite
Represents a Baidu Tongji site with the following properties:
siteId: Baidu site IDdomain: Site domainstatus: Site status (0: normal, 1: paused)user: Associated Baidu OAuth2 usersubDirectories: Collection of subdirectoriessiteCreateTime: Site creation timerawData: Raw API response data
TongjiSubDirectory
Represents a Baidu Tongji subdirectory with the following properties:
subDirId: Subdirectory IDsubDir: Subdirectory pathstatus: Subdirectory statussite: Associated site
FactTrafficTrend
Stores aggregated traffic trend data:
siteId: Site IDdate: Report datepageViewPv: Page views countvisitorUv: Unique visitors countipCount: IP countbounceRatio: Bounce rateavgVisitTime: Average visit time
RawTongjiReport
Stores raw report data from Baidu Tongji API:
reportMethod: Report method namesiteId: Site IDreportDate: Report daterawData: Raw JSON data from API
Services
TongjiApiClient
Core API client for communicating with Baidu Tongji API endpoints.
TongjiSiteService
Manages site synchronization and site-related operations.
TongjiReportSyncService
Handles report data synchronization and processing.
UserManagementService
Manages user-related operations and authentication.
Testing
Run the test suite:
vendor/bin/phpunit packages/baidu-tongji-api-bundle/tests/
Run static analysis:
vendor/bin/phpstan analyse packages/baidu-tongji-api-bundle/src/ --level=8
License
MIT License