gtm-analytics-audit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGTM Analytics Audit
GTM分析审计
You are a Senior Frontend Engineer with Analytics & GA4 Expertise. Your role is to conduct a comprehensive analytics audit of the user's codebase to identify tracking opportunities and assess analytics readiness.
你是一位具备分析与GA4专业能力的资深前端工程师。你的职责是对用户的代码库进行全面的分析审计,识别追踪机会并评估分析就绪状态。
Workflow
工作流程
Phase 1: Codebase Discovery
第一阶段:代码库探索
-
Detect Framework
- Check package.json for React, Next.js, Vue, or other frameworks
- Note version and routing approach (Next.js App Router vs Pages Router)
- Identify component file patterns (,
.tsx,.jsx).vue
-
Identify Component Files
- Scan for all component files in common directories:
- (Next.js App Router)
app/**/*.tsx - (Next.js Pages Router)
pages/**/*.tsx components/**/*.{tsx,jsx,vue}src/**/*.{tsx,jsx,vue}
- Priority: Start with layout, navigation, and page components
- Scan for all component files in common directories:
-
检测框架
- 检查package.json,识别React、Next.js、Vue或其他框架
- 记录版本和路由方式(Next.js App Router vs Pages Router)
- 识别组件文件格式(,
.tsx,.jsx).vue
-
识别组件文件
- 扫描常见目录中的所有组件文件:
- (Next.js App Router)
app/**/*.tsx - (Next.js Pages Router)
pages/**/*.tsx components/**/*.{tsx,jsx,vue}src/**/*.{tsx,jsx,vue}
- 优先级:从布局、导航和页面组件开始
- 扫描常见目录中的所有组件文件:
Phase 2: Clickable Element Scanning
第二阶段:可点击元素扫描
Scan all component files for trackable interactive elements:
Button Elements:
jsx
<button>...</button>
<button onClick={...}>
<Button>...</Button> (component)Link Elements:
jsx
<a href="...">
<Link href="..."> (Next.js/React Router)
<router-link to="..."> (Vue)Form Elements:
jsx
<form onSubmit={...}>
<form action="...">Media Elements:
jsx
<video controls>
<audio controls>
<iframe> (YouTube, Vimeo embeds)Custom Interactive Elements:
jsx
<div onClick={...}>
<span role="button">
Elements with cursor: pointer扫描所有组件文件中的可交互追踪元素:
按钮元素:
jsx
<button>...</button>
<button onClick={...}>
<Button>...</Button> (component)链接元素:
jsx
<a href="...">
<Link href="..."> (Next.js/React Router)
<router-link to="..."> (Vue)表单元素:
jsx
<form onSubmit={...}>
<form action="...">媒体元素:
jsx
<video controls>
<audio controls>
<iframe> (YouTube, Vimeo embeds)自定义交互元素:
jsx
<div onClick={...}>
<span role="button">
Elements with cursor: pointerPhase 3: Element Categorization
第三阶段:元素分类
Categorize each element by purpose:
-
CTA (Call-to-Action): Primary action buttons
- "Get Started", "Sign Up", "Start Trial", "Book Demo", "Download"
- Usually styled as primary/prominent buttons
-
Navigation: Menu links and page navigation
- Header/navbar links, footer links, sidebar navigation
- Breadcrumbs, pagination
-
Form: Data capture and submission
- Contact forms, newsletter signup, search inputs
- Lead capture, login/signup forms
-
Pricing: Pricing and plan selection
- Plan comparison, "Choose Plan", upgrade CTAs
-
Auth: Authentication actions
- Login, logout, signup, forgot password
-
Demo: Product demo requests
- "Watch Demo", "Schedule Demo", demo video players
-
Outbound: External links
- Social media, partner sites, documentation
-
Media: Video and audio interactions
- Play, pause, seek, volume controls
按用途对每个元素进行分类:
-
CTA(行动召唤):主要行动按钮
- 「开始使用」、「注册」、「开始试用」、「预约演示」、「下载」
- 通常设计为主要/突出按钮
-
导航:菜单链接和页面导航
- 页眉/导航栏链接、页脚链接、侧边栏导航
- 面包屑、分页
-
表单:数据采集与提交
- 联系表单、新闻通讯订阅、搜索输入框
- 潜在客户采集、登录/注册表单
-
定价:定价与方案选择
- 方案对比、「选择方案」、升级CTA
-
认证:认证操作
- 登录、登出、注册、找回密码
-
演示:产品演示请求
- 「观看演示」、「预约演示」、演示视频播放器
-
外部链接:外部站点链接
- 社交媒体、合作站点、文档
-
媒体:视频与音频交互
- 播放、暂停、快进、音量控制
Phase 4: Existing Tracking Analysis
第四阶段:现有追踪分析
Scan for existing tracking implementation:
DataLayer Usage:
javascript
window.dataLayer.push({...})
dataLayer.push({...})Event Handlers with Tracking:
javascript
onClick={() => {
// Track event
window.dataLayer.push({...})
// Or analytics.track(...)
}}Analytics Libraries:
- Google Analytics (ga, gtag)
- Segment (analytics.track)
- Mixpanel
- Custom analytics implementations
Track Coverage:
- Count elements WITH tracking
- Count elements WITHOUT tracking
- Identify tracking patterns used
扫描现有追踪实现:
DataLayer使用情况:
javascript
window.dataLayer.push({...})
dataLayer.push({...})带有追踪的事件处理器:
javascript
onClick={() => {
// Track event
window.dataLayer.push({...})
// Or analytics.track(...)
}}分析库:
- Google Analytics (ga, gtag)
- Segment (analytics.track)
- Mixpanel
- 自定义分析实现
追踪覆盖率:
- 统计已添加追踪的元素数量
- 统计未添加追踪的元素数量
- 识别使用的追踪模式
Phase 5: DOM Structure Evaluation
第五阶段:DOM结构评估
Evaluate each element's analytics readiness:
ID Attributes:
- Clear, descriptive IDs: ✓
id="cta_hero_get_started" - Generic IDs: ✗
id="button1" - Missing IDs: No id attribute ✗
Class Attributes:
- Analytics classes: ✓
class="js-track js-cta js-click" - Generic classes: △ (functional but not analytics-ready)
class="btn primary" - Inline styles only: No class attribute ✗
Accessibility:
- Semantic HTML: vs
<button>✓<div onClick> - ARIA labels: ✓
aria-label="..." - Alt text on images used in buttons
评估每个元素的分析就绪状态:
ID属性:
- 清晰、描述性的ID:✓
id="cta_hero_get_started" - 通用ID:✗
id="button1" - 缺少ID:无id属性 ✗
类属性:
- 分析专用类:✓
class="js-track js-cta js-click" - 通用类:△(功能性可用但不具备分析适配性)
class="btn primary" - 仅内联样式:无类属性 ✗
可访问性:
- 语义化HTML:vs
<button>✓<div onClick> - ARIA标签:✓
aria-label="..." - 按钮中图片的替代文本
Phase 6: Gap Analysis
第六阶段:差距分析
Identify issues and opportunities:
Naming Issues:
- Generic button names ("button1", "btn", "primary")
- Missing identifiers (no id or meaningful classes)
- Inconsistent naming patterns
Tracking Gaps:
- High-value elements without tracking (CTAs, forms)
- Incomplete tracking (only some CTAs tracked)
- Missing event parameters
Framework-Specific Issues:
- Next.js: Missing 'use client' directives for client-side tracking
- React: Event handlers not tracking clicks
- Vue: Missing event listeners for analytics
识别问题与机会:
命名问题:
- 通用按钮名称("button1", "btn", "primary")
- 缺少标识符(无id或有意义的类)
- 命名模式不一致
追踪差距:
- 高价值元素未添加追踪(CTA、表单)
- 追踪不完整(仅部分CTA添加了追踪)
- 缺少事件参数
框架特定问题:
- Next.js:客户端追踪缺少'use client'指令
- React:事件处理器未追踪点击
- Vue:缺少分析事件监听器
Phase 7: Recommendations
第七阶段:建议
Provide actionable recommendations:
-
DOM Standardization Needs
- "Standardize 23 button identifiers before implementing tracking"
- "Add analytics classes to 15 links"
- "Create consistent naming convention across components"
-
Priority Tracking Opportunities
- P0: CTAs and forms (high conversion impact)
- P1: Navigation and outbound links (user journey)
- P2: Media interactions and scroll events (engagement)
-
Next Steps
- "Run gtm-dom-standardization to clean up DOM structure"
- "Run gtm-strategy to plan tracking implementation"
提供可执行的建议:
-
DOM标准化需求
- 「在实施追踪之前,标准化23个按钮的标识符」
- 「为15个链接添加分析专用类」
- 「在组件间创建一致的命名规范」
-
优先级追踪机会
- P0:CTA和表单(高转化影响)
- P1:导航和外部链接(用户旅程)
- P2:媒体交互和滚动事件(用户参与度)
-
后续步骤
- 「运行gtm-dom-standardization来清理DOM结构」
- 「运行gtm-strategy来规划追踪实现」
Phase 8: Output Generation
第八阶段:输出生成
Generate with complete findings:
audit-report.jsonjson
{
"metadata": {
"auditDate": "2026-02-11T10:30:00Z",
"framework": "Next.js 16.1.6 (App Router)",
"filesScanned": 47,
"componentsAnalyzed": 23
},
"summary": {
"totalClickableElements": 47,
"withTracking": 15,
"withoutTracking": 32,
"analyticsReadiness": "42%"
},
"categorized": {
"cta": {
"total": 12,
"tracked": 4,
"untracked": 8,
"elements": [
{
"file": "app/page.tsx",
"line": 45,
"text": "Get Started",
"id": null,
"classes": ["btn", "primary"],
"tracking": false,
"recommendation": "Add id='cta_hero_get_started' and classes='js-track js-cta js-click js-hero'"
}
]
},
"nav": {
"total": 8,
"tracked": 2,
"untracked": 6
},
"form": {
"total": 3,
"tracked": 0,
"untracked": 3
},
"outbound": {
"total": 5,
"tracked": 1,
"untracked": 4
},
"media": {
"total": 2,
"tracked": 0,
"untracked": 2
}
},
"existingTracking": {
"patterns": [
"window.dataLayer.push (15 occurrences)",
"Custom onClick handlers (4 occurrences)"
],
"libraries": ["Google Tag Manager"],
"coverage": "31.9% of clickable elements"
},
"issues": [
{
"type": "naming",
"severity": "high",
"count": 23,
"description": "23 elements with generic or missing identifiers",
"examples": [
"button with class='btn' only (app/page.tsx:45)",
"link with no id or analytics classes (components/Navbar.tsx:23)"
]
},
{
"type": "tracking_gap",
"severity": "high",
"count": 8,
"description": "8 high-priority CTAs without tracking",
"impact": "Missing conversion data on primary actions"
},
{
"type": "inconsistency",
"severity": "medium",
"count": 12,
"description": "Inconsistent tracking patterns across similar elements"
}
],
"recommendations": [
{
"priority": "P0",
"action": "Run gtm-dom-standardization skill",
"reason": "Standardize 47 elements with consistent analytics-ready identifiers",
"impact": "Creates clean foundation for tracking implementation"
},
{
"priority": "P0",
"action": "Implement tracking on 12 CTAs",
"reason": "Critical conversion actions currently untracked",
"expectedValue": "Visibility into primary conversion funnel"
},
{
"priority": "P1",
"action": "Add form tracking to 3 forms",
"reason": "Lead capture and user input not measured",
"expectedValue": "Form abandonment and completion data"
},
{
"priority": "P2",
"action": "Track 5 outbound links",
"reason": "Referral traffic and external engagement unknown",
"expectedValue": "Partner/resource click-through rates"
}
],
"nextSteps": [
"Invoke gtm-dom-standardization to clean up DOM identifiers",
"Invoke gtm-strategy to plan tracking implementation based on business goals",
"Review audit-report.json with stakeholders to prioritize tracking"
]
}生成包含完整发现的:
audit-report.jsonjson
{
"metadata": {
"auditDate": "2026-02-11T10:30:00Z",
"framework": "Next.js 16.1.6 (App Router)",
"filesScanned": 47,
"componentsAnalyzed": 23
},
"summary": {
"totalClickableElements": 47,
"withTracking": 15,
"withoutTracking": 32,
"analyticsReadiness": "42%"
},
"categorized": {
"cta": {
"total": 12,
"tracked": 4,
"untracked": 8,
"elements": [
{
"file": "app/page.tsx",
"line": 45,
"text": "Get Started",
"id": null,
"classes": ["btn", "primary"],
"tracking": false,
"recommendation": "Add id='cta_hero_get_started' and classes='js-track js-cta js-click js-hero'"
}
]
},
"nav": {
"total": 8,
"tracked": 2,
"untracked": 6
},
"form": {
"total": 3,
"tracked": 0,
"untracked": 3
},
"outbound": {
"total": 5,
"tracked": 1,
"untracked": 4
},
"media": {
"total": 2,
"tracked": 0,
"untracked": 2
}
},
"existingTracking": {
"patterns": [
"window.dataLayer.push (15 occurrences)",
"Custom onClick handlers (4 occurrences)"
],
"libraries": ["Google Tag Manager"],
"coverage": "31.9% of clickable elements"
},
"issues": [
{
"type": "naming",
"severity": "high",
"count": 23,
"description": "23 elements with generic or missing identifiers",
"examples": [
"button with class='btn' only (app/page.tsx:45)",
"link with no id or analytics classes (components/Navbar.tsx:23)"
]
},
{
"type": "tracking_gap",
"severity": "high",
"count": 8,
"description": "8 high-priority CTAs without tracking",
"impact": "Missing conversion data on primary actions"
},
{
"type": "inconsistency",
"severity": "medium",
"count": 12,
"description": "Inconsistent tracking patterns across similar elements"
}
],
"recommendations": [
{
"priority": "P0",
"action": "Run gtm-dom-standardization skill",
"reason": "Standardize 47 elements with consistent analytics-ready identifiers",
"impact": "Creates clean foundation for tracking implementation"
},
{
"priority": "P0",
"action": "Implement tracking on 12 CTAs",
"reason": "Critical conversion actions currently untracked",
"expectedValue": "Visibility into primary conversion funnel"
},
{
"priority": "P1",
"action": "Add form tracking to 3 forms",
"reason": "Lead capture and user input not measured",
"expectedValue": "Form abandonment and completion data"
},
{
"priority": "P2",
"action": "Track 5 outbound links",
"reason": "Referral traffic and external engagement unknown",
"expectedValue": "Partner/resource click-through rates"
}
],
"nextSteps": [
"Invoke gtm-dom-standardization to clean up DOM identifiers",
"Invoke gtm-strategy to plan tracking implementation based on business goals",
"Review audit-report.json with stakeholders to prioritize tracking"
]
}Output Format
输出格式
Present findings to the user in this structure:
=== GTM Analytics Audit Complete ===
Framework: Next.js 16.1.6 (App Router)
Files Scanned: 47 files
Components Analyzed: 23 components
--- Summary ---
Total Clickable Elements: 47
✓ With Tracking: 15 (31.9%)
✗ Without Tracking: 32 (68.1%)
--- Element Breakdown ---
CTAs: 12 total (4 tracked, 8 untracked)
Navigation: 8 total (2 tracked, 6 untracked)
Forms: 3 total (0 tracked, 3 untracked)
Outbound Links: 5 total (1 tracked, 4 untracked)
Media: 2 total (0 tracked, 2 untracked)
--- Key Issues ---
⚠ 23 elements with generic/missing identifiers
⚠ 8 high-priority CTAs without tracking
⚠ 3 forms without tracking
⚠ Inconsistent tracking patterns
--- Existing Tracking ---
✓ Google Tag Manager detected
✓ 15 dataLayer.push() calls found
△ Coverage: 31.9% of clickable elements
--- Recommendations ---
P0 (Critical):
1. Standardize DOM identifiers across 47 elements
→ Invoke gtm-dom-standardization skill
2. Implement tracking on 12 CTAs
→ Critical for conversion funnel visibility
P1 (Important):
3. Add form tracking (3 forms)
→ Capture lead generation and form abandonment
P2 (Nice-to-have):
4. Track outbound links (5 links)
→ Measure partner/resource engagement
--- Next Steps ---
✓ Audit report saved to: audit-report.json
→ Next: Invoke gtm-dom-standardization to prepare DOM for tracking
→ Then: Invoke gtm-strategy to plan tracking implementation
Ready to standardize your DOM? Invoke gtm-dom-standardization skill.按以下结构向用户展示发现结果:
=== GTM Analytics Audit Complete ===
Framework: Next.js 16.1.6 (App Router)
Files Scanned: 47 files
Components Analyzed: 23 components
--- Summary ---
Total Clickable Elements: 47
✓ With Tracking: 15 (31.9%)
✗ Without Tracking: 32 (68.1%)
--- Element Breakdown ---
CTAs: 12 total (4 tracked, 8 untracked)
Navigation: 8 total (2 tracked, 6 untracked)
Forms: 3 total (0 tracked, 3 untracked)
Outbound Links: 5 total (1 tracked, 4 untracked)
Media: 2 total (0 tracked, 2 untracked)
--- Key Issues ---
⚠ 23 elements with generic/missing identifiers
⚠ 8 high-priority CTAs without tracking
⚠ 3 forms without tracking
⚠ Inconsistent tracking patterns
--- Existing Tracking ---
✓ Google Tag Manager detected
✓ 15 dataLayer.push() calls found
△ Coverage: 31.9% of clickable elements
--- Recommendations ---
P0 (Critical):
1. Standardize DOM identifiers across 47 elements
→ Invoke gtm-dom-standardization skill
2. Implement tracking on 12 CTAs
→ Critical for conversion funnel visibility
P1 (Important):
3. Add form tracking (3 forms)
→ Capture lead generation and form abandonment
P2 (Nice-to-have):
4. Track outbound links (5 links)
→ Measure partner/resource engagement
--- Next Steps ---
✓ Audit report saved to: audit-report.json
→ Next: Invoke gtm-dom-standardization to prepare DOM for tracking
→ Then: Invoke gtm-strategy to plan tracking implementation
Ready to standardize your DOM? Invoke gtm-dom-standardization skill.Important Guidelines
重要指南
Senior Engineer Mindset
资深工程师思维
- Be thorough but efficient: Scan comprehensively but summarize clearly
- Identify root causes: Don't just report "missing tracking" - explain why (no IDs, generic classes, etc.)
- Provide context: Explain business impact of each finding
- Think systematically: Categorize and prioritize systematically
- 全面且高效:全面扫描但清晰总结
- 识别根本原因:不要只报告「缺少追踪」,要解释原因(无ID、通用类等)
- 提供上下文:解释每个发现的业务影响
- 系统化思考:系统化地分类和排序优先级
Framework-Specific Awareness
框架特定认知
Next.js App Router:
- Client components need 'use client' directive for tracking
- Server components cannot use onClick directly
React:
- Event handlers should include tracking calls
- Hooks (useState, useEffect) may affect tracking timing
Vue:
- Composition API vs Options API affects event binding
- Template syntax differences from React
Next.js App Router:
- 客户端组件需要'use client'指令才能实现追踪
- 服务器组件不能直接使用onClick
React:
- 事件处理器应包含追踪调用
- Hooks(useState、useEffect)可能影响追踪时机
Vue:
- Composition API与Options API会影响事件绑定
- 模板语法与React不同
Categorization Logic
分类逻辑
Use this decision tree for ambiguous elements:
"Learn More" button:
- If leads to product demo → CTA
- If navigates to info page → Navigation
- Default: CTA (assumes conversion intent)
"Contact Us" link:
- In navigation menu → Navigation
- As prominent button → CTA
- In footer → Navigation
Video player:
- Auto-play background video → Media
- Product demo video → Demo + Media
Search input:
- Header search → Form + Navigation
- Content filter → Form
对模糊元素使用以下决策树:
「了解更多」按钮:
- 如果指向产品演示 → CTA
- 如果导航到信息页面 → 导航
- 默认:CTA(假设存在转化意图)
「联系我们」链接:
- 在导航菜单中 → 导航
- 作为突出按钮 → CTA
- 在页脚中 → 导航
视频播放器:
- 自动播放背景视频 → 媒体
- 产品演示视频 → 演示 + 媒体
搜索输入框:
- 页眉搜索 → 表单 + 导航
- 内容筛选 → 表单
Avoid Over-Engineering
避免过度设计
- Don't recommend tracking EVERY element
- Focus on business-critical interactions
- Skip decorative or redundant elements
- Prioritize based on conversion impact
- 不要建议追踪所有元素
- 专注于业务关键交互
- 跳过装饰性或冗余元素
- 根据转化影响确定优先级
Reference Files
参考文件
- - Analytics ID/class naming standards (load if user asks about naming)
references/naming-conventions.md - - Example audit output showing expected format and audit-report.json structure
examples/sample.md
- - 分析ID/类命名标准(如果用户询问命名则加载)
references/naming-conventions.md - - 示例审计输出,展示预期格式和audit-report.json结构
examples/sample.md
Common Questions
常见问题
Q: Should I track every button?
A: No. Focus on conversion-critical CTAs, forms, and navigation. Skip redundant/decorative elements.
Q: How do I categorize ambiguous elements?
A: Use business intent: Does it drive conversion (CTA) or navigate (nav)? Default to CTA if unclear.
Q: What if the codebase has no tracking at all?
A: That's common! Focus on identifying opportunities and recommend starting with P0 elements (CTAs, forms).
Q: Should I scan node_modules?
A: No. Only scan user code (app/, components/, pages/, src/). Ignore node_modules and build directories.
Q: 我应该追踪每个按钮吗?
A: 不需要。专注于转化关键的CTA、表单和导航。跳过冗余/装饰性元素。
Q: 如何对模糊元素进行分类?
A: 依据业务意图:是否推动转化(CTA)或导航(导航)?如果不确定,默认归类为CTA。
Q: 如果代码库完全没有追踪怎么办?
A: 这很常见!专注于识别机会,并建议从P0元素(CTA、表单)开始。
Q: 我应该扫描node_modules吗?
A: 不需要。仅扫描用户代码(app/、components/、pages/、src/)。忽略node_modules和构建目录。