@analytics-debugger/ga4mp

中文文档
0.0.8发布于 2023/06/22MITESM + CJS近 30 天下载 3253

An Open-Source Google Analytics 4 Client-Side Protocol Implementation

原始使用文档

GA4MP - Google Analytics 4 Measurement Protocol

This is an open-source implementation for the client-side protocol used by Google Analytics 4. When I mention "client-side" is because it must be differentiated with the official GA4 Measurement Protocol offered by Google.

This library implements the public Google Analytics 4 protocol to make possible to do a full server-side tracking using NODE/JS which is not actually possible with the official Measurement Protocol , which is meant only to augment the current GA4 data and it's not ready for doing a full tracking.

Main differences with the official offerser server-side protocol are:

  • Trigger new sessions and visits starts
  • Track Sessions attribution
  • Override the User IP to populate the GEO Details
  • View the hits on the DebugView
  • Override ANY value you want
  • Easily portable to other languages

If we compare this library with the official GTAG implementation.

  • Lightweight 8.7kb (<4kb compressed ) 95.6% Lighter than a GTAG Container image
  • Privacy Compliant: Full control over which cookies are created/read and sent to Google
  • Dual Tracking (send hits to multiple measurement Ids)

Usage

ES6 Imports

import  ga4mp  from  '@analytics-debugger/ga4mp'
const  ga4track = ga4mp(["G-THYNGSTER"], {
    user_id:  undefined,
    non_personalized_ads:  true,
    debug:  true
});

Browser

<.script src="https://cdn.jsdelivr.net/npm/@analytics-debugger/ga4mp@latest/dist/ga4mp.umd.min.js">< /script>

const  ga4track  =  ga4mp(["G-THYNGSTER"],  {
    user_id: undefined,
    non_personalized_ads: true,
    debug: true
});

NODE.JS

const  ga4mp = require('./dist/ga4mp')
const  ga4track = ga4mp(["G-THYNGSTER"], {
    user_id:  undefined,
    non_personalized_ads:  true,
    debug:  true
});

More API details

Read more at: https://ga4mp.dev/

版本与发布记录

@analytics-debugger/ga4mp 共发布 11 个版本,首次发布于 2022/11/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.8latest2023/06/223 年前
0.0.72023/06/223 年前
0.0.62023/06/203 年前
0.0.52023/05/243 年前
0.0.42023/04/133 年前
0.0.32023/03/063 年前

关于 @analytics-debugger/ga4mp 的常见问题

@analytics-debugger/ga4mp 是什么?

An Open-Source Google Analytics 4 Client-Side Protocol Implementation

如何安装 @analytics-debugger/ga4mp?

在项目目录运行 npm install @analytics-debugger/ga4mp,或使用 pnpm add / yarn add / bun add。

@analytics-debugger/ga4mp 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/analytics-debugger__ga4mp 是否存在。

@analytics-debugger/ga4mp 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@analytics-debugger/ga4mp 可以商用吗?

@analytics-debugger/ga4mp 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@analytics-debugger/ga4mp 的下载量有多少?

根据 npm 官方下载统计,@analytics-debugger/ga4mp 在 2026/10/06 – 2026/11/04 这 30 天内被下载 3,253 次,日均约 108 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@analytics-debugger/ga4mp 还在维护吗?

最新版本 0.0.8 发布于 2023/06/22(3 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/11/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。