strego/google-bundle

用于使用通用分析Google API的包

安装: 43

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 1

类型:symfony-bundle

dev-master 2014-06-23 16:41 UTC

This package is not auto-updated.

Last update: 2024-09-24 07:01:37 UTC


README

此项目基于AntiMattr/GoogleBundle原始项目。它仅用于使用通用分析API进行分析

安装

应用程序内核

将GoogleBundle添加到应用程序内核的registerBundles()方法中

public function registerBundles()
{
    return array(
        new Strego\GoogleBundle\StregoGoogleBundle(),
    );
}

配置

Google Analytics

应用程序config.yml

通过向应用程序的config.yml文件中添加以下内容来启用Google Analytics服务的加载

    strego_google:
        default_tracker: default
        trackers:
            default:
                accountId: xXxxXx
                cookieDomain: .example.com

完整配置参考

    strego_google:
        default_tracker: default
        trackers:
            default:
                accountId: xXxxXx
                cookieDomain: .example.com
                allowHash: false
                allowLinker: true
                trackPageLoadTime: false

视图

head标签中包含Google Analytics异步模板,或者在布局的</body>标签之前(模板将懒加载ga)

使用twig

{% include "StregoGoogleBundle:Analytics:async.html.twig" %}

用法

手动触发页面视图

通过以下方式在你的控制器中获取分析服务:

$analytics = $this->get('strego_google');

// To add just a pageview:
$analytics->addPageView('/testPage');

//To add a Pageview with a specific title
$analytics->addPageView('/testPage2', 'testPage2Title);