BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/atroui/analytics-provider

Analytics Provider

atroui/analytics-provider
FreeBlock

Plausible / GA loader with trackEvent helpers.

Install it

npx shadcn@latest add https://atroui.com/r/analytics-provider.json

Source

registry/default/blocks/analytics-provider.tsxatroui.com/r/analytics-provider.json
1"use client";
2
3import { useEffect } from "react";
4import Script from "next/script";
5
6import { getExperimentVariant, trackEvent } from "@/lib/analytics";
7
8export { trackEvent, getExperimentVariant };
9
10type AnalyticsProviderProps = {
11 children?: React.ReactNode;
12};
13
14/**
15 * Loads optional Plausible/GA scripts and exposes experiment tracking.
16 * Set NEXT_PUBLIC_PLAUSIBLE_DOMAIN or NEXT_PUBLIC_GA_ID in env.
17 */
18export function AnalyticsProvider({ children }: AnalyticsProviderProps) {
19 const plausibleDomain = process.env.NEXT_PUBLIC_PLAUSIBLE_DOMAIN;
20 const rawGaId = process.env.NEXT_PUBLIC_GA_ID ?? "";
21 // Only allow Measurement ID shape (G-XXXXXXXX) to avoid script injection.
22 const gaId = /^G-[A-Z0-9]+$/i.test(rawGaId) ? rawGaId : undefined;
23
24 useEffect(() => {
25 trackEvent("page_view", { path: window.location.pathname });
26 }, []);
27
28 return (
29 <>
30 {plausibleDomain ? (
31 <Script
32 defer
33 data-domain={plausibleDomain}
34 src="https://plausible.io/js/script.js"
35 strategy="afterInteractive"
36 />
37 ) : null}
38 {gaId ? (
39 <>
40 <Script
41 src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}
42 strategy="afterInteractive"
43 />
44 <Script id="ga-init" strategy="afterInteractive">
45 {`window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','${gaId}');`}
46 </Script>
47 </>
48 ) : null}
49 {children}
50 </>
51 );
52}
53
54export function useExperiment(experimentId: string, variants: string[], weights?: number[]) {
55 useEffect(() => {
56 getExperimentVariant({ id: experimentId, variants, weights });
57 }, [experimentId, variants, weights]);
58}

What it pulls in

npm packages

  • next

Other registry items

  • @atroui/analytics

Files it writes

  • registry/default/blocks/analytics-provider.tsx

Facts

Registry
atroui
Type
registry:block
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-11
Last confirmed
today

Go to the source

atroui.com atroui/atroui on GitHub Raw registry item This item as JSON

More from atroui

All 81 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
AR Portfolioar-portfolioatrouiBlocksFree1 dep
Before / Afterbefore-after-slideratrouiBlocksFreeno deps
Calendly Embedcalendly-embedatrouiBlocksFree1 dep
ChangelogchangelogatrouiBlocksFreeno deps
Command Menucommand-menuatrouiBlocksFree4 deps
Contact Formcontact-formatrouiBlocksFree2 deps
Contextual CTAcontextual-ctaatrouiBlocksFree2 deps
Count Upcount-upatrouiBlocksFreeno deps
BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex