rz / google-api-client-bundle
此包已被废弃,不再维护。未建议替换包。
PHP的Google API客户端库的Symfony2包装器
dev-master / 2.0.0.x-dev
2016-07-30 15:40 UTC
Requires
- php: >=5.3.2
- google/apiclient: 2.*
- symfony/framework-bundle: 2.*|~3.0
- symfony/yaml: 2.*|~3.0
Requires (Dev)
Suggests
- rz/block-bundle: 2.0.0.*
This package is not auto-updated.
Last update: 2023-11-25 13:29:55 UTC
README
GoogleBundle允许您将各种Google服务添加到您的应用程序中。目前实现:Google Analytics、Google Tag Manager和客户端API
稳定版本
安装
将以下内容添加到您的composer.json文件中
{ "require": { "rz/google-api-client-bundle" : "1.0.*" } }
通过运行安装库
composer install
如果一切正常,Google Bundle现在可以在vendor/rz/google-api-client-bundle找到。
最后,请确保在AppKernel.php中启用此包,包括以下内容
// app/AppKernel.php public function registerBundles() { $bundles = array( //... new Rz\GoogleAPIClientBundle\RzGoogleAPIClientBundle(), ); }
配置
Google Analytics
rz_google_api_client: settings: google_services: ################ # Sample Analytics Code replace with you own tracking code ################ analytics: enabled: true tracking_id: UA-XXXXXXXX-X tracker_name: __rz_gaTracker ################ # Sample GTM Code replace with you own tracking code ################ tag_manager: enabled: true gtm_id: GTM-XXXXXX ################ # Google Client API ################ client_api: ################ # Google Client API Public API ################ public: app_name: rz-cms-XXXXXX api_key: ~ site_name: rz-cms ################ # Google Client API Service Account ################ service: app_name: ~ client_id: ~ client_email: ~ certificate_fingerprint: ~ certificate_key: %kernel.root_dir%/config/rmzamora/rz/google_api_key/YOUR_KEY_HERE.json certificate_p12: %kernel.root_dir%/config/rmzamora/rz/google_api_key/YOUR_KEY_HERE.p12 certificate_password: XXXXXXXX ################ # Google Client API Web Application ################ web_app: client_id: ~ client_secret: ~
视图Twig助手
google analytics跟踪代码
{{ rz_google_analytics_tracking_code() }}
google analytics事件,例如:pageview
{{ rz_google_analytics_page_view() }}
google analytics自定义事件,例如:pageview带有参数
{{ rz_google_analytics_page_view_custom({'page': /MY_PAGE_URL}) }}
google analytics仪表板需要RzBlockBundle和RzAdminBundle
{{ rz_google_service_analytics_embed_api() }} //embed code required to use Analytics EmbedAPI
# SHOW YOUR SITE ANALYTICS on YOUR SonataAdmin Dashbaord - sonata_admin.yml
dashboard:
blocks:
- { position: top, type: rz_google_api_client.block.admin_ga_site_traffic, settings: { mode: admin, title: Google Analytics } }
# Register Block under sonata_block.yml
rz_google_api_client.block.admin_ga_site_traffic:
contexts: [admin]
截图
返回:rzproject