-
Notifications
You must be signed in to change notification settings - Fork 0
/
timing.html
37 lines (33 loc) · 1.05 KB
/
timing.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Google Analytics 時間追蹤範例</title>
<!-- 以下是 GA 追蹤碼的基本安裝 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-C4MV9WZDDJ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments) };
gtag("js", new Date());
gtag("config", "G-C4MV9WZDDJ");
</script>
<script>
var startTime = (new Date()).getTime(); // 取得當前時間:毫秒
function trackTiming() {
var time = (new Date()).getTime() - startTime; // 取得時間差:毫秒
// 送出時間紀錄
gtag("event", "timing_complete", {
"name": "凝視的時間",
"event_category": "使用行為",
"value": time
});
alert("User Timing Sent!");
}
</script>
</head>
<body>
追蹤網頁瀏覽次數
<button onclick="trackTiming();">點擊紀錄:凝視的時間</button>
</body>
</html>