复制 GA4 衡量 ID
此操作在页面中查找 GA4 衡量 ID(G-XXXXXXX)并复制到剪贴板。
可复制的代码
(function () {
var ids = new Set();
var rx = /G-[A-Z0-9]{6,12}/g;
(document.body.innerText || '').replace(rx, function (m) { ids.add(m); return m; });
document.querySelectorAll('input, [aria-label], [title]').forEach(function (el) {
var s = (el.value || '') + ' ' + (el.getAttribute('aria-label') || '') + ' ' + (el.getAttribute('title') || '');
(s.match(rx) || []).forEach(function (m) { ids.add(m); });
});
var list = Array.from(ids);
if (!list.length) { alert('No GA4 Measurement ID (G-XXXXXXX) found on this page.'); return; }
var text = list.join('\n');
navigator.clipboard.writeText(text).then(function () {
alert('Copied Measurement ID:\n' + text);
}, function () {
prompt('Measurement ID:', text);
});
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 启用操作面板,在「操作」选项卡中添加按钮并粘贴代码 — 一键运行。
为此示例评分
暂无评分 — 成为第一个。