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();
|
2023-05-18 10:26:52 +02:00
|
|
|
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
|
2023-05-18 10:26:52 +02:00
|
|
|
: `${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;
|