Google Analytics 4 Setup for Openclaw

A comprehensive automation skill to intelligently detect web frameworks and implement Google Analytics 4 tracking with best practices.

jeftekhari
v0.1.0
Feb 3, 2026
1
3.9k
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install add-analytics

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install add-analytics using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is Google Analytics 4 Setup?

The Google Analytics 4 Setup skill is a specialized tool within the Openclaw Skills ecosystem designed to eliminate the manual overhead of implementing web analytics. It intelligently scans your project's architecture to identify the specific framework being used—ranging from Next.js and Nuxt to Astro and SvelteKit—and applies a tailored integration strategy. By automating the creation of components, plugins, and environment configurations, it ensures that your tracking is both robust and performant.

Beyond basic page views, this skill addresses modern development needs such as TypeScript support, environment variable management, and Single Page Application (SPA) route tracking. Using this skill ensures that your analytics implementation follows the latest Google standards, helping you avoid common pitfalls like duplicate tracking or incorrectly formatted IDs that often plague manual setups.

Google Analytics 4 Setup Use Cases

  • Deploying Google Analytics 4 across diverse tech stacks including React, Vue, and Angular.
  • Upgrading legacy web projects from Universal Analytics to the modern GA4 standard.
  • Implementing standardized event tracking for conversions, sign-ups, and user engagement.
  • Adding GDPR-compliant cookie consent mechanisms to existing analytics workflows.
  • Standardizing analytics implementation across multiple client repositories.

How Google Analytics 4 Setup Works

  1. The skill performs a priority scan of your project files to detect the specific framework and package manager in use.
  2. It validates the provided Measurement ID to ensure it adheres to the required G-XXXXXXXXXX format.
  3. Based on the framework, it generates optimized tracking code, such as React components, Nuxt plugins, or Astro scripts.
  4. It automatically configures the necessary environment variables and ensures sensitive IDs are added to .gitignore.
  5. If requested via flags, it injects advanced utility libraries for custom event tracking and consent management.
  6. It provides a final verification checklist to confirm the setup is active and reporting data correctly.

Google Analytics 4 Setup Setup

To initiate the setup using Openclaw Skills, provide your Measurement ID and optional flags for enhanced functionality:

openclaw run add-analytics "G-XXXXXXXXXX" --events --consent --debug

Ensure you have your GA4 Measurement ID from the Google Analytics dashboard before starting the process.

Google Analytics 4 Setup Data Schema & Taxonomy

The skill organizes its output based on the detected environment, ensuring a clean and maintainable file structure:

Component Location Description
Environment Config .env, .env.local Stores the framework-specific Measurement ID variable.
Tracking Component app/layout.tsx or components/ The core script injection component for React/Next.js/Astro.
Event Utilities lib/analytics-events.ts Shared functions for tracking clicks, scrolls, and conversions.
Consent Logic lib/analytics-consent.ts Wrapper for managing analytics_storage and ad_storage states.
Type Definitions types/gtag.d.ts TypeScript global declarations for the window.gtag object.

Google Analytics 4 Setup Advanced Features

  • Multi-framework support covering over 12 major JavaScript environments and plain HTML.
  • Automated SPA route change detection to ensure accurate page view reporting in dynamic apps.
  • Comprehensive event tracking suite including engagement, conversion, and error monitoring utilities.
  • Consent mode integration for privacy compliance, allowing 'granted' or 'denied' states for storage.
  • Debug mode configuration to enable real-time validation in development environments via the GA4 DebugView.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*