定制 rapidez/gtm 二次开发

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

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

rapidez/gtm

Composer 安装命令:

composer require rapidez/gtm

包简介

Rapidez GTM

关键字:

README 文档

README

This Rapidez package provides 2 views with the GTM scripts, listens to events emitted by the Rapidez Core and adds ecommerce data to the datalayer.

Installation

composer require rapidez/gtm

And add your GTM ID in the .env

GTM_ID=

And finally add @include('rapidez-gtm::head') and @include('rapidez-gtm::foot') in the head and at the bottom of your layout template, most likely at: resources/views/vendor/rapidez/layouts/app.blade.php. If you haven't published the Rapidez views yet, you can publish them with:

php artisan vendor:publish --provider="Rapidez\Core\RapidezServiceProvider" --tag=views

Multistore

Just add all stores in config/rapidez/gtm.php after you've published the config with:

php artisan vendor:publish --provider="Rapidez\GTM\GTMServiceProvider" --tag=config

Where the key of the id array is the store code.

Views

If you need to change the views you can publish them with:

php artisan vendor:publish --provider="Rapidez\GTM\GTMServiceProvider" --tag=views

Purchase tracking

This package doesn't send any purchase events as it's better to send those from the backend in case a visitor blocks Analytics with a browser extension, for example with elgentos/magento2-serversideanalytics which includes a "AddGaUserId" GraphQL mutation so it's possible to push the id from Rapidez to Magento. When installed you can enable it in the .env with:

GTM_ELGENTOS=true

view_item_list event

To track the view_item_list event, you can use the v-item-list directive on your product list, for example:

v-item-list="{
    items: items,
    item_list_id: 'recommended_products',
    item_list_name: 'Recommended products',
}"

You can also track it only on intersection by adding the .intersection modifier. This defaults to 50% intersection, but can be overridden: v-item-list.intersection="{ intersection: 80, ... }"

Enhanced Conversions

To track Enhanced Conversions, we supply a seperate file you can run when you have captured the relevant user info you want to push.

for example after subscribing to the newsletter, or entering their details in the checkout. Here's an example of how you could implement it

import { setUserData } from 'Vendor/rapidez/gtm/resources/js/datalayer/google-ads.js';

window.app.$on('logged-in', () => {
    setUserData();
});

window.app.$on('checkout-credentials-saved', () => {
    setUserData();
});

Temporarily disable

If you'd like to test for example the Lighthouse scores without GTM you can disable it by added ?gtm=false to the url

Partytown

Scripts like GTM have a massive negative impact on performance and pagespeed, to remedy this scripts like Partytown have been made. Which allows you to keep your analytics but reclaim some of the performance.

Note that partytown is technically not production ready and still in beta.

Installation

  • Execute yarn add @builder.io/partytown
  • Configure Vite to copy the partytown files (however instead of dist it should go in public)
  • Make sure symfony/psr-http-message-bridge is installed, if it is not: composer require symfony/psr-http-message-bridge
  • Enable partytown for GTM by adding GTM_PARTYTOWN_ENABLE=true to your .env
  • Add /public/~partytown to your .gitignore

Additional domains and CORS

Not all domains support partytown due to their CORS settings (https://partytown.builder.io/proxying-requests) This package comes with a proxy for these domains which by default is only set up for GTM (see: config/rapidez/gtm.php) If you notice more domains giving CORS errors you can add them to the config or in a comma seperated list in your .env under GTM_PARTYTOWN_DOMAIN_WHITELIST.

Custom config

The partytown configuration is available in window.partytown so you can change the configuration by updating the configuration within <script></script> tags.

Running partytown but not for GTM

If you want to run partytown but not for GTM that's possible too by configuring GTM_PARTYTOWN_ENABLE=false and manually including the partytown view in the head.

@push('head')
    @include('rapidez-gtm::partytown.index')
@endpush

License

GNU General Public License v3. Please see License File for more information.

rapidez/gtm 适用场景与选型建议

rapidez/gtm 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 11.82k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2022 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「rapidez」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 rapidez/gtm 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 4
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2022-07-22