Merge pull request #2047 from jclab-joseph/fix/tracking-code-base-path

Fix to add basePath to trackingCode generation
This commit is contained in:
Mike Cao 2023-05-22 21:17:56 -07:00 committed by GitHub
commit 050cd2f5d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,10 +4,12 @@ import useConfig from 'hooks/useConfig';
export function TrackingCode({ websiteId }) { export function TrackingCode({ websiteId }) {
const { formatMessage, messages } = useMessages(); const { formatMessage, messages } = useMessages();
const { trackerScriptName } = useConfig(); const { basePath, trackerScriptName } = useConfig();
const url = trackerScriptName?.startsWith('http') const url = trackerScriptName?.startsWith('http')
? trackerScriptName ? trackerScriptName
: `${location.origin}/${trackerScriptName?.split(',')?.map(n => n.trim())?.[0] || 'script.js'}`; : `${location.origin}${basePath}/${
trackerScriptName?.split(',')?.map(n => n.trim())?.[0] || 'script.js'
}`;
const code = `<script async src="${url}" data-website-id="${websiteId}"></script>`; const code = `<script async src="${url}" data-website-id="${websiteId}"></script>`;