UNPKG

strapi-google-analytics-dashboard

Version:

A plug-and-play Google Analytics 4 dashboard for Strapi 5.x. No code required — just install, configure your credentials, and instantly start tracking GA metrics directly in your admin panel.

98 lines (97 loc) 4.05 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const jsxRuntime = require("react/jsx-runtime"); const react = require("react"); const designSystem = require("@strapi/design-system"); const CenterLoader = require("./CenterLoader-DmhVCSwe.js"); const Settings = () => { const [propertyId, setPropertyId] = react.useState(""); const [measurementId, setMeasurementId] = react.useState(""); const [credentials, setCredentials] = react.useState(""); const [loading, setLoading] = react.useState(true); react.useEffect(() => { fetch("/api/strapi-google-analytics-dashboard/settings").then((res) => res.json()).then((data) => { if (data) { setPropertyId(data.propertyId || ""); setMeasurementId(data.measurementId || ""); setCredentials(JSON.stringify(data.credentials || {}, null, 2)); } }).catch(console.error).finally(() => setLoading(false)); }, []); const saveSettings = async () => { try { await fetch("/api/strapi-google-analytics-dashboard/settings", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ propertyId, measurementId, credentials: JSON.parse(credentials) }) }); alert("Settings saved successfully!"); } catch (error) { alert("Error saving settings. Check your JSON credentials."); } }; if (loading) return /* @__PURE__ */ jsxRuntime.jsx(CenterLoader.CenteredLoader, {}); return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 8, background: "neutral0", shadow: "tableShadow", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, maxWidth: "600px", children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", as: "h2", children: "Google Analytics Settings" }), /* @__PURE__ */ jsxRuntime.jsxs( designSystem.Field.Root, { id: "propertyId", hint: "Enter your Google Analytics Property ID.", children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "GA Property ID" }), /* @__PURE__ */ jsxRuntime.jsx( designSystem.TextInput, { label: "Property ID", name: "propertyId", onChange: (e) => setPropertyId(e.target.value), value: propertyId } ), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}) ] } ), /* @__PURE__ */ jsxRuntime.jsxs( designSystem.Field.Root, { id: "measurementId", hint: "Measurement ID is optional but recommended for enhanced tracking.", children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "GA Measurement ID" }), /* @__PURE__ */ jsxRuntime.jsx( designSystem.TextInput, { label: "Measurement ID", name: "measurementId", onChange: (e) => setMeasurementId(e.target.value), value: measurementId } ), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}) ] } ), /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { id: "credentials", hint: "Paste your Google Analytics Service Account JSON here.", children: [ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "GA Service Account JSON" }), /* @__PURE__ */ jsxRuntime.jsx( designSystem.Textarea, { label: "GA Service Account JSON", name: "credentials", onChange: (e) => setCredentials(e.target.value), value: credentials, rows: 10 } ), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}) ] }), /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: saveSettings, children: "Save" }) ] }) }); }; exports.default = Settings;