定制 taggrs/magento2-data-layer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

taggrs/magento2-data-layer

Composer 安装命令:

composer require taggrs/magento2-data-layer

包简介

This extension collect eccommerce data from Magento 2 and pushes it to the Google Tag Manager DataLayer.

README 文档

README

This extension collect eccommerce data from Magento 2 and pushes it to the Google Tag Manager DataLayer.

Installation

Set your Magento store to maintenance mode.

bin/magento maintenance:enable

Install the extension via composer.

composer require taggrs/magento2-data-layer

Enable module and perform database upgrade.

bin/magento setup:upgrage

Perform dependency-injection compilation.

bin/magento setup:di:compile

Deploy static content.

bin/magento setup:static-content:deploy

Disable maintenance mode.

bin/magento maintenance:disable

Configuration

The configuration for this extension is located at

Stores > Configuration > TAGGRS > Data Layer

Google Tag Manager Settings

This tab is to configure GTM.

  1. Google Tag Manager Code enter your GTM- tracking code.
  2. Measurements API secret enter your Google Measurements API secret.
  3. Subdomain for Enhanced Tracking Script enter your subdomain for enhanced tracking.

Events

Per-event settings to enable or disable measuring

Events

The events that are currently captured are:

  • view_item_list
  • view_item
  • add_to_cart
  • remove_from_cart
  • view_cart
  • select_promotion
  • begin_checkout
  • purchase

view_item_list

This event is triggered on the Catalog Category pages and the Catalog Search Result page. In both cases the DataLayer is rendered in the backend.

Because of the Full Page Cache (FPC) it is necessary to retrieve the user_data part via AJAX before pushing it to the DataLayer global.

The block for rendering the Catalog Category Datalayer is Taggrs\DataLayer\Block\Event\CategoryViewItemList.

The block for rendering the Catalog Search Results DataLayer is Taggrs\DataLayer\Block\Event\SearchResultsViewItemList.

view_item

This event is triggered on the Catalog Product Page. This DataLayer is rendered in the backend.

Because of the FPC it is necessary to retrieve the user_data part via AJAX before pushing it to the DataLayer global.

The block for rendering the DataLayer is Taggrs\DataLayer\Block\Event\ViewItem.

add_to_cart

This event is triggered when a product is added to the cart. Because adding a product to the cart is an AJAX event in Magento 2, it is necessary to render the DataLayer via an AJAX event.

The DataLayer is rendered in the following frontend controller: Taggrs\DataLayer\Controller\AddToCart\Index.

remove_from_cart

This event is triggered when a product is removed from the cart. It can happen from the Minicart, or from the Checkout Cart page.

Minicart

Because removing a product from the cart is an AJAX event in Magento 2, it is necessary to render the DataLayer via AJAX.

Because it's impossible to retrieve information about a product that is removed from the cart, it is necessary to have the information about the cart readily available in the frontend.

This data is rendered in Taggrs\DataLayer\Controller\GetQuoteData\Index.

The DataLayer is built and pushed to the DataLayer global in Taggrs/DataLayer/view/frontend/web/js/checkout-sidebar-mixin.js.

Checkout Cart

Because there's a redirect after removing a product from the cart it's needed to render the DataLayer in the backend and store it in the session to show it in the frontend.

The DataLayer is built in Taggrs\DataLayer\Plugin\RemoveFromCart. Which is registered as a plugin for Magento\Checkout\Controller\Cart\Delete::beforeExecute().

It's then stored in the session and after the redirect it's retrieved from the session and rendered by Taggrs\DataLayer\Block\SessionDataLayer.

view_cart

This event is triggered on the Checkout Cart page. Because the checkout pages aren't cached in the FPC it's not necessary to load the user data via AJAX.

The DataLayer is rendered in Taggrs\DataLayer\Block\Event\ViewCart.

view_cart is also triggered via AJAX if the header mini cart is opened. The AJAX DataLayer is rendered in Taggrs\DataLayer\Controller\ViewCart\Index.

select_promotion

This event is triggered when a customer applies a discount code. This can be on the Checkout Cart page or on the Checkout Payment page.

Checkout Cart page

Because there's a redirect after applying a coupon, it's needed to render the DataLayer in the backend and store it in the session to show it in the frontend, just like the remove_from_cart event on the Checkout Cart page.

The DataLayer is built in Taggrs\DataLayer\Plugin\SelectPromotion.

Checkout Payment page

Because applying a coupon on the Checkout Payment page is an AJAX event, the DataLayer needs to be rendered via AJAX too.

The DataLayer is built in Taggrs\DataLayer\Controller\SelectPromotion\Index.

begin_checkout

This event is triggered on the Checkout Index page. This DataLayer is rendered in the backend in Taggrs\DataLayer\Block\Event\BeginCheckout.

add_shipping_info

This event is triggered on the Checkout Index page when a logged in customer selects his shipping address, or when a guest customer enters the postcode.

The DataLayer is rendered in Taggrs\Datalayer\Controller\AddShippingInfo\Index.

add_payment_info

This event is triggered on the Checkout Index page when a customer selects a payment method.

The DataLayer is rendered in Taggrs\Datalayer\Controller\AddPaymentInfo\Index.

purchase

This event is triggered on the Checkout Thank You page. Because in some cases customers will not see the Checkout Thank You page, it's also needed to push the DataLayer from the backend using the Google Measurements API.

Checkout Thank You page

This DataLayer is rendered in the backend using Taggrs\DataLayer\Block\Event\Purchase.

taggrs/magento2-data-layer 适用场景与选型建议

taggrs/magento2-data-layer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.13k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2024 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 taggrs/magento2-data-layer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 taggrs/magento2-data-layer 我们能提供哪些服务?
定制开发 / 二次开发

基于 taggrs/magento2-data-layer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 23.13k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 14
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-05-29