Skip to content
Skills Library
Data & analytics · Building & coding

google-analytics

/google-analytics

Adds Google Analytics 4 (GA4) to a website with a simple cookie consent banner, so visits are counted only after a visitor agrees. Creates the GA4 property and web stream with the user, puts the measurement ID in an environment variable, loads Google's tag only after consent using Consent Mode, adds an accessible banner with equal Accept and Reject buttons and a way to change the choice later, and checks that visits show up in Realtime. Explains in plain words what consent laws generally ask for, without giving legal advice. Use when the user says "add Google Analytics", "add GA4", "how many p

Repository
vibe.md ↗
Licence
MIT
Last repository change
13.11.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
6
Deprecation

No signals detected. Repository changed on 13.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Adds Google Analytics 4 (GA4) to a website with a simple cookie consent banner, so visits are counted only after a visitor agrees. Creates the GA4 property and web stream with the user, puts the measurement ID in an environment variable, loads Google's tag only after consent using Consent Mode, adds an accessible banner with equal Accept and Reject buttons and a way to change the choice later, and checks that visits show up in Realtime. Explains in plain words what consent laws generally ask for, without giving legal advice. Use when the user says "add Google Analytics", "add GA4", "how many p

Triggers from the description

add Google Analyticsadd GA4
Original author description

Adds Google Analytics 4 (GA4) to a website with a simple cookie consent banner, so visits are counted only after a visitor agrees. Creates the GA4 property and web stream with the user, puts the measurement ID in an environment variable, loads Google's tag only after consent using Consent Mode, adds an accessible banner with equal Accept and Reject buttons and a way to change the choice later, and checks that visits show up in Realtime. Explains in plain words what consent laws generally ask for, without giving legal advice. Use when the user says "add Google Analytics", "add GA4", "how many p

How it works

  1. Purpose
  2. When to Use
  3. Prerequisites
  4. Instructions
  5. Examples
Original SKILL.md headings · 126 lines, 902 words
SKILL.md preview
---
name: google-analytics
description: Adds Google Analytics 4 (GA4) to a website with a simple cookie consent banner, so visits are counted only after a visitor agrees. Creates the GA4 property and web stream with the user, puts the measurement ID in an environment variable, loads Google's tag only after consent using Consent Mode, adds an accessible banner with equal Accept and Reject buttons and a way to change the choice later, and checks that visits show up in Realtime. Explains in plain words what consent laws generally ask for, without giving legal advice. Use when the user says "add Google Analytics", "add GA4", "how many people visit my site?", "I need a cookie banner for analytics", "Analytics shows no data", "תוסיף גוגל אנליטיקס לאתר", or "תוסיף באנר עוגיות". Not for Google Ads or ad tracking pixels, not for Search Console data (use google-search-console), and not for other analytics tools.
license: MIT
compatibility: Needs read and write access to the project and a Google account. Works with Next.js, React and Vite apps, Astro, and plain HTML. The user creates the property in Google Analytics; the agent explains and checks.
metadata:
  collection: vibe.md
  group: google
---

# Google: Analytics (GA4) with consent

Read [the shared google contract](../GOOGLE.md) first, and follow it.

## Purpose

Google Analytics counts visits and shows where visitors come from. In many
places (for example the EU and the UK), sites must ask
before setting analytics cookies. This skill adds GA4 so that **nothing loads
until the visitor says yes**, with a simple banner, and checks that data
arrives.

## When to Use

- The user wants visitor numbers or GA4 on their site.
- The user needs a cookie banner for analytics.
- GA4 shows no data, or shows data before anyone agreed.
- Examples: "Add Google Analytics to my site", "Add GA4 to my Next.js app", "How
  many people visit my site?", "I need a cookie banner for analytics", "תוסיף גוגל אנליטיקס
  לאתר", "תוסיף באנר עוגיות".

Do not use this skill:

- for Google Ads conversion tracking or ad pixels.
- to put the measurement ID on the host. This skill names it;
  `deploy-frontend-env` puts it on the host.
- for search rankings and indexing. Use `google-search-console`.
- for legal advice. Say plainly this is not legal advice, and that a business
  with legal questions should ask a lawyer.

## Prerequisites

- A Google account. GA4 has no charge for normal use; it does not need a Google
  Cloud project or billing.
- The site's live address.

## Instructions

1. **Check what is there.** Look for an existing `gtag(`, `G-` ID,
   `googletagmanager.com`, `@next/third-parties`, Google Tag Manager (`GTM-`),
   or another consent tool (Cookiebot, Osano and similar). If one exists, work
   with it instead of adding a second tag or banner.

2. **Create the property and stream with the user.** Tell them what to do at
   <https://analytics.google.com/>: create a GA4 **property** for the site,
   then a **Web data stream** with the live address. Google then shows a
   **Measurement ID** starting with `G-`. It is not a secret. Official guide:
   <https://support.google.com/analytics/answer/9304153>. Keep "Enhanced
   measurement" on; it counts page changes in single-page apps too.

3. **Put the ID in an environment variable, with a yes.** Use the public prefix,
   for example `NEXT_PUBLIC_GA_MEASUREMENT_ID` or `VITE_GA_MEASUREMENT_ID`.
   The user may paste this ID in the chat; it is public. Check the name is set.

4. **Add the consent banner, with a yes.** Keep it small and plain:
   - One sentence on what is collected and why, a link to the privacy policy,
     and two buttons of equal size and weight: **Accept** and **Reject**.
   - Store the choice (for example in `localStorage` as `analytics-consent`),
     and do not show the banner again once chosen.
   - A "Cookie settings" link in the footer that shows the banner again, so the
     visitor can change their mind. If they change Accept to Reject, call
     `gtag('consent', 'update', { analytics_storage: 'denied' })`, delete the
     `_ga` and `_ga_*` cookies, store the new choice, and do not load the tag on
     later pages.
   - Accessible: a labelled region, buttons reachable by keyboard, visible
     focus, enough contrast in light and dark themes.
   Do not hide Reject, pre-tick anything, or block the page until a choice is
   made.

5. **Load GA4 only after Accept, with Consent Mode, with a yes.**
   - Before any Google tag, set the defaults to denied:
     `gtag('consent', 'default', { analytics_storage: 'denied', ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied' })`.
   - Load the Google tag (`https://www.googletagmanager.com/gtag/js?id=...`)
     **only after** the visitor accepts, or on a later visit when the stored
     choice is Accept. Then call
     `gtag('consent', 'update', { analytics_storage: 'granted' })` and
     `gtag('config', '<id>')`. Leave the ad settings denied unless the user
     runs ads and asks.
   - On Reject, load nothing.
   - In Next.js, the `GoogleAnalytics` component from `@next/third-parties/google`
     can be rendered only when consent is granted. Docs:
     <https://nextjs.org/docs/app/guides/third-party-libraries#google-analytics>.
   Consent Mode docs:
   <https://developers.google.com/tag-platform/security/guides/consent>.

6. **Verify.**
   - In the browser (a browser tool if you have one, otherwise ask the user),
     open the site with a fresh profile or private window: before choosing,
     the network list shows **no** request to `googletagmanager.com` or
     `google-analytics.com`.
   - Click Reject and reload: still none.
   - Clear the choice, click Accept: the tag loads and a `collect` request is
     sent.
   - Ask the user to open GA4's **Realtime** report and confirm the visit
     appears (it can take a minute). For more detail, Google's Tag Assistant
     (<https://tagassistant.google.com/>) shows the consent state.

7. **After deploying, check again on the live site** (the variable must be on
   the host; hand off to `deploy-frontend-env`). Report what you checked.

## Examples

**User:** "Add Google Analytics to my Next.js site."

**Agent:** Finds no existing tag. Walks the user through creating the property
and web stream; the user shares the `G-` ID. Adds
`NEXT_PUBLIC_GA_MEASUREMENT_ID`, a small banner with Accept and Reject and a
footer link, and renders `GoogleAnalytics` only after Accept. Checks in the
browser that nothing loads before a choice or after Reject, and that Accept
sends a request. The user sees the visit in Realtime.

**User:** "תוסיף באנר עוגיות לאנליטיקס"

**Agent:** Answers in Hebrew. Finds GA4 already loaded on every page without
consent. Explains why that is a problem in plain words, without legal advice,
and with a yes moves the tag behind a consent banner. Verifies nothing loads
before Accept.

**User:** "Analytics shows zero visitors."

**Agent:** Checks the ID variable is set on the host, that the stream's address
matches the site, and whether the tag only loads after consent (then visitors who
reject are not counted, which is expected). Opens the site, accepts, and has the
user watch Realtime.

Versions

RepositoryScoreLicence
This page · vibe-md/vibe.md100MIT
superdesigndev/treg100Apache-2.0
davila7/claude-code-templates100MIT
AceDataCloud/Skills100Apache-2.0
OpenClaudia/openclaudia-skills100MIT
fabiensalles/claude-marketplace100MIT
henkisdabro/wookstar-claude-plugins100MIT
lichamnesia/lich-skills100MIT

Database snapshot: 13.11.2026 · package version 3f35e5b188ff (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100cookie-consent
    Implement GDPR and ePrivacy-compliant cookie consent: a banner with equal Accept and Reject buttons, per-category choices, stored consent records, consent-gated analytics with Google Consent Mode v2, and Global Privacy Control. Use when adding a cookie banner, managing marketing…
  • 100consent-mode-auditor
    Audits Google Consent Mode v2 and the cookie banner from HAR files or Tag Assistant, checks what fires before consent, and estimates the GA4 sessions and Google Ads conversions lost to declines. Use when asked for a consent mode v2 check or when data drops in Europe or the UK.
  • 90google-analytics-4
    Use this skill whenever the user installs, configures, or debugs Google Analytics 4, or mentions gtag.js, the Google tag, GTM, key events or conversion tracking, e-commerce events, DebugView or Tag Assistant, or a cookie/consent banner tied to analytics. Covers installation…
  • 98web-analytics
    Measure a site accurately, lawfully and lightly: analytics, tags, events, conversions and consent. Use when setting up GA4 with Google Tag Manager or Consent Mode v2, choosing a privacy-first tool (Plausible, Umami, Matomo, PostHog, Cloudflare), designing an event and conversion…
  • 100iubenda
    Iubenda integration for cookie consent, privacy policy, and GDPR compliance. Use when integrating Iubenda cookie banner, setting up Google Consent Mode v2, or generating privacy documents with Iubenda.
  • 95google-analytics-cli
    Google Analytics 4 data analysis and reporting via google-analytics-cli. Use when the user wants to check GA4 traffic, run reports with dimensions and metrics, monitor realtime users, explore account structure, or analyze user behavior. Triggers: "Google Analytics", "GA4",…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.