@md-oss/analytics 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Copyright 2026 Mirasaki Development
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
+
5
+ THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @md-oss/analytics
2
+
3
+ Thin helpers to wire analytics in Next.js apps: Vercel Analytics by default, Google Analytics when a measurement ID is present. Includes a typed env loader for `NEXT_PUBLIC_GA_MEASUREMENT_ID`.
4
+
5
+ ## Features
6
+ - Drop-in `AnalyticsProvider` that renders Vercel Analytics and conditionally Google Analytics
7
+ - Typed env helper using `@t3-oss/env-nextjs` with Zod validation for GA measurement IDs
8
+ - Direct re-exports of `GoogleAnalytics` (Next.js third-parties) and `VercelAnalytics` for custom composition
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pnpm add @md-oss/analytics
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Wrap your Next.js root layout or app with the provider:
19
+
20
+ ```tsx
21
+ // app/layout.tsx
22
+ import { AnalyticsProvider } from '@md-oss/analytics/provider';
23
+
24
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
25
+ return (
26
+ <html lang="en">
27
+ <body>
28
+ <AnalyticsProvider>{children}</AnalyticsProvider>
29
+ </body>
30
+ </html>
31
+ );
32
+ }
33
+ ```
34
+
35
+ Add your GA ID (optional) to the environment:
36
+
37
+ ```env
38
+ NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX
39
+ ```
40
+
41
+ Validate env in Next.js:
42
+
43
+ ```ts
44
+ // app/env.ts
45
+ import { env } from '@md-oss/analytics/env';
46
+
47
+ export const { NEXT_PUBLIC_GA_MEASUREMENT_ID } = env();
48
+ ```
49
+
50
+ If `NEXT_PUBLIC_GA_MEASUREMENT_ID` is set, the provider renders `GoogleAnalytics` with that ID. Vercel Analytics is always enabled via `@vercel/analytics/react`.
51
+
52
+ ## Exports
53
+ - `env` — validated client env loader for GA measurement ID
54
+ - `AnalyticsProvider` — combines Vercel + conditional GA
55
+ - `GoogleAnalytics` — re-export from `@next/third-parties/google`
56
+ - `VercelAnalytics` — re-export from `@vercel/analytics/react`
package/dist/env.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var t=Object.defineProperty;var e=(E,r)=>t(E,"name",{value:r,configurable:!0});var _=require("@t3-oss/env-nextjs"),n=require("zod/v4");const s=e(()=>_.createEnv({client:{NEXT_PUBLIC_GA_MEASUREMENT_ID:n.z.string().startsWith("G-").optional()},runtimeEnv:{NEXT_PUBLIC_GA_MEASUREMENT_ID:process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID}}),"env");exports.env=s;
2
+ //# sourceMappingURL=env.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.cjs","sources":["../src/env.ts"],"sourcesContent":["import { createEnv } from '@t3-oss/env-nextjs';\nimport { z } from 'zod/v4';\n\nexport const env = (): Readonly<{\n\tNEXT_PUBLIC_GA_MEASUREMENT_ID?: string | undefined;\n}> =>\n\tcreateEnv({\n\t\tclient: {\n\t\t\tNEXT_PUBLIC_GA_MEASUREMENT_ID: z.string().startsWith('G-').optional(),\n\t\t},\n\t\truntimeEnv: {\n\t\t\tNEXT_PUBLIC_GA_MEASUREMENT_ID: process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID,\n\t\t},\n\t});\n"],"names":["env","__name","createEnv","z"],"mappings":"oJAGO,MAAMA,EAAMC,EAAA,IAGlBC,EAAAA,UAAU,CACT,OAAQ,CACP,8BAA+BC,EAAAA,EAAE,OAAA,EAAS,WAAW,IAAI,EAAE,SAAA,CAAS,EAErE,WAAY,CACX,8BAA+B,QAAQ,IAAI,6BAAA,CAE7C,CAAC,EAViB"}
package/dist/env.d.cts ADDED
@@ -0,0 +1,5 @@
1
+ declare const env: () => Readonly<{
2
+ NEXT_PUBLIC_GA_MEASUREMENT_ID?: string | undefined;
3
+ }>;
4
+
5
+ export { env };
package/dist/env.d.mts ADDED
@@ -0,0 +1,5 @@
1
+ declare const env: () => Readonly<{
2
+ NEXT_PUBLIC_GA_MEASUREMENT_ID?: string | undefined;
3
+ }>;
4
+
5
+ export { env };
package/dist/env.mjs ADDED
@@ -0,0 +1,2 @@
1
+ var r=Object.defineProperty;var E=(t,_)=>r(t,"name",{value:_,configurable:!0});import{createEnv as n}from"@t3-oss/env-nextjs";import{z as o}from"zod/v4";const e=E(()=>n({client:{NEXT_PUBLIC_GA_MEASUREMENT_ID:o.string().startsWith("G-").optional()},runtimeEnv:{NEXT_PUBLIC_GA_MEASUREMENT_ID:process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID}}),"env");export{e as env};
2
+ //# sourceMappingURL=env.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.mjs","sources":["../src/env.ts"],"sourcesContent":["import { createEnv } from '@t3-oss/env-nextjs';\nimport { z } from 'zod/v4';\n\nexport const env = (): Readonly<{\n\tNEXT_PUBLIC_GA_MEASUREMENT_ID?: string | undefined;\n}> =>\n\tcreateEnv({\n\t\tclient: {\n\t\t\tNEXT_PUBLIC_GA_MEASUREMENT_ID: z.string().startsWith('G-').optional(),\n\t\t},\n\t\truntimeEnv: {\n\t\t\tNEXT_PUBLIC_GA_MEASUREMENT_ID: process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID,\n\t\t},\n\t});\n"],"names":["env","__name","createEnv","z"],"mappings":"yJAGO,MAAMA,EAAMC,EAAA,IAGlBC,EAAU,CACT,OAAQ,CACP,8BAA+BC,EAAE,OAAA,EAAS,WAAW,IAAI,EAAE,SAAA,CAAS,EAErE,WAAY,CACX,8BAA+B,QAAQ,IAAI,6BAAA,CAE7C,CAAC,EAViB"}
@@ -0,0 +1,2 @@
1
+ "use strict";var o=Object.defineProperty;var e=(r,t)=>o(r,"name",{value:t,configurable:!0});var n=require("@next/third-parties/google");Object.defineProperty(exports,"GoogleAnalytics",{enumerable:!0,get:e(function(){return n.GoogleAnalytics},"get")});
2
+ //# sourceMappingURL=google.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { GoogleAnalytics } from '@next/third-parties/google';
2
+ import '@vercel/analytics/react';
@@ -0,0 +1,2 @@
1
+ export { GoogleAnalytics } from '@next/third-parties/google';
2
+ import '@vercel/analytics/react';
@@ -0,0 +1,2 @@
1
+ import{GoogleAnalytics as l}from"@next/third-parties/google";export{l as GoogleAnalytics};
2
+ //# sourceMappingURL=google.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";var n=Object.defineProperty;var i=(e,a)=>n(e,"name",{value:a,configurable:!0});var r=require("react/jsx-runtime"),t=require("./env.cjs"),c=require("@next/third-parties/google"),o=require("@vercel/analytics/react");require("@t3-oss/env-nextjs"),require("zod/v4");const{NEXT_PUBLIC_GA_MEASUREMENT_ID:s}=t.env(),u=i(({children:e})=>r.jsxs(r.Fragment,{children:[e,r.jsx(o.Analytics,{}),s&&r.jsx(c.GoogleAnalytics,{gaId:s})]}),"AnalyticsProvider");exports.AnalyticsProvider=u;
2
+ //# sourceMappingURL=provider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.cjs","sources":["../src/provider.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\nimport { env } from './env';\nimport { GoogleAnalytics } from './google';\nimport { VercelAnalytics } from './vercel';\n\ntype AnalyticsProviderProps = {\n\treadonly children: ReactNode;\n};\n\nconst { NEXT_PUBLIC_GA_MEASUREMENT_ID } = env();\n\nexport const AnalyticsProvider = ({\n\tchildren,\n}: AnalyticsProviderProps): JSX.Element => (\n\t<>\n\t\t{children}\n\t\t<VercelAnalytics />\n\t\t{NEXT_PUBLIC_GA_MEASUREMENT_ID && (\n\t\t\t<GoogleAnalytics gaId={NEXT_PUBLIC_GA_MEASUREMENT_ID} />\n\t\t)}\n\t</>\n);\n"],"names":["NEXT_PUBLIC_GA_MEASUREMENT_ID","env","AnalyticsProvider","__name","children","jsxs","Fragment","VercelAnalytics","jsx","GoogleAnalytics"],"mappings":"mRASA,KAAM,CAAE,8BAAAA,CAAA,EAAkCC,MAAA,EAE7BC,EAAoBC,EAAA,CAAC,CACjC,SAAAC,CACD,IACCC,EAAAA,KAAAC,WAAA,CACE,SAAA,CAAAF,QACAG,EAAAA,UAAA,EAAgB,EAChBP,GACAQ,EAAAA,IAACC,EAAAA,gBAAA,CAAgB,KAAMT,CAAA,CAA+B,CAAA,CAAA,CAExD,EATgC"}
@@ -0,0 +1,8 @@
1
+ import { ReactNode, JSX } from 'react';
2
+
3
+ type AnalyticsProviderProps = {
4
+ readonly children: ReactNode;
5
+ };
6
+ declare const AnalyticsProvider: ({ children, }: AnalyticsProviderProps) => JSX.Element;
7
+
8
+ export { AnalyticsProvider };
@@ -0,0 +1,8 @@
1
+ import { ReactNode, JSX } from 'react';
2
+
3
+ type AnalyticsProviderProps = {
4
+ readonly children: ReactNode;
5
+ };
6
+ declare const AnalyticsProvider: ({ children, }: AnalyticsProviderProps) => JSX.Element;
7
+
8
+ export { AnalyticsProvider };
@@ -0,0 +1,2 @@
1
+ var n=Object.defineProperty;var r=(o,m)=>n(o,"name",{value:m,configurable:!0});import{jsxs as s,Fragment as p,jsx as t}from"react/jsx-runtime";import{env as c}from"./env.mjs";import{GoogleAnalytics as e}from"@next/third-parties/google";import{Analytics as a}from"@vercel/analytics/react";import"@t3-oss/env-nextjs";import"zod/v4";const{NEXT_PUBLIC_GA_MEASUREMENT_ID:i}=c(),l=r(({children:o})=>s(p,{children:[o,t(a,{}),i&&t(e,{gaId:i})]}),"AnalyticsProvider");export{l as AnalyticsProvider};
2
+ //# sourceMappingURL=provider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.mjs","sources":["../src/provider.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\nimport { env } from './env';\nimport { GoogleAnalytics } from './google';\nimport { VercelAnalytics } from './vercel';\n\ntype AnalyticsProviderProps = {\n\treadonly children: ReactNode;\n};\n\nconst { NEXT_PUBLIC_GA_MEASUREMENT_ID } = env();\n\nexport const AnalyticsProvider = ({\n\tchildren,\n}: AnalyticsProviderProps): JSX.Element => (\n\t<>\n\t\t{children}\n\t\t<VercelAnalytics />\n\t\t{NEXT_PUBLIC_GA_MEASUREMENT_ID && (\n\t\t\t<GoogleAnalytics gaId={NEXT_PUBLIC_GA_MEASUREMENT_ID} />\n\t\t)}\n\t</>\n);\n"],"names":["NEXT_PUBLIC_GA_MEASUREMENT_ID","env","AnalyticsProvider","__name","children","jsxs","Fragment","VercelAnalytics","jsx","GoogleAnalytics"],"mappings":"0UASA,KAAM,CAAE,8BAAAA,CAAA,EAAkCC,EAAA,EAE7BC,EAAoBC,EAAA,CAAC,CACjC,SAAAC,CACD,IACCC,EAAAC,EAAA,CACE,SAAA,CAAAF,IACAG,EAAA,EAAgB,EAChBP,GACAQ,EAACC,EAAA,CAAgB,KAAMT,CAAA,CAA+B,CAAA,CAAA,CAExD,EATgC"}
@@ -0,0 +1,2 @@
1
+ "use strict";var c=Object.defineProperty;var e=(r,t)=>c(r,"name",{value:t,configurable:!0});var n=require("@vercel/analytics/react");Object.defineProperty(exports,"VercelAnalytics",{enumerable:!0,get:e(function(){return n.Analytics},"get")});
2
+ //# sourceMappingURL=vercel.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export { Analytics as VercelAnalytics } from '@vercel/analytics/react';
@@ -0,0 +1 @@
1
+ export { Analytics as VercelAnalytics } from '@vercel/analytics/react';
@@ -0,0 +1,2 @@
1
+ import{Analytics as e}from"@vercel/analytics/react";export{e as VercelAnalytics};
2
+ //# sourceMappingURL=vercel.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@md-oss/analytics",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@github.com/Mirasaki-OSS/monorepo-template.git",
12
+ "directory": "vendor/analytics"
13
+ },
14
+ "type": "module",
15
+ "description": "Next.js analytics helpers with Vercel Analytics + optional Google Analytics",
16
+ "license": "ISC",
17
+ "files": [
18
+ "dist/**/*",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "exports": {
23
+ "./env": {
24
+ "require": {
25
+ "types": "./dist/env.d.cts",
26
+ "default": "./dist/env.cjs"
27
+ },
28
+ "import": {
29
+ "types": "./dist/env.d.mts",
30
+ "default": "./dist/env.mjs"
31
+ }
32
+ },
33
+ "./google": {
34
+ "require": {
35
+ "types": "./dist/google.d.cts",
36
+ "default": "./dist/google.cjs"
37
+ },
38
+ "import": {
39
+ "types": "./dist/google.d.mts",
40
+ "default": "./dist/google.mjs"
41
+ }
42
+ },
43
+ "./provider": {
44
+ "require": {
45
+ "types": "./dist/provider.d.cts",
46
+ "default": "./dist/provider.cjs"
47
+ },
48
+ "import": {
49
+ "types": "./dist/provider.d.mts",
50
+ "default": "./dist/provider.mjs"
51
+ }
52
+ },
53
+ "./vercel": {
54
+ "require": {
55
+ "types": "./dist/vercel.d.cts",
56
+ "default": "./dist/vercel.cjs"
57
+ },
58
+ "import": {
59
+ "types": "./dist/vercel.d.mts",
60
+ "default": "./dist/vercel.mjs"
61
+ }
62
+ }
63
+ },
64
+ "dependencies": {
65
+ "@next/third-parties": "^16.1.5",
66
+ "@t3-oss/env-nextjs": "^0.13.10",
67
+ "@types/react": "^19.2.10",
68
+ "@vercel/analytics": "^1.6.1",
69
+ "react": "^19.2.4",
70
+ "zod": "^4.3.6",
71
+ "@md-oss/config": "^0.1.0"
72
+ },
73
+ "devDependencies": {
74
+ "@types/node": "^25.0.9",
75
+ "pkgroll": "^2.21.5",
76
+ "typescript": "^5.9.3"
77
+ },
78
+ "scripts": {
79
+ "build": "pkgroll --minify --clean-dist --sourcemap --define.process.env.NODE_ENV='\"production\"' --define.DEBUG=false",
80
+ "clean": "git clean -xdf .turbo dist node_modules tsconfig.tsbuildinfo",
81
+ "dev": "tsc --watch",
82
+ "typecheck": "tsc --noEmit"
83
+ }
84
+ }