feat: google analytics setting
This commit is contained in:
@@ -1,28 +1,48 @@
|
||||
import { APP_NAME, OUR_DOMAIN } from "~/lib/env"
|
||||
import { UniLink } from "../ui/UniLink"
|
||||
import { Profile, Note } from "~/lib/types"
|
||||
import Script from "next/script"
|
||||
|
||||
export const SiteFooter: React.FC<{
|
||||
site?: Profile
|
||||
page?: Note
|
||||
}> = ({ site, page }) => {
|
||||
return (
|
||||
<footer className="text-zinc-500 border-t">
|
||||
<div className="max-w-screen-md mx-auto px-5 py-10 text-xs">
|
||||
<p className="font-medium text-base">
|
||||
©{" "}
|
||||
<UniLink href="/" className="hover:text-indigo-500">
|
||||
{site?.username}
|
||||
</UniLink>{" "}
|
||||
· Powered by{" "}
|
||||
<UniLink
|
||||
href={`https://${OUR_DOMAIN}`}
|
||||
className="hover:text-indigo-500"
|
||||
>
|
||||
{APP_NAME}
|
||||
</UniLink>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
<>
|
||||
<footer className="text-zinc-500 border-t">
|
||||
<div className="max-w-screen-md mx-auto px-5 py-10 text-xs">
|
||||
<p className="font-medium text-base">
|
||||
©{" "}
|
||||
<UniLink href="/" className="hover:text-indigo-500">
|
||||
{site?.username}
|
||||
</UniLink>{" "}
|
||||
· Powered by{" "}
|
||||
<UniLink
|
||||
href={`https://${OUR_DOMAIN}`}
|
||||
className="hover:text-indigo-500"
|
||||
>
|
||||
{APP_NAME}
|
||||
</UniLink>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
{site?.ga && (
|
||||
<div className="xlog-google-analytics">
|
||||
<Script
|
||||
src={`https://www.googletagmanager.com/gtag/js?id=G-${site.ga}`}
|
||||
strategy="afterInteractive"
|
||||
/>
|
||||
<Script id="google-analytics" strategy="afterInteractive">
|
||||
{`
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){window.dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', 'G-${site.ga}');
|
||||
`}
|
||||
</Script>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { FieldLabel } from "./FieldLabel"
|
||||
type InputProps<TMultiline extends boolean> = {
|
||||
label?: string
|
||||
addon?: string
|
||||
prefix?: string
|
||||
isBlock?: boolean
|
||||
error?: string
|
||||
help?: React.ReactNode
|
||||
@@ -17,6 +18,7 @@ export const Input = forwardRef(function Input<
|
||||
{
|
||||
label,
|
||||
addon,
|
||||
prefix,
|
||||
className,
|
||||
isBlock,
|
||||
error,
|
||||
@@ -29,18 +31,25 @@ export const Input = forwardRef(function Input<
|
||||
: React.ForwardedRef<HTMLInputElement>,
|
||||
) {
|
||||
const hasAddon = !!addon
|
||||
const hasPrefix = !!prefix
|
||||
const Component = (multiline ? "textarea" : "input") as any
|
||||
|
||||
return (
|
||||
<div>
|
||||
{label && <FieldLabel label={label} id={inputProps.id} />}
|
||||
<div className="flex items-center">
|
||||
{prefix && (
|
||||
<span className="flex items-center px-3 text-gray-600 bg-gray-50 h-10 border border-r-0 rounded-l-lg relative -z-10">
|
||||
{prefix}
|
||||
</span>
|
||||
)}
|
||||
<Component
|
||||
{...inputProps}
|
||||
ref={ref as any}
|
||||
className={clsx(
|
||||
"input",
|
||||
hasAddon && `has-addon`,
|
||||
hasPrefix && `has-prefix`,
|
||||
isBlock && `is-block`,
|
||||
className,
|
||||
)}
|
||||
|
||||
@@ -177,6 +177,9 @@ body {
|
||||
@apply w-full;
|
||||
}
|
||||
|
||||
.input.has-prefix {
|
||||
@apply rounded-l-none;
|
||||
}
|
||||
.input.has-addon {
|
||||
@apply rounded-r-none;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ export type Notes = {
|
||||
export type Profile = UniProfile & {
|
||||
navigation?: SiteNavigationItem[]
|
||||
css?: string
|
||||
ga?: string
|
||||
}
|
||||
|
||||
export type Profiles = {
|
||||
|
||||
@@ -94,6 +94,9 @@ export const getSite = async (input: string) => {
|
||||
site.metadata?.raw?.["_xlog_css"] ||
|
||||
site.metadata?.raw?.["_crosslog_css"] ||
|
||||
""
|
||||
site.ga =
|
||||
site.metadata?.raw?.attributes?.find((a: any) => a.trait_type === "xlog_ga")
|
||||
?.value || ""
|
||||
site.name = site.name || site.username
|
||||
|
||||
return site
|
||||
@@ -122,6 +125,7 @@ export async function updateSite(payload: {
|
||||
subdomain?: string
|
||||
navigation?: SiteNavigationItem[]
|
||||
css?: string
|
||||
ga?: string
|
||||
}) {
|
||||
return await unidata.profiles.set(
|
||||
{
|
||||
@@ -135,7 +139,7 @@ export async function updateSite(payload: {
|
||||
...(payload.description && { bio: payload.description }),
|
||||
...(payload.icon && { avatars: [payload.icon] }),
|
||||
...(payload.subdomain && { username: payload.subdomain }),
|
||||
...((payload.navigation || payload.css) && {
|
||||
...((payload.navigation || payload.css || payload.ga) && {
|
||||
attributes: [
|
||||
...(payload.navigation
|
||||
? [
|
||||
@@ -153,6 +157,14 @@ export async function updateSite(payload: {
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(payload.ga
|
||||
? [
|
||||
{
|
||||
trait_type: "xlog_ga",
|
||||
value: payload.ga,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useRouter } from "next/router"
|
||||
import { DashboardLayout } from "~/components/dashboard/DashboardLayout"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useGetSite, useUpdateSite } from "~/queries/site"
|
||||
import { UniLink } from "~/components/ui/UniLink"
|
||||
|
||||
export default function SiteSettingsGeneralPage() {
|
||||
const router = useRouter()
|
||||
@@ -21,6 +22,7 @@ export default function SiteSettingsGeneralPage() {
|
||||
defaultValues: {
|
||||
name: "",
|
||||
description: "",
|
||||
ga: "",
|
||||
},
|
||||
})
|
||||
|
||||
@@ -29,6 +31,7 @@ export default function SiteSettingsGeneralPage() {
|
||||
site: subdomain,
|
||||
name: values.name,
|
||||
description: values.description,
|
||||
ga: values.ga,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -46,8 +49,10 @@ export default function SiteSettingsGeneralPage() {
|
||||
|
||||
useEffect(() => {
|
||||
if (site.data) {
|
||||
form.setValue("name", site.data.name || "")
|
||||
form.setValue("description", site.data.bio || "")
|
||||
!form.getValues("name") && form.setValue("name", site.data.name || "")
|
||||
!form.getValues("description") &&
|
||||
form.setValue("description", site.data.bio || "")
|
||||
!form.getValues("ga") && form.setValue("ga", site.data.ga || "")
|
||||
}
|
||||
}, [site.data, form])
|
||||
|
||||
@@ -75,10 +80,31 @@ export default function SiteSettingsGeneralPage() {
|
||||
<textarea
|
||||
id="description"
|
||||
className="input is-block"
|
||||
rows={6}
|
||||
rows={2}
|
||||
{...form.register("description")}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-5">
|
||||
<Input
|
||||
id="ga"
|
||||
{...form.register("ga")}
|
||||
prefix="G-"
|
||||
label="Google Analytics"
|
||||
help={
|
||||
<p>
|
||||
Integrate Google Analytics into your xlog. You can follow the
|
||||
instructions{" "}
|
||||
<UniLink
|
||||
className="underline"
|
||||
href="https://support.google.com/analytics/answer/9539598"
|
||||
>
|
||||
here
|
||||
</UniLink>{" "}
|
||||
to find your Measurement ID.
|
||||
</p>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-5">
|
||||
<Button type="submit" isLoading={updateSite.isLoading}>
|
||||
Save
|
||||
|
||||
Reference in New Issue
Block a user