umami/components/pages/settings/websites/TrackingCode.js

25 lines
749 B
JavaScript
Raw Normal View History

2023-01-10 08:59:26 +01:00
import { TextArea } from 'react-basics';
2023-03-22 22:05:55 +01:00
import useMessages from 'hooks/useMessages';
2023-04-20 16:41:25 +02:00
import useConfig from 'hooks/useConfig';
2023-01-10 08:59:26 +01:00
2023-04-21 17:00:42 +02:00
export function TrackingCode({ websiteId }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, messages } = useMessages();
const { basePath, trackerScriptName } = useConfig();
2023-04-22 02:21:44 +02:00
const url = trackerScriptName?.startsWith('http')
2023-04-20 16:41:25 +02:00
? trackerScriptName
: `${location.origin}${basePath}/${
trackerScriptName?.split(',')?.map(n => n.trim())?.[0] || 'script.js'
}`;
2023-01-10 09:13:32 +01:00
const code = `<script async src="${url}" data-website-id="${websiteId}"></script>`;
2023-01-10 08:59:26 +01:00
return (
<>
2023-01-25 16:42:46 +01:00
<p>{formatMessage(messages.trackingCode)}</p>
2023-01-10 08:59:26 +01:00
<TextArea rows={4} value={code} readOnly allowCopy />
</>
);
}
2023-04-21 17:00:42 +02:00
export default TrackingCode;