dmitrykazak / magento-google-tag-manager
Magento 2 的 Google Tag Manager (GTM) 扩展
1.1.0
2020-01-08 21:46 UTC
Requires
- php: ~7.2.0|~7.3.0
This package is auto-updated.
Last update: 2024-09-29 06:25:40 UTC
README
GTM 扩展用于 Magento 2。GTM 允许您快速轻松地更新跟踪代码和相关代码片段,以帮助管理电子营销标签的生命周期。
安装
通过 Composer 步骤安装 Magento 2 扩展
-
定位您的 Magento 2 项目根目录。
-
使用 Composer 安装 Magento 2 扩展
composer require dmitrykazak/magento-google-tag-manager
- 安装完成后扩展
# Enable the extension and clear static view files $ bin/magento module:enable DK_GoogleTagManager --clear-static-content # Update the database schema and data $ bin/magento setup:upgrade # Recompile your Magento project $ bin/magento setup:di:compile # Clean the cache $ bin/magento cache:flush
手动(不推荐)
- 下载所需版本的扩展
- 解压缩文件
- 创建文件夹
{root}/app/code/DK/GoogleTagManager
- 将此文件夹中的文件复制过来
Magento Google Tag Manager 功能
- 测量产品印象
- 测量产品点击
- 测量产品详情查看
- 测量购物车添加或删除
- 测量结账
- 测量结账选项
- 测量购买
通用配置
- 登录到 Magento 管理员,
配置 > 销售 > Google API > Google Tag Manager.
- 输入您的 GTM 账号
- 在 Google Tag Manager 中设置标签、触发器和变量
数据层
- 产品印象
{ "ecommerce": { "currencyCoce": "USD", "impressions": [ { "id": "WT09", "name": "Breathe-Easy Tank", "price": "34.0000", "category": "Bras & Tanks", "brand": "Breathe-Easy Tank", "path": "Bras & Tanks/Women Sale/Erin Recommends/Default Category", "list": "Search Results", "position": 1 }, { "id": "WT09", "name": "Breathe-Easy", "price": "31.0000", "category": "Bras & Tanks", "brand": "Breathe-Easy Tank", "path": "Bras & Tanks/Women Sale/Erin Recommends/Default Category", "list": "Search Results", "position": 2 } ] } }
- 产品点击
{ "event": "productClick", "ecommerce": { "click": { "actionField": { "list": "Search Results" } }, "products": [ { "id": "WT09", "name": "Breathe-Easy Tank", "price": "34.0000", "category": "Bras & Tanks", "brand": "Breathe-Easy Tank", "path": "Bras & Tanks/Women Sale/Erin Recommends/Default Category", "list": "Search Results", "position": 1 } ] } }
- 产品详情
{ "ecommerce": { "detail": { "actionField": { "list": "Bras" } }, "products": [ { "id": "WT09", "name": "Breathe-Easy Tank", "price": "34.0000", "category": "Bras & Tanks", "brand": "Breathe-Easy Tank", "path": "Bras & Tanks/Women Sale/Erin Recommends/Default Category" } ] } }
- 添加到购物车
{ "event": "addToCart", "ecommerce": { "add": { "products": [ { "id": "WT09", "name": "Breathe-Easy Tank", "price": "34.0000", "quantity": 1, "category": "Bras & Tanks", "brand": "Breathe-Easy Tank", "path": "Bras & Tanks/Women Sale/Erin Recommends/Default Category", "variant": "Color:Red | Size:X" } ] } } }
- 从购物车中删除
{ "event": "removeFromCart", "ecommerce": { "remove": { "products": [ { "id": "WT11", "name": "Breathe-Easy Tank", "price": "69.0000", "quantity": 1, "category": "Bras & Tanks", "brand": "Breathe-Easy Tank", "path": "Bras & Tanks/Women Sale/Erin Recommends/Default Category", "variant": "Color:Red | Size:X" } ] } } }
- 结账
{ "event": "checkout", "ecommerce": { "currencyCode": "USD", "checkout": { "actionField": { "step": 1, "option": "cart" }, "products": [ { "id": "WT09", "name": "Breathe-Easy Tank", "price": "34.0000", "category": "Bras & Tanks", "brand": "Breathe-Easy Tank", "path": "Bras & Tanks/Women Sale/Erin Recommends/Default Category", "variant": "Color:Red | Size:X" } ] } } }
- 结账选项
{ "event": "checkout", "ecommerce": { "checkout": { "actionField": { "step": 3, "option": "Flat Rate - Fixed" } } } }
- 购买
{ "event": "purchase", "ecommerce": { "currencyCode": "USD", "purchase": { "actionField": { "id": "000000033", "affiliation": "Main Website Store", "revenue": "82", "tax": "0", "shipping": "5.0000", "coupon": "NEW" }, "products": [ { "id": "WT06", "name": "Breathe-Easy Tank", "price": "77.0000", "quantity": "1.0000", "category": "Bras & Tanks", "brand": "Breathe-Easy Tank", "path": "Bras & Tanks/Women Sale/Erin Recommends/Default Category", "variant": "Color:Red | Size:X" } ] } } }
支持
如果您遇到任何问题或错误,请打开 GitHub 上的 问题。
定制
如果您想为产品 dto 添加额外的字段
- 在 di.xml 中添加新的 DataProvider
<type name="DK\GoogleTagManager\Model\DataLayer\DataProvider\DataProviderList"> <arguments> <argument name="dataProviders" xsi:type="array"> <item name="DK\GoogleTagManager\Model\DataLayer\Dto\Product" xsi:type="array"> <item name="category-id" xsi:type="object">DK\GoogleTagManager\Model\DataLayer\DataProvider\CategoryId</item> </item> </argument> </arguments> </type>
- 为字段添加自定义 DataProvider
declare(strict_types=1); namespace DK\GoogleTagManager\Model\DataLayer\DataProvider; class CategoryId implements DataProviderInterface { public function getData(array $params = []): array { return [ 'categoryId' => 1, ]; } }