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