@@ -33,6 +33,7 @@ import { Label } from "@crm/ui/components/label";
3333import { StatusIndicator } from "@crm/ui/components/status-indicator" ;
3434import { Switch } from "@crm/ui/components/switch" ;
3535import { useMutation , useQuery } from "@tanstack/react-query" ;
36+ import { useState } from "react" ;
3637import { toast } from "sonner" ;
3738import { useCrmCache } from "@/lib/trpc/cache" ;
3839import { useTRPC } from "@/lib/trpc/client" ;
@@ -41,6 +42,7 @@ export function TrackingScript() {
4142 const trpc = useTRPC ( ) ;
4243 const cache = useCrmCache ( ) ;
4344 const tracking = useQuery ( trpc . tracking . settings . queryOptions ( ) ) ;
45+ const [ section , setSection ] = useState ( "html" ) ;
4446
4547 const setFlag = useMutation (
4648 trpc . tracking . setFlag . mutationOptions ( {
@@ -116,18 +118,29 @@ export function TrackingScript() {
116118 </ CardDescription >
117119
118120 < CardAction >
119- < Button size = "sm" onClick = { ( ) => copy ( snippet ) } type = "button" >
121+ < Button
122+ size = "sm"
123+ onClick = { ( ) =>
124+ copy ( section === "gtm" ? tagManagerSnippet : snippet )
125+ }
126+ type = "button"
127+ >
120128 < Icon icon = { Copy } data-icon = "inline-start" />
121129 Copy
122130 </ Button >
123131 </ CardAction >
124132 </ CardHeader >
125133
126134 < CardContent >
127- < Accordion type = "single" collapsible defaultValue = "html" >
135+ < Accordion
136+ type = "single"
137+ collapsible
138+ value = { section }
139+ onValueChange = { setSection }
140+ >
128141 < AccordionItem value = "html" >
129142 < AccordionTrigger > Paste it into your HTML</ AccordionTrigger >
130- < AccordionContent >
143+ < AccordionContent className = "flex flex-col gap-4" >
131144 < pre className = "overflow-x-auto rounded-md border bg-muted p-4 font-mono text-code-foreground text-xs/5" >
132145 < span className = "text-code-accent" > { "<script" } </ span >
133146 { "\n src=" }
@@ -149,7 +162,7 @@ export function TrackingScript() {
149162 < AccordionTrigger >
150163 Add it through Google Tag Manager
151164 </ AccordionTrigger >
152- < AccordionContent >
165+ < AccordionContent className = "flex flex-col gap-4" >
153166 < pre className = "overflow-x-auto rounded-md border bg-muted p-4 font-mono text-code-foreground text-xs/5" >
154167 < span className = "text-code-accent" > { "<script" } </ span >
155168 { "\n src=" }
@@ -168,23 +181,12 @@ export function TrackingScript() {
168181 off any consent-blocked category you do not need.
169182 </ li >
170183 </ ol >
171- < div className = "flex items-center justify-between gap-4" >
172- < p className = "text-muted-foreground text-xs/relaxed" >
173- Tag Manager drops a{ " " }
174- < span className = "font-mono text-foreground" > data-site</ span > { " " }
175- attribute when it injects a script, so this form carries the
176- site ID in the URL instead.
177- </ p >
178- < Button
179- size = "xs"
180- variant = "outline"
181- type = "button"
182- onClick = { ( ) => copy ( tagManagerSnippet ) }
183- >
184- < Icon icon = { Copy } data-icon = "inline-start" />
185- Copy
186- </ Button >
187- </ div >
184+ < p className = "text-muted-foreground text-xs/relaxed" >
185+ Tag Manager drops a{ " " }
186+ < span className = "font-mono text-foreground" > data-site</ span > { " " }
187+ attribute when it injects a script, so this form carries the
188+ site ID in the URL instead.
189+ </ p >
188190 </ AccordionContent >
189191 </ AccordionItem >
190192 </ Accordion >
0 commit comments