import React, { useEffect } from 'react';

const Tracker: React.FC = () => {
    useEffect(() => {
        let websiteId = '';

        if (import.meta.env.MODE === 'production') {
            websiteId = 'cmhannsc96cerxj0euz76p49w';
        } else if (import.meta.env.MODE === 'beta') {
            websiteId = 'cmhanoe4f6cexxj0e3yxb5gq1';
        }

        if (websiteId) {
            const script = document.createElement('script');
            script.src = 'https://tianji.aimloperations.com/tracker.js';
            script.async = true;
            script.defer = true;
            script.setAttribute('data-website-id', websiteId);

            document.body.appendChild(script);

            return () => {
                document.body.removeChild(script);
            };
        }
    }, []);

    return null;
};

export default Tracker;
