mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 16:17:13 +01:00
27 lines
872 B
TypeScript
27 lines
872 B
TypeScript
import { TextArea } from 'react-basics';
|
|
import { useMessages, useConfig } from 'components/hooks';
|
|
|
|
export function TrackingCode({ websiteId, hostUrl }: { websiteId: string; hostUrl?: string }) {
|
|
const { formatMessage, messages } = useMessages();
|
|
const config = useConfig();
|
|
|
|
const trackerScriptName =
|
|
config?.trackerScriptName?.split(',')?.map((n: string) => n.trim())?.[0] || 'script.js';
|
|
|
|
const url = trackerScriptName?.startsWith('http')
|
|
? trackerScriptName
|
|
: `${hostUrl || process.env.hostUrl || window?.location.origin}${
|
|
process.env.basePath
|
|
}/${trackerScriptName}`;
|
|
|
|
const code = `<script defer src="${url}" data-website-id="${websiteId}"></script>`;
|
|
|
|
return (
|
|
<>
|
|
<p>{formatMessage(messages.trackingCode)}</p>
|
|
<TextArea rows={4} value={code} readOnly allowCopy />
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default TrackingCode;
|