PageSourceSearch

https://www.advantech.com/2026/js/home/tracking-events.js?v=PQSJKv4CE27SKifCbB6pkWhcmRiit69r0QwADbtStUg

js advantech.com collected 2026-10-09 21:46:09 UTC 5,064 bytes, 93 lines download raw bytes

1/**
2 * Homepage GA4 Tracking Events
3 * ────────────────────────────
4 * 透過 dataLayer.push 推送 site_click 事件給 GTM。
5 * 條件: 語系非 zh-cn 時才啟動。
6 *
7 * 兩組事件:
8 *  KV:               { event: "site_click", Item: "KV", Item_Cate: undefined, Item_Name: 標題 }
9 *                    (Item_Cate 明確送 undefined,清掉 GTM data model 殘留的上一次值,見 push() 註解)
10 *  Homepage Content: { event: "site_click", Item: "Homepage Content", Item_Cate: 區塊類型, Item_Name: 標題 }
11 *
12 * ── Homepage Content(Task #47335,Sena 2026-10 覆驗規格)──
13 * 取代原本的 Solution / IoT Partner / Corporate News / Case Study 四個 Item 值(規格明確要求
14 * 移除,GA4 報表上舊 Item 的歷史資料不會跟新事件接起來,這是已知取捨)。
15 *
16 * 區塊類型讀 <section data-home-section="..."> 再對照成固定英文值,不讀區塊標題文字也不靠
17 * 樣式 class 判斷:
18 *  - 區塊標題已多語系翻譯(#47332),拿標題當 Item_Cate 會讓報表依語系拆成多種字串
19 *  - 樣式 class 會隨改版變動——舊版這支檔案的 selector 在新版面上線後大多對不到元素,
20 *    追蹤悄悄失效,正是這次要修的問題
21 *
22 * Item_Name 從被點的連結「往上找到所在卡片,再往下找標題」:Solutions 大卡(遮罩連結+
23 * Discover More 按鈕)與 Case Study(遮罩連結+Learn more)一張卡有兩個連結,標題跟連結
24 * 不在固定相對位置,只有先定位到卡片才能兩個連結都拿到同一個標題。
25 *
26 * 全部用 $(document).on 事件委派:KV 的 slide 是 home/index.js 之後才塞進來的,News/
27 * Case Study/Video 也會被 personalization.js 整段替換,委派才不會漏掉新產生的元素。
28 */
29(function ($) {
30    'use strict';
31
32    // data-home-section 值 → GA4 Item_Cate(Sena 規格指定的字串,不要改名)
33    var SECTION_CATE = {
34        'news': 'News',
35        'solutions': 'Solution',
36        'case-studies': 'Case Study',
37        'videos': 'Video'
38    };
39
40    $(function () {
41        var langElement = document.getElementById('hidGlobalLang');
42        var currentLang = langElement ? langElement.value : '';
43
44        if (currentLang === 'zh-cn') return;
45
46        // 每次都帶齊 Item / Item_Cate / Item_Name 三個欄位:GTM 會把每次 push 合併進同一份
47        // data model,沒帶到的 key 會沿用上一次的值。KV 沒有分類,若不明確送 undefined,使用者
48        // 先點內容卡(例如 ctrl+click 開新分頁、人還留在首頁)再點 KV,GTM 讀到的 Item_Cate
49        // 會是上一次的值(例如 "Video")。
50        // 這裡刻意直接組物件、不用 $.extend:$.extend 會略過值為 undefined 的屬性,
51        // Item_Cate: undefined 會被丟掉,等於沒清。
52        function push(item, itemCate, itemName) {
53            window.dataLayer = window.dataLayer || [];
54            window.dataLayer.push({
55                event: 'site_click',
56                Item: item,
57                Item_Cate: itemCate,
58                Item_Name: itemName
59            });
60        }
61
62        function cleanText(text) {
63            return String(text || '').replace(/\s+/g, ' ').trim();
64        }
65
66        // 1. KV Banner 點擊
67        $(document).on('click', '.ui-home-hero__actions .ui-btn', function () {
68            var itemName = $(this).closest('.ui-home-hero__slide').find('.item__title').first().text();
69            push('KV', undefined, cleanText(itemName));
70        });
71
72        // 2. Homepage Content:News / Solutions / Case Studies / Videos 區塊內任一連結
73        $(document).on('click', '[data-home-section] a', function () {
74            var $link = $(this);
75            var section = $link.closest('[data-home-section]').attr('data-home-section');
76            var itemCate = SECTION_CATE[section];
77            if (!itemCate) return; // 未列在對照表的區塊不推送,避免送出非規格值
78
79            // 正常路徑:卡片標題。找不到(例如 UI Kit 改版、連結不再包在 .ui-card/.ui-bento-item 裡)
80            // 才退回連結的 aria-label——它會帶前綴("view more about ..."、"Watch: ..."),
81            // 不如標題乾淨,但比送出空字串有意義。兩者都沒有就不送,並留 console 警告,
82            // 避免版面變動後悄悄送出無意義的資料。
83            var itemName = cleanText($link.closest('.ui-card, .ui-bento-item').find('h3, h4').first().text())
84                || cleanText($link.attr('aria-label'));
85            if (!itemName) {
86                console.warn('[homepage tracking] Homepage Content link has no card title or aria-label; event not sent.', this);
87                return;
88            }
89
90            push('Homepage Content', itemCate, itemName);
91        });
92    });
93})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.