stefandoorn/google-tag-manager-plugin

Sylius的Google Tag Manager插件。

安装次数: 196,028

依赖项: 2

建议者: 0

安全: 0

星标: 21

关注者: 3

分支: 13

公开问题: 3

类型:sylius-plugin


README

License Version Build

相关插件

安装

1. Composer

composer require stefandoorn/google-tag-manager-plugin

2. 加载包

添加到包列表

new GtmPlugin\GtmPlugin(),

3. 按照所需子包的安装说明进行安装(https://github.com/xyNNN/GoogleTagManagerBundle

添加到您的配置

google_tag_manager:
    enabled: true
    id: "GTM-XXXXXX"
    autoAppend: false

并配置您想使用此插件的功能

gtm:
    inject: true
    features:
        environment: true
        route: true
        context: true
        events: true

如果您将autoAppend设置为false,并且还禁用了此插件内的inject设置,您必须自行管理GTM容器的加载。

如果您将autoAppend设置为false,并将inject设置为true,请注意以下事项

将必要的输出到HTML(head、body和footer)通过事件完成。请确保以下'sonata_block_render_events'存在于您的视图中

  • sylius.shop.layout.javascripts
  • sylius.shop.layout.head
  • sylius.shop.layout.before_body
  • sylius.shop.layout.after_body

您可以使用以下方法获取默认配置

bin/console config:dump-reference GtmPlugin

5. 安装资产(可选:仅当您想使用事件功能时)

bin/console assets:install 
bin/console sylius:install:assets
bin/console sylius:theme:assets:install

功能

  • 环境:将Symfony/Sylius环境发送到GTM
  • 路由:将Symfony/Sylius路由发送到GTM
  • 上下文:将Sylius上下文信息发送到GTM(货币、区域、渠道)
  • 事件:见下文 - 允许您轻松从HTML内部使用JS注册事件。

用法

从JS注册事件

var event = new GaEvent('category');
event.register(action, label, value);

请确保在GTM配置中也监听此特定事件。