Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Better script installation view

Blue Mouse3d6e6c4d7b9b
diff --git a/web/app/pages/Onboarding/Onboarding.tsx b/web/app/pages/Onboarding/Onboarding.tsx
index b2ff2b690..618e49861 100644
--- a/web/app/pages/Onboarding/Onboarding.tsx
+++ b/web/app/pages/Onboarding/Onboarding.tsx
@@ -9,14 +9,70 @@ import {
FileTextIcon,
ClockIcon,
FolderPlusIcon,
+ CopyIcon,
+ CheckIcon,
+ PackageIcon,
+ TagIcon,
+ SquaresFourIcon,
+ ArrowSquareOutIcon,
+ InfoIcon,
} from '@phosphor-icons/react'
+import type { CSSProperties } from 'react'
import { useState, useEffect, useRef, useCallback } from 'react'
import { Trans, useTranslation } from 'react-i18next'
import { useNavigate, useFetcher, useLoaderData } from 'react-router'
import { toast } from 'sonner'
+import {
+ siAngular,
+ siAstro,
+ siBigcommerce,
+ siCarrd,
+ siDjango,
+ siDocusaurus,
+ siDotnet,
+ siDrupal,
+ siEleventy,
+ siExpress,
+ siFastapi,
+ siFastify,
+ siFlask,
+ siFramer,
+ siGatsby,
+ siGhost,
+ siGitbook,
+ siHexo,
+ siHtmx,
+ siHugo,
+ siJekyll,
+ siJoomla,
+ siLaravel,
+ siNestjs,
+ siNextdotjs,
+ siNextra,
+ siNuxt,
+ siPreact,
+ siPrestashop,
+ siQwik,
+ siReact,
+ siRemix,
+ siRubyonrails,
+ siShopify,
+ siSolid,
+ siSquarespace,
+ siSvelte,
+ siVite,
+ siVitepress,
+ siVuedotjs,
+ siWebflow,
+ siWix,
+ siWoocommerce,
+ siWordpress,
+ type SimpleIcon,
+} from 'simple-icons'
import { useAuthProxy } from '~/hooks/useAuthProxy'
import {
+ API_URL,
BROWSER_LOGO_MAP,
DOCS_URL,
INTEGRATIONS_URL,
@@ -36,6 +92,7 @@ import type {
OnboardingLoaderData,
} from '~/routes/onboarding'
import { Badge } from '~/ui/Badge'
+import CodeBlock from '~/ui/CodeBlock'
import Button from '~/ui/Button'
import Flag from '~/ui/Flag'
import PulsatingCircle from '~/ui/icons/PulsatingCircle'
@@ -43,7 +100,6 @@ import Input from '~/ui/Input'
import Loader from '~/ui/Loader'
import Alert from '~/ui/Alert'
import { Text } from '~/ui/Text'
-import Textarea from '~/ui/Textarea'
import { trackCustom } from '~/utils/analytics'
import { cn } from '~/utils/generic'
import routes from '~/utils/routes'
@@ -374,6 +430,299 @@ const FeatureVisualization = ({
)
}
+const API_URL_WITHOUT_TRAILING_SLASH = API_URL.endsWith('/')
+ ? API_URL.slice(0, -1)
+ : API_URL
+
+type TrackingTab = 'script' | 'npm' | 'gtm' | 'platforms'
+
+const TRACKING_TABS: {
+ id: TrackingTab
+ labelKey: string
+ icon: React.ElementType
+}[] = [
+ { id: 'script', labelKey: 'Script', icon: CodeIcon },
+ { id: 'npm', labelKey: 'NPM', icon: PackageIcon },
+ { id: 'gtm', labelKey: 'Tag Manager', icon: TagIcon },
+ { id: 'platforms', labelKey: 'Platforms', icon: SquaresFourIcon },
+]
+
+const PLATFORM_INTEGRATIONS: {
+ name: string
+ href: string
+ icon: SimpleIcon
+ iconClassName?: string
+}[] = [
+ // CMS & site builders
+ {
+ name: 'WordPress',
+ href: 'https://swetrix.com/docs/wordpress-integration',
+ icon: siWordpress,
+ },
+ {
+ name: 'Shopify',
+ href: 'https://swetrix.com/docs/shopify-integration',
+ icon: siShopify,
+ },
+ {
+ name: 'Webflow',
+ href: 'https://swetrix.com/docs/webflow-integration',
+ icon: siWebflow,
+ },
+ {
+ name: 'Wix',
+ href: 'https://swetrix.com/docs/wix-integration',
+ icon: siWix,
+ },
+ {
+ name: 'Squarespace',
+ href: 'https://swetrix.com/docs/squarespace-integration',
+ icon: siSquarespace,
+ iconClassName: 'dark:text-white',
+ },
+ {
+ name: 'Ghost',
+ href: 'https://swetrix.com/docs/ghost-integration',
+ icon: siGhost,
+ iconClassName: 'dark:text-white',
+ },
+ {
+ name: 'Framer',
+ href: 'https://swetrix.com/docs/framer-integration',
+ icon: siFramer,
+ },
+ {
+ name: 'Drupal',
+ href: 'https://swetrix.com/docs/drupal-integration',
+ icon: siDrupal,
+ },
+ {
+ name: 'Joomla',
+ href: 'https://swetrix.com/docs/joomla-integration',
+ icon: siJoomla,
+ },
+ {
+ name: 'BigCommerce',
+ href: 'https://swetrix.com/docs/bigcommerce-integration',
+ icon: siBigcommerce,
+ iconClassName: 'dark:text-white',
+ },
+ {
+ name: 'WooCommerce',
+ href: 'https://swetrix.com/docs/woocommerce-integration',
+ icon: siWoocommerce,
+ },
+ {
+ name: 'PrestaShop',
+ href: 'https://swetrix.com/docs/prestashop-integration',
+ icon: siPrestashop,
+ },
+ {
+ name: 'Carrd',
+ href: 'https://swetrix.com/docs/carrd-integration',
+ icon: siCarrd,
+ },
+ // Frameworks
+ {
+ name: 'React',
+ href: 'https://swetrix.com/docs/react-integration',
+ icon: siReact,
+ },
+ {
+ name: 'Next.js',
+ href: 'https://swetrix.com/docs/nextjs-integration',
+ icon: siNextdotjs,
+ iconClassName: 'dark:text-white',
+ },
+ {
+ name: 'Vue',
+ href: 'https://swetrix.com/docs/vue-integration',
+ icon: siVuedotjs,
+ },
+ {
+ name: 'Nuxt',
+ href: 'https://swetrix.com/docs/nuxt-integration',
+ icon: siNuxt,
+ },
+ {
+ name: 'Angular',
+ href: 'https://swetrix.com/docs/angular-integration',
+ icon: siAngular,
+ iconClassName: 'text-[#DD0031]',
+ },
+ {
+ name: 'SvelteKit',
+ href: 'https://swetrix.com/docs/sveltekit-integration',
+ icon: siSvelte,
+ },
+ {
+ name: 'Remix',
+ href: 'https://swetrix.com/docs/remix-integration',
+ icon: siRemix,
+ iconClassName: 'dark:text-white',
+ },
+ {
+ name: 'Gatsby',
+ href: 'https://swetrix.com/docs/gatsby-integration',
+ icon: siGatsby,
+ },
+ {
+ name: 'Astro',
+ href: 'https://swetrix.com/docs/astro-integration',
+ icon: siAstro,
+ },
+ {
+ name: 'Preact',
+ href: 'https://swetrix.com/docs/preact-integration',
+ icon: siPreact,
+ },
+ {
+ name: 'Qwik',
+ href: 'https://swetrix.com/docs/qwik-integration',
+ icon: siQwik,
+ },
+ {
+ name: 'Solid.js',
+ href: 'https://swetrix.com/docs/solidjs-integration',
+ icon: siSolid,
+ },
+ {
+ name: 'htmx',
+ href: 'https://swetrix.com/docs/htmx-integration',
+ icon: siHtmx,
+ iconClassName: 'dark:text-white',
+ },
+ // Docs & static site generators
+ {
+ name: 'Docusaurus',
+ href: 'https://swetrix.com/docs/docusaurus-integration',
+ icon: siDocusaurus,
+ },
+ {
+ name: 'Hugo',
+ href: 'https://swetrix.com/docs/hugo-integration',
+ icon: siHugo,
+ },
+ {
+ name: 'Jekyll',
+ href: 'https://swetrix.com/docs/jekyll-integration',
+ icon: siJekyll,
+ },
+ {
+ name: 'Eleventy',
+ href: 'https://swetrix.com/docs/eleventy-integration',
+ icon: siEleventy,
+ iconClassName: 'dark:text-white',
+ },
+ {
+ name: 'VitePress',
+ href: 'https://swetrix.com/docs/vitepress-integration',
+ icon: siVitepress,
+ },
+ {
+ name: 'Nextra',
+ href: 'https://swetrix.com/docs/nextra-integration',
+ icon: siNextra,
+ },
+ {
+ name: 'Hexo',
+ href: 'https://swetrix.com/docs/hexo-integration',
+ icon: siHexo,
+ },
+ {
+ name: 'GitBook',
+ href: 'https://swetrix.com/docs/gitbook-integration',
+ icon: siGitbook,
+ },
+ // Backend
+ {
+ name: 'Laravel',
+ href: 'https://swetrix.com/docs/laravel-integration',
+ icon: siLaravel,
+ },
+ {
+ name: 'Django',
+ href: 'https://swetrix.com/docs/django-integration',
+ icon: siDjango,
+ iconClassName: 'dark:text-[#44B78B]',
+ },
+ {
+ name: 'Flask',
+ href: 'https://swetrix.com/docs/flask-integration',
+ icon: siFlask,
+ },
+ {
+ name: 'Ruby on Rails',
+ href: 'https://swetrix.com/docs/ruby-on-rails-integration',
+ icon: siRubyonrails,
+ },
+ {
+ name: 'Express',
+ href: 'https://swetrix.com/docs/express-integration',
+ icon: siExpress,
+ iconClassName: 'dark:text-white',
+ },
+ {
+ name: 'NestJS',
+ href: 'https://swetrix.com/docs/nestjs-integration',
+ icon: siNestjs,
+ },
+ {
+ name: 'Fastify',
+ href: 'https://swetrix.com/docs/fastify-integration',
+ icon: siFastify,
+ iconClassName: 'dark:text-white',
+ },
+ {
+ name: 'FastAPI',
+ href: 'https://swetrix.com/docs/fastapi-integration',
+ icon: siFastapi,
+ },
+ {
+ name: 'ASP.NET',
+ href: 'https://swetrix.com/docs/aspnet-integration',
+ icon: siDotnet,
+ },
+]
+
+const PlatformIcon = ({
+ icon,
+ className,
+ style,
+}: {
+ icon: SimpleIcon
+ className?: string
+ style?: CSSProperties
+}) => (
+ <svg
+ viewBox='0 0 24 24'
+ className={className}
+ style={style}
+ aria-hidden='true'
+ >
+ <path fill='currentColor' d={icon.path} />
+ </svg>
+)
+
+const getNpmSnippet = (pid: string) =>
+ `import * as Swetrix from 'swetrix'
+
+Swetrix.init('${pid}'${isSelfhosted ? `, {\n apiURL: '${API_URL_WITHOUT_TRAILING_SLASH}/v1/log',\n}` : ''})
+Swetrix.trackViews()`
+
+const getGtmSnippet = (pid: string) =>
+ `<script>
+ (function () {
+ var el = document.createElement("script");
+ el.src = "https://swetrix.org/swetrix.js";
+ el.onload = function () {
+ swetrix.init("${pid}"${isSelfhosted ? `, {\n apiURL: "${API_URL_WITHOUT_TRAILING_SLASH}/v1/log",\n }` : ''});
+ swetrix.trackViews();
+ };
+ document.head.appendChild(el);
+ })();
+</script>`
+
const ProjectVisualisation = () => {
return (
<div className='mb-8 w-full rounded-xl p-6 ring-1 ring-gray-200 dark:ring-slate-800'>
@@ -394,6 +743,351 @@ const ProjectVisualisation = () => {
)
}
+const SetupTrackingStep = ({
+ project,
+ isWaitingForEvents,
+ hasEvents,
+}: {
+ project: Project
+ isWaitingForEvents: boolean
+ hasEvents: boolean
+}) => {
+ const { t } = useTranslation('common')
+ const [activeTab, setActiveTab] = useState<TrackingTab>('script')
+
+ return (
+ <div>
+ <Text as='h1' size='3xl' weight='bold' tracking='tight' className='mb-2'>
+ {t('onboarding.installTracking.title')}
+ </Text>
+ <Text as='p' colour='secondary' className='mb-2'>
+ <Trans
+ t={t}
+ i18nKey='onboarding.installTracking.desc'
+ components={{
+ url: (
+ <a
+ href={INTEGRATIONS_URL}
+ target='_blank'
+ rel='noopener noreferrer'
+ className='font-medium text-indigo-600 hover:underline dark:text-indigo-400'
+ />
+ ),
+ }}
+ />
+ </Text>
+ <div className='mb-5 flex items-center gap-1.5'>
+ <InfoIcon className='size-3.5 shrink-0 text-gray-400 dark:text-slate-500' />
+ <Text as='p' size='xs' colour='muted'>
+ {t('onboarding.installTracking.optional')}
+ </Text>
+ </div>
+
+ {/* Tabs */}
+ <div className='mb-4 flex gap-1 rounded-lg bg-gray-100 p-1 dark:bg-slate-800'>
+ {TRACKING_TABS.map((tab) => {
+ const Icon = tab.icon
+ const isActive = activeTab === tab.id
+ return (
+ <button
+ key={tab.id}
+ type='button'
+ onClick={() => setActiveTab(tab.id)}
+ className={cn(
+ 'flex flex-1 items-center justify-center gap-1.5 rounded-md px-3 py-2 text-xs font-medium transition-all',
+ isActive
+ ? 'bg-white text-gray-900 ring-1 ring-gray-200 ring-inset dark:bg-slate-700 dark:text-gray-100 dark:ring-slate-800'
+ : 'text-gray-500 hover:text-gray-700 dark:text-slate-400 dark:hover:text-slate-200',
+ )}
+ >
+ <Icon
+ className='size-4 shrink-0'
+ weight={isActive ? 'bold' : 'regular'}
+ />
+ <span className='hidden sm:inline'>{tab.labelKey}</span>
+ </button>
+ )
+ })}
+ </div>
+
+ {/* Tab content */}
+ <div className='rounded-xl border border-gray-200 bg-gray-50 p-5 dark:border-slate-700 dark:bg-slate-950'>
+ {activeTab === 'script' && (
+ <div>
+ <div className='mb-4 flex items-center gap-3'>
+ <div className='flex size-10 items-center justify-center rounded-lg border border-gray-200 dark:border-slate-700'>
+ <CodeIcon className='size-5 text-gray-700 dark:text-gray-200' />
+ </div>
+ <div>
+ <Text as='h3' size='sm' weight='semibold'>
+ {t('onboarding.installTracking.websiteInstallation')}
+ </Text>
+ <Text as='p' size='xs' colour='secondary'>
+ <Trans
+ t={t}
+ i18nKey='modals.trackingSnippet.add'
+ components={{
+ bsect: <Badge label='<body>' colour='slate' />,
+ }}
+ />
+ </Text>
+ </div>
+ </div>
+
+ <CodeBlock code={getSnippet(project.id)} />
+ </div>
+ )}
+
+ {activeTab === 'npm' && (
+ <div>
+ <div className='mb-4 flex items-center gap-3'>
+ <div className='flex size-10 items-center justify-center rounded-lg border border-gray-200 dark:border-slate-700'>
+ <PackageIcon className='size-5 text-gray-700 dark:text-gray-200' />
+ </div>
+ <div>
+ <Text as='h3' size='sm' weight='semibold'>
+ {t('onboarding.installTracking.npm.title')}
+ </Text>
+ <Text as='p' size='xs' colour='secondary'>
+ {t('onboarding.installTracking.npm.desc')}
+ </Text>
+ </div>
+ </div>
+
+ <div className='space-y-4'>
+ <div>
+ <Text as='p' size='xs' weight='semibold' className='mb-2'>
+ {t('onboarding.installTracking.npm.step1')}
+ </Text>
+ <CodeBlock code='npm install swetrix' />
+ </div>
+ <div>
+ <Text as='p' size='xs' weight='semibold' className='mb-2'>
+ {t('onboarding.installTracking.npm.step2')}
+ </Text>
+ <CodeBlock code={getNpmSnippet(project.id)} />
+ </div>
+ </div>
+
+ <Text as='p' size='xs' colour='muted' className='mt-4'>
+ <Trans
+ t={t}
+ i18nKey='onboarding.installTracking.npm.entryFileHint'
+ components={{
+ codeA: (
+ <code className='rounded bg-gray-200 px-1 py-0.5 dark:bg-slate-800' />
+ ),
+ codeB: (
+ <code className='rounded bg-gray-200 px-1 py-0.5 dark:bg-slate-800' />
+ ),
+ url: (
+ <a
+ href={`${DOCS_URL}/install-script`}
+ target='_blank'
+ rel='noopener noreferrer'
+ className='font-medium text-indigo-600 hover:underline dark:text-indigo-400'
+ />
+ ),
+ }}
+ />
+ </Text>
+ </div>
+ )}
+
+ {activeTab === 'gtm' && (
+ <div>
+ <div className='mb-4 flex items-center gap-3'>
+ <div className='flex size-10 items-center justify-center rounded-lg border border-gray-200 dark:border-slate-700'>
+ <TagIcon className='size-5 text-gray-700 dark:text-gray-200' />
+ </div>
+ <div>
+ <Text as='h3' size='sm' weight='semibold'>
+ {t('onboarding.installTracking.gtm.title')}
+ </Text>
+ <Text as='p' size='xs' colour='secondary'>
+ {t('onboarding.installTracking.gtm.desc')}
+ </Text>
+ </div>
+ </div>
+
+ <div className='space-y-4'>
+ <div>
+ <Text as='p' size='xs' weight='semibold' className='mb-2'>
+ {t('onboarding.installTracking.gtm.step1')}
+ </Text>
+ <CopyableField value={project.id} />
+ </div>
+
+ <div>
+ <Text as='p' size='xs' weight='semibold' className='mb-2'>
+ {t('onboarding.installTracking.gtm.step2')}
+ </Text>
+ <CodeBlock code={getGtmSnippet(project.id)} />
+ </div>
+
+ <div>
+ <Text as='p' size='xs' weight='semibold' className='mb-2'>
+ {t('onboarding.installTracking.gtm.step3')}
+ </Text>
+ </div>
+ </div>
+
+ <Text as='p' size='xs' colour='muted' className='mt-4'>
+ <a
+ href={`${DOCS_URL}/gtm-integration`}
+ target='_blank'
+ rel='noopener noreferrer'
+ className='inline-flex items-center gap-1 font-medium text-indigo-600 hover:underline dark:text-indigo-400'
+ >
+ {t('onboarding.installTracking.gtm.viewGuide')}
+ <ArrowSquareOutIcon className='size-3.5' />
+ </a>
+ </Text>
+ </div>
+ )}
+
+ {activeTab === 'platforms' && (
+ <div>
+ <div className='mb-4 flex items-center gap-3'>
+ <div className='flex size-10 items-center justify-center rounded-lg border border-gray-200 dark:border-slate-700'>
+ <SquaresFourIcon className='size-5 text-gray-700 dark:text-gray-200' />
+ </div>
+ <div>
+ <Text as='h3' size='sm' weight='semibold'>
+ {t('onboarding.installTracking.platforms.title')}
+ </Text>
+ <Text as='p' size='xs' colour='secondary'>
+ {t('onboarding.installTracking.platforms.desc')}
+ </Text>
+ </div>
+ </div>
+
+ <div className='grid grid-cols-2 gap-2 sm:grid-cols-4'>
+ {PLATFORM_INTEGRATIONS.map((integration) => (
+ <a
+ key={integration.name}
+ href={integration.href}
+ target='_blank'
+ rel='noopener noreferrer'
+ className='flex items-center gap-2.5 rounded-lg bg-white px-3 py-2.5 ring-1 ring-gray-200 transition-colors hover:bg-gray-50 hover:ring-gray-300 dark:bg-slate-900 dark:ring-slate-700 dark:hover:bg-slate-800 dark:hover:ring-slate-600'
+ >
+ <PlatformIcon
+ icon={integration.icon}
+ className={cn(
+ 'size-4 shrink-0 text-(--brand-color)',
+ integration.iconClassName,
+ )}
+ style={
+ {
+ '--brand-color': `#${integration.icon.hex}`,
+ } as CSSProperties
+ }
+ />
+ <Text as='span' size='xs' weight='medium'>
+ {integration.name}
+ </Text>
+ </a>
+ ))}
+ </div>
+
+ <Text as='p' size='xs' colour='muted' className='mt-4'>
+ <a
+ href={INTEGRATIONS_URL}
+ target='_blank'
+ rel='noopener noreferrer'
+ className='inline-flex items-center gap-1 font-medium text-indigo-600 hover:underline dark:text-indigo-400'
+ >
+ {t('onboarding.installTracking.platforms.viewAll')}
+ <ArrowSquareOutIcon className='size-3.5' />
+ </a>
+ </Text>
+ </div>
+ )}
+ </div>
+
+ {isWaitingForEvents && (
+ <div className='mt-6 rounded-xl border border-indigo-200 bg-indigo-50 p-4 dark:border-indigo-800 dark:bg-indigo-900/20'>
+ <div className='flex items-center gap-3'>
+ <PulsatingCircle type='big' />
+ <div>
+ <Text as='h3' size='sm' weight='semibold'>
+ {t('onboarding.verifyInstallation.waitingForEvents')}
+ </Text>
+ <Text as='p' size='xs' colour='muted'>
+ {t('onboarding.verifyInstallation.waitingForAnEvent')}
+ </Text>
+ </div>
+ </div>
+ </div>
+ )}
+
+ {hasEvents && (
+ <div className='mt-6 rounded-xl border border-emerald-200 bg-emerald-50 p-4 dark:border-emerald-800 dark:bg-emerald-900/20'>
+ <div className='flex items-center gap-3'>
+ <CheckCircleIcon className='size-6 text-emerald-600 dark:text-emerald-400' />
+ <div>
+ <Text
+ as='h3'
+ size='sm'
+ weight='semibold'
+ className='text-emerald-700 dark:text-emerald-300'
+ >
+ {t('onboarding.verifyInstallation.perfect')}
+ </Text>
+ <Text
+ as='p'
+ size='xs'
+ className='text-emerald-600 dark:text-emerald-400'
+ >
+ {t('onboarding.verifyInstallation.eventReceived')}
+ </Text>
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+ )
+}
+
+const CopyableField = ({ value }: { value: string }) => {
+ const [copied, setCopied] = useState(false)
+
+ const handleCopy = async () => {
+ try {
+ await navigator.clipboard.writeText(value)
+ setCopied(true)
+ setTimeout(() => setCopied(false), 2000)
+ } catch {
+ toast.error('Failed to copy')
+ }
+ }
+
+ return (
+ <div className='flex items-center justify-between rounded-lg bg-white px-4 py-3 font-mono text-sm ring-1 ring-gray-200 dark:bg-slate-950 dark:ring-slate-700'>
+ <span className='truncate text-gray-900 dark:text-gray-100'>{value}</span>
+ <button
+ type='button'
+ onClick={handleCopy}
+ className='ml-3 flex shrink-0 items-center gap-1.5 text-xs font-medium text-gray-500 hover:text-gray-700 dark:text-slate-400 dark:hover:text-slate-200'
+ >
+ {copied ? (
+ <>
+ <CheckIcon className='size-4 text-emerald-500' />
+ <span className='text-emerald-600 dark:text-emerald-400'>
+ Copied
+ </span>
+ </>
+ ) : (
+ <>
+ <CopyIcon className='size-4' />
+ Copy
+ </>
+ )}
+ </button>
+ </div>
+ )
+}
+
const Onboarding = () => {
const { t, i18n } = useTranslation('common')
const { theme } = useTheme()
@@ -855,139 +1549,11 @@ const Onboarding = () => {
)}
{currentStep === 'setup_tracking' && project && (
- <div>
- <Text
- as='h1'
- size='3xl'
- weight='bold'
- tracking='tight'
- className='mb-2'
- >
- {t('onboarding.installTracking.title')}
- </Text>
- <Text as='p' colour='secondary' className='mb-6'>
- <Trans
- t={t}
- i18nKey='onboarding.installTracking.desc'
- components={{
- url: (
- <a
- href={INTEGRATIONS_URL}
- target='_blank'
- rel='noopener noreferrer'
- className='font-medium text-indigo-600 hover:underline dark:text-indigo-400'
- />
- ),
- }}
- />
- </Text>
-
- <div className='rounded-xl border border-gray-200 bg-gray-50 p-5 dark:border-slate-700 dark:bg-slate-950'>
- <div className='mb-4 flex items-center gap-3'>
- <div className='flex size-10 items-center justify-center rounded-lg border border-gray-200 dark:border-slate-700'>
- <CodeIcon className='size-5 text-gray-700 dark:text-gray-200' />
- </div>
- <div>
- <Text as='h3' size='sm' weight='semibold'>
- {t(
- 'onboarding.installTracking.websiteInstallation',
- )}
- </Text>
- <Text as='p' size='xs' colour='secondary'>
- <Trans
- t={t}
- i18nKey='modals.trackingSnippet.add'
- components={{
- bsect: (
- <Badge label='<body>' colour='slate' />
- ),
- }}
- />
- </Text>
- </div>
- </div>
-
- <Textarea
- classes={{
- container: 'font-mono text-xs',
- textarea:
- 'bg-white dark:bg-slate-950 ring-1 ring-gray-200 dark:ring-slate-700',
- }}
- value={getSnippet(project.id)}
- rows={12}
- readOnly
- />
-
- <Text
- as='p'
- size='xs'
- colour='secondary'
- className='mt-4'
- >
- <Trans
- t={t}
- i18nKey='onboarding.installTracking.weAlsoSupport'
- components={{
- url: (
- <a
- href={DOCS_URL}
- target='_blank'
- rel='noopener noreferrer'
- className='font-medium text-indigo-600 hover:underline dark:text-indigo-400'
- />
- ),
- }}
- />
- </Text>
- </div>
-
- {isWaitingForEvents && (
- <div className='mt-6 rounded-xl border border-indigo-200 bg-indigo-50 p-4 dark:border-indigo-800 dark:bg-indigo-900/20'>
- <div className='flex items-center gap-3'>
- <PulsatingCircle type='big' />
- <div>
- <Text as='h3' size='sm' weight='semibold'>
- {t(
- 'onboarding.verifyInstallation.waitingForEvents',
- )}
- </Text>
- <Text as='p' size='xs' colour='muted'>
- {t(
- 'onboarding.verifyInstallation.waitingForAnEvent',
- )}
- </Text>
- </div>
- </div>
- </div>
- )}
-
- {hasEvents && (
- <div className='mt-6 rounded-xl border border-emerald-200 bg-emerald-50 p-4 dark:border-emerald-800 dark:bg-emerald-900/20'>
- <div className='flex items-center gap-3'>
- <CheckCircleIcon className='size-6 text-emerald-600 dark:text-emerald-400' />
- <div>
- <Text
- as='h3'
- size='sm'
- weight='semibold'
- className='text-emerald-700 dark:text-emerald-300'
- >
- {t('onboarding.verifyInstallation.perfect')}
- </Text>
- <Text
- as='p'
- size='xs'
- className='text-emerald-600 dark:text-emerald-400'
- >
- {t(
- 'onboarding.verifyInstallation.eventReceived',
- )}
- </Text>
- </div>
- </div>
- </div>
- )}
- </div>
+ <SetupTrackingStep
+ project={project}
+ isWaitingForEvents={isWaitingForEvents}
+ hasEvents={hasEvents}
+ />
)}
</motion.div>
</AnimatePresence>
@@ -1026,16 +1592,25 @@ const Onboarding = () => {
</Button>
)}
{currentStep === 'setup_tracking' && (
- <Button
- onClick={() => {
- setIsWaitingForEvents(true)
- handleCompleteOnboarding(false)
- }}
- primary
- large
- >
- {t('common.continue')}
- </Button>
+ <>
+ <Button
+ onClick={() => handleCompleteOnboarding(true)}
+ secondary
+ large
+ >
+ {t('onboarding.installTracking.skipForNow')}
+ </Button>
+ <Button
+ onClick={() => {
+ setIsWaitingForEvents(true)
+ handleCompleteOnboarding(false)
+ }}
+ primary
+ large
+ >
+ {t('common.continue')}
+ </Button>
+ </>
)}
</div>
</div>
diff --git a/web/app/ui/CodeBlock.tsx b/web/app/ui/CodeBlock.tsx
new file mode 100644
index 000000000..e8365a8cd
--- /dev/null
+++ b/web/app/ui/CodeBlock.tsx
@@ -0,0 +1,125 @@
+import { CheckIcon, CopyIcon } from '@phosphor-icons/react'
+import { useMemo, useState } from 'react'
+import { toast } from 'sonner'
+
+const highlightHTML = (code: string): React.ReactNode[] => {
+ const parts: React.ReactNode[] = []
+ const regex =
+ /(<\/?[a-zA-Z][a-zA-Z0-9]*)|(\s[a-zA-Z-]+(?==))|("[^"]*")|(&lt;\/?[a-zA-Z][a-zA-Z0-9]*)|(\/>|>)|(\/\/.*$)|(['"]https?:\/\/[^'"]*['"])|(swetrix\.\w+)|(document\.\w+)|(\b(?:function|var|const|let|document|window)\b)/gm
+ let lastIndex = 0
+
+ const matches = [...code.matchAll(regex)]
+
+ for (const match of matches) {
+ const [fullMatch] = match
+ const index = match.index!
+
+ if (index > lastIndex) {
+ parts.push(code.slice(lastIndex, index))
+ }
+
+ if (fullMatch.startsWith('<') || fullMatch.startsWith('&lt;')) {
+ parts.push(
+ <span key={index} className='text-rose-600 dark:text-rose-400'>
+ {fullMatch}
+ </span>,
+ )
+ } else if (fullMatch.startsWith('"') || fullMatch.startsWith("'")) {
+ parts.push(
+ <span key={index} className='text-emerald-600 dark:text-emerald-400'>
+ {fullMatch}
+ </span>,
+ )
+ } else if (fullMatch === '/>' || fullMatch === '>') {
+ parts.push(
+ <span key={index} className='text-rose-600 dark:text-rose-400'>
+ {fullMatch}
+ </span>,
+ )
+ } else if (fullMatch.startsWith('//')) {
+ parts.push(
+ <span key={index} className='text-gray-400 dark:text-slate-500'>
+ {fullMatch}
+ </span>,
+ )
+ } else if (
+ fullMatch.match(/^swetrix\.\w+/) ||
+ fullMatch.match(/^document\.\w+/)
+ ) {
+ parts.push(
+ <span key={index} className='text-sky-600 dark:text-sky-400'>
+ {fullMatch}
+ </span>,
+ )
+ } else if (fullMatch.match(/^\s[a-zA-Z-]+$/)) {
+ parts.push(
+ <span key={index} className='text-amber-600 dark:text-amber-400'>
+ {fullMatch}
+ </span>,
+ )
+ } else {
+ parts.push(
+ <span key={index} className='text-violet-600 dark:text-violet-400'>
+ {fullMatch}
+ </span>,
+ )
+ }
+
+ lastIndex = index + fullMatch.length
+ }
+
+ if (lastIndex < code.length) {
+ parts.push(code.slice(lastIndex))
+ }
+
+ return parts
+}
+
+interface CodeBlockProps {
+ code: string
+ onCopy?: () => void
+}
+
+const CodeBlock = ({ code, onCopy }: CodeBlockProps) => {
+ const [copied, setCopied] = useState(false)
+
+ const handleCopy = async () => {
+ try {
+ await navigator.clipboard.writeText(code)
+ setCopied(true)
+ onCopy?.()
+ setTimeout(() => setCopied(false), 2000)
+ } catch {
+ toast.error('Failed to copy')
+ }
+ }
+
+ const highlighted = useMemo(() => highlightHTML(code), [code])
+
+ return (
+ <div className='group relative'>
+ <pre className='overflow-x-auto rounded-lg bg-white p-4 font-mono text-xs leading-relaxed ring-1 ring-gray-200 dark:bg-slate-950 dark:ring-slate-700'>
+ <code>{highlighted}</code>
+ </pre>
+ <button
+ type='button'
+ onClick={handleCopy}
+ className='absolute top-2.5 right-2.5 flex items-center gap-1.5 rounded-md bg-gray-100 px-2 py-1.5 text-xs font-medium text-gray-600 opacity-0 transition-opacity group-hover:opacity-100 hover:bg-gray-200 dark:bg-slate-800 dark:text-gray-300 dark:hover:bg-slate-700'
+ >
+ {copied ? (
+ <>
+ <CheckIcon className='size-3.5' />
+ Copied
+ </>
+ ) : (
+ <>
+ <CopyIcon className='size-3.5' />
+ Copy
+ </>
+ )}
+ </button>
+ </div>
+ )
+}
+
+export default CodeBlock
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index 22938df76..aceca9892 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -2200,7 +2200,29 @@
"desc": "Add the Swetrix script to your website. You can also use Swetrix for tracking events on your mobile or desktop apps, send events directly to our API. Learn more about more advanced integrations in our <url>documentation</url>.",
"websiteInstallation": "Website installation",
"pasteScript": "Paste the script to your website",
- "weAlsoSupport": "We also support intalling Swetrix via NPM (for React, Vue, etc.), provide Events API to send events directly to our API, and many different integrations with other services like WordPress or Google Tag Manager. <url>Learn more</url>."
+ "weAlsoSupport": "We also support intalling Swetrix via NPM (for React, Vue, etc.), provide Events API to send events directly to our API, and many different integrations with other services like WordPress or Google Tag Manager. <url>Learn more</url>.",
+ "optional": "This step is optional — you can always set up tracking later from your project settings.",
+ "skipForNow": "Skip for now",
+ "npm": {
+ "title": "NPM package",
+ "desc": "For React, Vue, Angular, and other JS frameworks.",
+ "step1": "1. Install the package",
+ "step2": "2. Import and initialise",
+ "entryFileHint": "Add this to your app's entry file (e.g. <codeA>index.js</codeA> or <codeB>App.js</codeB>). <url>View full docs</url>"
+ },
+ "gtm": {
+ "title": "Google Tag Manager",
+ "desc": "Add Swetrix via GTM without touching your codebase.",
+ "step1": "1. Your Project ID",
+ "step2": "2. Create a Custom HTML tag in GTM with this code",
+ "step3": "3. Set the trigger to \"All Pages\" and publish",
+ "viewGuide": "View full GTM guide"
+ },
+ "platforms": {
+ "title": "Platform guides",
+ "desc": "Step-by-step integration guides for popular platforms.",
+ "viewAll": "View all integrations"
+ }
},
"verifyInstallation": {
"navTitle": "Verify installation",