<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://ctd.ueh.edu.vn/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_partner-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_field-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_program-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_space-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_department-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_ctd-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_seminartalk-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_study-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_document-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_lecturers-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_student-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_science-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-posts-mona_leader-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-taxonomies-category_partner-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-taxonomies-category_program-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-taxonomies-department_program-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-taxonomies-category_ctd-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-taxonomies-tax_study-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-taxonomies-tax_science_author-1.xml</loc></sitemap><sitemap><loc>https://ctd.ueh.edu.vn/wp-sitemap-taxonomies-tax_science_year-1.xml</loc></sitemap></sitemapindex>
    <script id="ctd-ga4-tracker">
    (function() {
        'use strict';
        if (navigator.webdriver || /bot|crawl|spider|lighthouse/i.test(navigator.userAgent)) return;

        var endpoint = "https:\/\/ctd.ueh.edu.vn\/wp-admin\/admin-ajax.php?action=ctd_analytics_collect";
        var postId   = 0;
        var postType = "";
        var courseTitle = "";

        function randId(prefix) {
            return prefix + '_' + Math.random().toString(36).substring(2, 10) + '_' + Date.now().toString(36);
        }
        function getCookie(name) {
            var m = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
            return m ? decodeURIComponent(m[1]) : '';
        }
        function setCookie(name, val, maxAgeSec) {
            document.cookie = name + '=' + encodeURIComponent(val) + '; path=/; max-age=' + maxAgeSec + '; SameSite=Lax';
        }

        var clientId = getCookie('_ctd_cid');
        var isNewUser = 0;
        try { if (!clientId) clientId = localStorage.getItem('_ctd_cid') || ''; } catch (e) {}
        if (!clientId) {
            clientId = randId('cid');
            isNewUser = 1;
        }
        setCookie('_ctd_cid', clientId, 63072000);
        try { localStorage.setItem('_ctd_cid', clientId); } catch (e) {}

        var sessionId = getCookie('_ctd_sid');
        if (!sessionId) sessionId = randId('sid');
        setCookie('_ctd_sid', sessionId, 1800);

        var chBrands = '';
        try {
            if (navigator.userAgentData && Array.isArray(navigator.userAgentData.brands)) {
                chBrands = navigator.userAgentData.brands.map(function(b) { return b.brand + '/' + b.version; }).join(', ');
            }
        } catch (e) {}

        var screenW = window.screen ? window.screen.width : window.innerWidth;
        var screenH = window.screen ? window.screen.height : window.innerHeight;
        var screenRes = screenW + 'x' + screenH;
        var touchPoints = navigator.maxTouchPoints || 0;

        var currentEventId = 0;
        var maxScroll = 0;

        function updateScrollDepth() {
            var scrollTop = window.scrollY || document.documentElement.scrollTop || 0;
            var docH = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, 1);
            var winH = window.innerHeight || 1;
            var pct = Math.min(100, Math.round(((scrollTop + winH) / docH) * 100));
            if (pct > maxScroll) maxScroll = pct;
        }
        window.addEventListener('scroll', updateScrollDepth, { passive: true });
        updateScrollDepth();

        function sendPayload(payload, useBeacon) {
            setCookie('_ctd_sid', sessionId, 1800);
            var body = JSON.stringify(payload);
            if (useBeacon && navigator.sendBeacon) {
                var blob = new Blob([body], { type: 'application/json' });
                navigator.sendBeacon(endpoint, blob);
                return;
            }
            fetch(endpoint, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: body,
                keepalive: true
            }).then(function(r) { return r.json(); }).then(function(res) {
                if (res && res.success && res.data && res.data.event_id && !currentEventId) {
                    currentEventId = res.data.event_id;
                }
            }).catch(function() {});
        }

        var initialEvent = (postType === 'mona_program' || postType === 'khoa-hoc') ? 'course_view' : 'page_view';
        sendPayload({
            event_type: initialEvent,
            client_id: clientId,
            session_id: sessionId,
            is_new_user: isNewUser,
            post_id: postId,
            post_type: postType,
            course_title: courseTitle,
            page_url: window.location.href,
            page_title: document.title,
            referrer: document.referrer || '',
            screen_res: screenRes,
            screen_w: screenW,
            touch_points: touchPoints,
            ch_brands: chBrands,
            scroll_depth: maxScroll
        }, false);

        var unsentSec = 0;
        var lastActiveAt = Date.now();
        var totalSentSec = 0;

        function markUserActivity() { lastActiveAt = Date.now(); }
        ['mousemove', 'keydown', 'scroll', 'touchstart', 'click'].forEach(function(ev) {
            window.addEventListener(ev, markUserActivity, { passive: true });
        });

        function flushEngagement(useBeacon) {
            if (unsentSec <= 0 || !currentEventId) return;
            var delta = unsentSec;
            unsentSec = 0;
            totalSentSec += delta;
            sendPayload({
                event_type: 'user_engagement',
                client_id: clientId,
                session_id: sessionId,
                event_id: currentEventId,
                engage_delta: delta,
                scroll_depth: maxScroll
            }, useBeacon);
        }

        setInterval(function() {
            if (document.visibilityState === 'visible' && (Date.now() - lastActiveAt) < 60000) {
                unsentSec += 1;
                if ((totalSentSec === 0 && unsentSec >= 10) || unsentSec >= 20) {
                    flushEngagement(false);
                }
            }
        }, 1000);

        document.addEventListener('visibilitychange', function() {
            if (document.visibilityState === 'hidden') flushEngagement(true);
        });
        window.addEventListener('pagehide', function() {
            flushEngagement(true);
        });

        document.addEventListener('click', function(e) {
            var modalBtn = e.target.closest('[data-open-modal="modal-consultation"], .btn-register-course, .course-register-btn, a[href*="tuyensinh.ueh.edu.vn"], a[href*="/lien-he/"]');
            if (modalBtn) {
                var targetCourse = courseTitle || modalBtn.getAttribute('data-course') || '';
                if (!targetCourse) {
                    var sel = document.querySelector('select[name="course"], input[name="course"]');
                    if (sel && sel.value) targetCourse = sel.value;
                }
                sendPayload({
                    event_type: 'course_cta_click',
                    client_id: clientId,
                    session_id: sessionId,
                    post_id: postId,
                    post_type: 'mona_program',
                    course_title: targetCourse || 'Đăng ký tư vấn chung',
                    page_url: window.location.href,
                    page_title: document.title
                }, true);
                return;
            }

            var link = e.target.closest('a[href*="/chi-tiet-dao-tao/"], a[href*="/danh-muc-dao-tao/"], a[href*="/khoa-hoc/"]');
            if (link) {
                var href = link.getAttribute('href') || '';
                if (href.indexOf('#') === -1 && !/\/(chi-tiet-dao-tao|khoa-hoc)\/?$/.test(href)) {
                    var linkTitle = (link.getAttribute('title') || link.textContent || '').replace(/\s+/g, ' ').trim();
                    if (!linkTitle || linkTitle.toLowerCase() === 'xem chi tiết' || linkTitle.toLowerCase() === 'xem thêm') {
                        var card = link.closest('.trainPro-item, .box-program, .gen-item, .card, li');
                        if (card) {
                            var hEl = card.querySelector('h3, h4, h5, .trainPro-tit, .tt');
                            if (hEl) linkTitle = (hEl.textContent || '').replace(/\s+/g, ' ').trim();
                        }
                    }
                    if (linkTitle && linkTitle.length > 3 && linkTitle.toLowerCase() !== 'xem chi tiết') {
                        sendPayload({
                            event_type: 'course_click',
                            client_id: clientId,
                            session_id: sessionId,
                            post_id: 0,
                            post_type: 'mona_program',
                            course_title: linkTitle,
                            page_url: window.location.href,
                            page_title: document.title
                        }, true);
                    }
                }
            }
        }, true);

        document.addEventListener('change', function(e) {
            if (e.target && e.target.name === 'course' && e.target.value) {
                sendPayload({
                    event_type: 'course_cta_click',
                    client_id: clientId,
                    session_id: sessionId,
                    post_id: postId,
                    post_type: 'mona_program',
                    course_title: e.target.value.trim(),
                    page_url: window.location.href,
                    page_title: document.title
                }, false);
            }
        });

        document.addEventListener('submit', function(e) {
            var form = e.target.closest('.wpcf7-form, .ctelg-ajax-form, .mona-contacts-form form');
            if (form) {
                var cField = form.querySelector('[name="course"], [name="your-subject"]');
                var cVal = (cField && cField.value) ? cField.value.trim() : (courseTitle || 'Tư vấn chung');
                sendPayload({
                    event_type: 'generate_lead',
                    client_id: clientId,
                    session_id: sessionId,
                    post_id: postId,
                    post_type: 'mona_program',
                    course_title: cVal,
                    page_url: window.location.href,
                    page_title: document.title
                }, true);
            }
        });
    })();
    </script>
    