wearerequired/required-google-analytics 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

wearerequired/required-google-analytics

Composer 安装命令:

composer require wearerequired/required-google-analytics

包简介

WordPress plugin to add Google's global site tag (gtag.js) to your site, the modern way.

README 文档

README

A lightweight WordPress plugin to add Google's global site tag (gtag.js) to your site, the modern way.

The modern way? The script is added with support for preloading, which will provide a small performance boost on modern browsers.
Modern browsers are those that support the async script attribute. This does not include IE 9 and older mobile browsers.

You can use this plugin with Universal Analytics or Google Analytics 4 properties or, to help ease the transition period, dual tagging is also supported.

Beside that, the plugin doesn't do more. No fancy report view in your admin, no authentication requirements, no additional scripts, and no ads for random blog posts.

Installation

Install via Composer

$ composer require wearerequired/required-google-analytics

Add you property ID at Settings > Reading > Google Analytics.

Disable Analytics for opted-out users

The plugin provides a function to let users opt out of Google Analytics measurement. If the function window.requiredGADoOptOut() is called a ga-opted-out item is stored in the local browser storage and the window property window['ga-disable-PROPERTY_ID'] will be set to true.

Example:

<a href="#" onclick="requiredGADoOptOut();return false">Opt-out from Google Analytics for this site.</a>

Event Tracking for Universal Analytics

The plugin provides a small layer that transform data attributes on an HTML element to a Google Analytics event. To enable the layer use the following filter:

add_filter( 'required_ga.enable_event_tracking', '__return_true' );

To track the click event of a button you can now use the following data attributes:

  • data-ga-event-action: Event action.
  • data-ga-event-on: Optional. Event trigger. Defaults to click and can be any DOM event.
  • data-ga-event-category: Optional. Event category.
  • data-ga-event-label: Optional. Event label.
  • data-ga-event-value: Optional. Event value.

Example usage:

<button data-ga-event-action="xyz">Click me!</button>

<button data-ga-event-action="play_video" data-ga-event-category="engagement">Click me!</button>

Additional Config Info

To configure custom dimensions and metrics you can use the required_ga.additional_config_info filter. By default the forceSSL and anonymizeIp fields are set to true.

Example usage:

add_filter( 'required_ga.enable_event_tracking', function( $config ) {
	$config['custom_map'] = [
		'dimension1' => 'author',
	];

	if ( is_singular( 'post' ) ) {
		$config['author'] = get_the_author_meta( 'display_name', get_post()->post_author )
	}

	return $config;
} );

Support for analytics.js (Universal Analytics)

Starting with version 2.0 the plugin enqueues gtag.js. If you need support for analytics.js you can continue using the 1.x branch.

$ composer require wearerequired/required-google-analytics:"^1.0"

wearerequired/required-google-analytics 适用场景与选型建议

wearerequired/required-google-analytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.69k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2018 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 wearerequired/required-google-analytics 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 13.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2018-06-11