enable-analytics

작성자: vercel

스토어프론트에 Vercel Analytics, Vercel Speed Insights 및 Google Tag Manager를 추가합니다.

npx skills add https://github.com/vercel/shop --skill enable-analytics

Enable Analytics

The current storefront includes support for Vercel Web Analytics and Vercel Speed Insights, with each integration disabled by default in shop.config.ts. This skill enables or adds those integrations and can also add Google Tag Manager using the recommended integration.

Before you start

Ask the user two questions in order:

1. Do you need to add or change Vercel Analytics and/or Vercel Speed Insights?

  • Enable both — page views, custom events, and Core Web Vitals
  • Analytics only — page view and custom event tracking via @vercel/analytics
  • Speed Insights only — Core Web Vitals monitoring via @vercel/speed-insights
  • Neither — keep both integrations disabled

2. Do you want Google Tag Manager?

If yes, ask for the GTM container ID (e.g. GTM-XXXXXX). This will be stored in the NEXT_PUBLIC_GTM_ID environment variable.

Wait for the user to answer both questions before proceeding.


Part A: Vercel Analytics and Speed Insights

If the storefront has analytics configuration in shop.config.ts, enable only the selected integrations. If the user selected neither, keep both integration gates disabled and skip the remaining steps in this section.

analytics: {
  speedInsights: { enabled: false },
  vercel: { enabled: false },
},

A1. Install dependencies

For older storefronts without the integrations, install only the packages the user selected:

# Both
pnpm add @vercel/analytics @vercel/speed-insights

# Analytics only
pnpm add @vercel/analytics

# Speed Insights only
pnpm add @vercel/speed-insights

For older storefronts, create or update the root analytics component described below. Each library handles its own client-side behavior internally.


Part B: Google Tag Manager

Skip this section if the user did not want GTM.

B1. Install dependency

pnpm add @next/third-parties

B2. Add environment variable

Add to .env.example:

# Google Tag Manager (optional)
NEXT_PUBLIC_GTM_ID="GTM-XXXXXX"

Set the actual value in .env.local or in the Vercel dashboard under Environment Variables.

B3. Add GTM to components/analytics.tsx

Import GoogleTagManager from @next/third-parties/google. Read NEXT_PUBLIC_GTM_ID in the analytics component and render <GoogleTagManager gtmId={gtmId} /> only when the value exists. If the storefront extends shop.config.ts with a GTM integration gate, apply that gate inside the same component.


Part C: Root analytics integration

C1. Create or update components/analytics.tsx

Compose the selected providers in the root analytics component and apply each integration gate there:

import { GoogleTagManager } from "@next/third-parties/google";
import { Analytics } from "@vercel/analytics/next";
import { SpeedInsights } from "@vercel/speed-insights/next";

import { shopConfig } from "@/shop.config";

export function AnalyticsComponents() {
  const gtmId = process.env.NEXT_PUBLIC_GTM_ID;

  return (
    <>
      {shopConfig.analytics.vercel.enabled ? <Analytics /> : null}
      {shopConfig.analytics.speedInsights.enabled ? <SpeedInsights /> : null}
      {gtmId ? <GoogleTagManager gtmId={gtmId} /> : null}
    </>
  );
}

Remove imports for integrations the storefront does not support.

C2. Update app/layout.tsx

Always render the root analytics component inside <body> after the </NextIntlClientProvider> closing tag:

import { AnalyticsComponents } from "@/components/analytics";
<body ...>
  <a href="#main-content" ...>...</a>
  <SiteSchema locale={locale} />
  <NextIntlClientProvider locale={locale} messages={messages}>
    {/* ... existing layout content ... */}
  </NextIntlClientProvider>
  <AnalyticsComponents />
</body>

The root component remains mounted as the extension point for current and future analytics providers. Provider gates stay inside it so disabled integrations are not mounted.

Guardrails

  • Keep root analytics providers and their gates in components/analytics.tsx.
  • Always mount <AnalyticsComponents /> from the root layout, even when every provider is disabled.
  • The GTM container ID must come from NEXT_PUBLIC_GTM_ID, never hardcoded. The provider renders nothing if the env var is missing.
  • Use @next/third-parties/google for GTM, not a manual <script> tag. The Next.js component handles script loading and performance optimization.
  • Import paths: use @vercel/analytics/next and @vercel/speed-insights/next (the /next subpath), not the root package exports.
  • Add NEXT_PUBLIC_GTM_ID to .env.example with a placeholder value so other developers know the variable exists.

vercel의 다른 스킬

benchmark-sandbox
vercel
Vercel Sandbox에서 vercel-plugin eval 시나리오를 로컬 WezTerm 패널 대신 실행합니다. Claude Code와 플러그인이 사전 설치된 임시 마이크로VM을 프로비저닝합니다.
official
emil-design-eng
vercel
이 스킬은 Emil Kowalski의 UI 폴리시, 컴포넌트 디자인, 애니메이션 결정, 그리고 소프트웨어를 훌륭하게 만드는 보이지 않는 세부 사항에 대한 철학을 인코딩합니다.
official
vercel-react-best-practices
vercel
Vercel Engineering의 React 및 Next.js 성능 최적화 가이드라인입니다. 이 스킬은 React/Next.js 코드를 작성, 검토 또는 리팩토링할 때 사용해야 합니다.
official
vercel-react-best-practices
vercel
Vercel Engineering의 React 및 Next.js 성능 최적화 가이드라인입니다. 이 스킬은 React/Next.js 코드를 작성, 검토 또는 리팩토링할 때 사용해야 합니다.
official
write-guide
vercel
점진적인 예제를 통해 실제 사용 사례를 가르치는 기술 가이드를 제작합니다. 개념은 독자가 필요로 할 때만 소개됩니다.
official
release
vercel
Vercel-plugin 릴리스 — 게이트 실행, 버전 업, 아티팩트 생성, 커밋 및 푸시. "릴리스", "배포", "버전 업 및 푸시", "릴리스 생성" 요청 시 사용.
official
deepsec
vercel
dev3000에서 체크아웃한 Vercel 프로젝트에 대해 DeepSec을 실행합니다. 원클릭 DeepSec 설정, 프로젝트 컨텍스트 부트스트래핑, 제한된 1차 처리 등에 사용합니다.
official
backport-pr
vercel
병합된 Next.js 풀 리퀘스트를 canary에서 next-16-2와 같은 이전 릴리스 브랜치로 백포트합니다. 사용자가 백포트, 체리픽 또는 열기를 요청할 때 사용합니다…
official