function menuClose() { document.getElementById("nav-button").click(); } let mobile_search_keyword_show = false; function searchEvent(mobile_search = false) { let width = window.innerWidth; if (!mobile_search && width <= 991) { if (search_keyword && !mobile_search_keyword_show) { sendActionLog(window.location.pathname, "search", search_keyword.ad_id, "view", ""); mobile_search_keyword_show = true; } $("#header").addClass("d-none"); $("#search_header").removeClass("d-none"); } else { let e = document.getElementById("input_search_text").value; if (mobile_search) { e = document.getElementById("mobile_input_search_text").value; } try { if (search_keyword) { sendActionLog(window.location.pathname, "search", search_keyword.ad_id, "click", e); } } catch (e) {} sendDataLayer('search', 'navigation', {'search_term': e, 'search_type': 'manual'}); if (e && e == "營隊") { window.location.href = "/event/camp"; } else if (e && e == "競賽") { window.location.href = "/event/competition"; } else if (e && e == "課程") { window.location.href = "/event/course"; } else if (e && e == "免費") { window.location.href = "/event/free"; } else if (e && e == "證照") { window.location.href = "/event/certification"; } else if (e) { window.location.href = "/event/search?e=" + e; } else { window.location.href = "/event/search"; } } } function closeMobileSearch() { $("#header").removeClass("d-none"); $("#search_header").addClass("d-none"); } function sendDataLayer(event_name, index, ...args) { window.dataLayer = window.dataLayer || []; let data = { event: event_name, index: undefined, ad_id: undefined, ad_name: undefined, section_name: undefined, click_text: undefined, search_term: undefined, search_type: undefined, region: undefined, date: undefined, price_type: undefined, dept: undefined, event_type: undefined, event_id: undefined, event_name: undefined, position: undefined, action: undefined, entry_type: undefined, click_type: undefined, contact_type: undefined, source_event_id: undefined, source_event_name: undefined, status: undefined, reason: undefined, has_ticket_selection: undefined, ticket_type: undefined, payment_status: undefined, method: undefined, source: undefined, is_first_login: undefined, test_stage: undefined, button_name: undefined, question_number: undefined, code: undefined, share_platform: undefined, group_order_id: undefined, ...args[0], }; if(index){ data['index'] = index } let UserID = localStorage.getItem("eport-user_id"); if(UserID) { if(UserID !== 'null') { data.UserID = Number(UserID); }else{ data.UserID = null; } } window.dataLayer.push(data); } function getGAinformation() { function getClientId() { const match = document.cookie.match(/_ga=GA\d\.\d\.(\d+\.\d+)/); return match ? match[1] : null; } function getSessionId() { try { const cookies = document.cookie.split(';'); for (let cookie of cookies) { const eqPos = cookie.indexOf('='); const name = cookie.slice(0, eqPos).trim(); if (name.includes('_ga_')) { const raw = decodeURIComponent(cookie.slice(eqPos + 1)); if (raw.startsWith('GS2.')) { const parts = raw.split('.'); const components = parts[2].split('$'); const data = {}; components.forEach((comp) => { if (comp.startsWith('s')) data.session_id = comp.slice(1); else if (comp.startsWith('o')) data.session_number = comp.slice(1); }); return data; } } } } catch (error) { return { session_id: null, session_number: null }; } } return { client_id: getClientId(), ...getSessionId(), }; }