lsoft / ad-bundle
v1.6.0
2017-03-10 08:18 UTC
Requires
- sonata-project/admin-bundle: ^3.9
- symfony/symfony: ~2.8
README
用于sonata admin的广告小部件。
安装
步骤1: 使用composer下载LsoftAdBundle
在composer.json中添加NotificationBundle
{
"require": {
"lsoft/ad-bundle": "dev-master",
}
}
现在更新composer。
Composer将把bundle安装到项目的vendor/lsoft
目录中。
步骤2: 启用bundle
在kernel中启用bundle
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new LSoft\AdBundle\LSoftAdBundle(),
);
}
步骤3: 启用admin服务
在config.yml中配置bundle
# app/config/config.yml
doctrine:
# ...
orm:
# ...
result_cache_driver: apc
# ...
l_soft_ad:
pattern: pattern of apc cache (string)
lifetime: apc cache lifetime (seconds)
步骤4: 更新数据库
在twig中启用bundle
$ php app/console doctrine:schema:update --force
步骤5: 使用sonata admin创建广告
打开sonata admin,找到LSoft Ad组并创建广告、域名和广告提供者。域名是您页面的名称,区域是广告的位置
步骤6: 在twig中启用
在twig中启用bundle
# MyBundle/Resources/views/myTwig.html.twig
{{ render(controller('LSoftAdBundle:Default:index', { 'domain': 'domain', 'zone': 'top' })) }}
启用分析
步骤1: 创建google分析账户
http://www.google.com/analytics
步骤2: 添加google分析客户端ID和视图ID
# app/config/parameters.yml
parameters:
# ....
google_analytics_account_id: UA-XXXXXXXX-X # [a link](https://support.google.com/analytics/answer/1032385?hl=en)
google_analytics_web_client_id: (google analytics web client id token) # [a link](https://console.developers.google.com/apis/credentials)
google_analytics_view_id: xxxxxxxxx,
步骤3: 启用admin服务
在config.yml中配置bundle
# app/config/config.yml
# Twig Configuration
twig:
# ...
globals:
google_analytics_account_id: %google_analytics_account_id%
l_soft_ad:
# ...
analytics: analytics calculate lifetime (seconds)
步骤4: 在基础布局twig中启用
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//#/analytics.js','ga');
ga('create', '{{ google_analytics_account_id }}', 'auto');
ga('require', 'displayfeatures');
{% if app.session.get('adData') %}
{% set analytics = app.session.get('adData') %}
{% for analytic in analytics %}
{% if analytic.index %}
ga('set', 'dimension{{ analytic.index }}', '{{ analytic.domain }}');
{% endif %}
{% endfor %}
{% endif %}
ga('send', 'pageview');
{{ app.session.set('adData', null) }}
</script>
在管理仪表板中启用文件
步骤1: 创建google分析账户
创建web/uploads/l_soft_ad_images目录
步骤2: 启用表单twig小部件
# app/config/config.yml
twig:
# ....
form:
resources: ['LSoftAdBundle:Form:ad_file.html.twig']
# ....
步骤3: 启用bundle路由
在routing.yml中配置bundle
# app/config/routing.yml
# ...
lsoft_ads:
resource: "@LSoftAdBundle/Controller/"
type: annotation
prefix: /
# ...