znanylekarz/google-bundle
Composer 安装命令:
composer require znanylekarz/google-bundle
包简介
The GoogleBundle adds the ability to add various google-related services to your application. These include Google Analytics, Adwords and Static Maps.
关键字:
README 文档
README
GoogleBundle
The GoogleBundle adds the ability to add various google-related services to your application. These include Google Analytics, Adwords and Static Maps.
Installation
Initialize Submodule
git submodule add git@github.com:antimattr/GoogleBundle.git src/AntiMattr/GoogleBundle
Application Kernel
Add GoogleBundle to the registerBundles() method of your application kernel:
public function registerBundles()
{
return array(
new AntiMattr\GoogleBundle\GoogleBundle(),
);
}
Configuration
Google Analytics
Application config.yml
Enable loading of the Google Analytics service by adding the following to
the application's config.yml file:
google:
analytics:
trackers:
default:
name: MyJavaScriptCompatibleVariableNameWithNoSpaces
accountId: UA-xxxx-x
domain: .mydomain.com
trackPageLoadTime: true
View
Include the Google Analytics Async template in the head tag or just before the </body> of your layout (The template will lazy load _gaq).
With twig:
{% include "GoogleBundle:Analytics:async.html.twig" %}
Features
Logging a Default Page View
Requires no additional code
Sending a Custom Page View
$this->container()->get('google.analytics')->setCustomPageView('/profile/'.$username);
Adding to Page View Queue
Note: Page View Queue is always executed before a Custom Page View
$this->container()->get('google.analytics')->enqueuePageView('/my-first-page-view-in-queue');
$this->container()->get('google.analytics')->enqueuePageView('/my-second-page-view-in-queue');
Ecommerce Tracking
$transaction = new \AntiMattr\GoogleBundle\Analytics\Transaction();
$transaction->setOrderNumber('xxxx');
$transaction->setAffiliation('Store 777');
$transaction->setTotal(100.00);
$transaction->setTax(10.00);
$transaction->setShipping(5.00);
$transaction->setCity("NYC");
$transaction->setState("NY");
$transaction->setCountry("USA");
$this->get('google.analytics')->setTransaction($transaction);
$item = new \AntiMattr\GoogleBundle\Analytics\Item();
$item->setOrderNumber('xxxx');
$item->setSku('zzzz');
$item->setName('Product X');
$item->setCategory('Category A');
$item->setPrice(50.00);
$item->setQuantity(1);
$this->get('google.analytics')->addItem($item);
$item = new \AntiMattr\GoogleBundle\Analytics\Item();
$item->setOrderNumber('bbbb');
$item->setSku('jjjj');
$item->setName('Product Y');
$item->setCategory('Category B');
$item->setPrice(25.00);
$item->setQuantity(2);
$this->get('google.analytics')->addItem($item);
Google Adwords
Application config.yml
Enable loading of the Google Adwords service by adding the following to
the applications's config.yml file:
google:
adwords:
conversions:
account_create:
id: 111111
label: accountCreateLabel
value: 0
checkout_thanks:
id: 222222
label: checkoutThanksLabel
value: 0
Controller
$this->get('google.adwords')->activateConversionByKey('account_create');
View
Include the Google Adwords tracking template like this
{% include "GoogleBundle:Adwords:track.html.twig" %}
Google Maps - Static Map
Application config.yml
Enable loading of the Google Maps Static service by adding the following to
the applications's config.yml file (The static service does NOT require an API Key):
google:
maps: ~
Controller
use AntiMattr\GoogleBundle\Maps\StaticMap;
use AntiMattr\GoogleBundle\Maps\Marker;
...
$map = new StaticMap();
$map->setId("Paul");
$map->setSize("512x512");
$marker = new Marker();
$marker->setLatitude(40.596631);
$marker->setLongitude(-73.972359);
$map->addMarker($marker);
$this->container->get('google.maps')->addMap($map);
View
Include the Google Maps in your template like this:
{% if google_maps.hasMaps() %}
{% for map in google_maps.getMaps() %}
{% autoescape false %}
{{ map.render }}
{% endautoescape %}
{% endfor %}
{% endif %}
znanylekarz/google-bundle 适用场景与选型建议
znanylekarz/google-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 168.54k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「analytics」 「google」 「adwords」 「maps」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 znanylekarz/google-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 znanylekarz/google-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 znanylekarz/google-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
AdWords PHP API Client
Google Ads API for Laravel forked from nikolajlovenhardt/laravel-google-ads
AdWords PHP API Client
Analytics chooser extensions for site settings.
Laravel wrapper for the AdWords Targeting Idea Service
Google Shopping Product Feed for PHP
统计信息
- 总下载量: 168.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04