2023-10-20 16:18:30 +00:00
|
|
|
import { useGlobalConfig } from './useConfig';
|
|
|
|
import { useDataReady } from './useDataReady';
|
|
|
|
|
|
|
|
export function useInjectWebsiteScript() {
|
|
|
|
const { websiteId } = useGlobalConfig();
|
|
|
|
|
|
|
|
useDataReady(
|
|
|
|
() => typeof websiteId === 'string' && websiteId.length > 0,
|
|
|
|
() => {
|
|
|
|
const el = document.createElement('script');
|
|
|
|
el.src = location.origin + '/tracker.js';
|
|
|
|
el.setAttribute('data-website-id', String(websiteId));
|
2023-11-10 01:40:38 +00:00
|
|
|
el.setAttribute('async', 'async');
|
|
|
|
el.setAttribute('defer', 'defer');
|
2023-10-20 16:18:30 +00:00
|
|
|
document.head.append(el);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|