fix: get tracking code correctly

This commit is contained in:
MBRjun 2023-04-20 22:41:25 +08:00
parent 136f962218
commit 981abd5966
No known key found for this signature in database
GPG Key ID: 55755D05F9F0BE64

View File

@ -1,12 +1,13 @@
import { TextArea } from 'react-basics';
import { TRACKER_SCRIPT_URL } from 'lib/constants';
import useMessages from 'hooks/useMessages';
import useConfig from 'hooks/useConfig';
export default function TrackingCode({ websiteId }) {
const { formatMessage, messages } = useMessages();
const url = TRACKER_SCRIPT_URL.startsWith('http')
? TRACKER_SCRIPT_URL
: `${location.origin}${TRACKER_SCRIPT_URL}`;
const { trackerScriptName } = useConfig();
const url = trackerScriptName.startsWith('http')
? trackerScriptName
: `${location.origin}/${trackerScriptName}.js`;
const code = `<script async src="${url}" data-website-id="${websiteId}"></script>`;