Java 8 已停止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 Java 8 應用程式,即使貴機構先前使用機構政策重新啟用舊版執行階段的部署作業也一樣。現有的 Java 8 應用程式在
淘汰日期後,仍會繼續執行並接收流量。建議您
改用最新支援的 Java 版本。
與 Google Analytics 整合
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google Analytics 平台可讓您評估使用者在各種裝置和環境中與貴公司互動的情形。這個平台提供收集、儲存、處理及回報這類使用者互動資料所需的一切運算資源。
在用戶端和伺服器端都能進行分析資料收集作業。Google Analytics 提供簡單好用的 API 和 SDK,方便您傳送資料至 Google Analytics。此外,我們還開發了可在 App Engine 應用程式中使用的程式碼,讓您輕鬆傳送伺服器端分析資料至 Google Analytics。
收集用戶端分析資料
您可以使用資料收集 API 和 SDK,評估使用者與您的內容和行銷活動互動的情形。實作這些 API 和 SDK 後,您就能透過 Google Analytics 或 Reporting API 查看使用者互動資料。如要進一步瞭解用戶端的分析數據收集,請依照用戶端類型選取下列相關連結:
收集 App Engine 伺服器端分析資料
雖然 App Engine 提供在應用程式中記錄事件的機制,但在 Google Analytics 中追蹤特定伺服器端事件或許對您更有利。以下列舉一些好處:
- 歷史資料分析:App Engine 可讓您設定記錄檔的天數上限或大小。超過天數上限後,您就無法再存取記錄檔。但如果您使用 Google Analytics 追蹤事件,過去事件的效期會更長,您也能夠查看更久以前的記錄。
- 追蹤重要事件:由於應用程式的各種元件會將資料寫入記錄檔,因此這些檔案可能相當繁雜。事件追蹤功能可以讓您只鎖定想監控的重要事件,然後追蹤這些事件和一些其他中繼資料。
- 強大的使用者介面:Google Analytics 提供豐富的使用者介面,可用於透過視覺效果呈現、回報及匯出伺服器端事件。
只要在 App Engine 應用程式中整合下列原始碼範例,即可輕鬆享有以上好處。如要進一步瞭解這個做法,請參閱 Google Analytics 開發人員指南的事件追蹤部分。
原始碼範例
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThe Google Analytics Platform is a comprehensive system for measuring user interactions across various devices and environments, providing the necessary resources for data collection, storage, processing, and reporting.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Analytics supports both client-side and server-side data collection through user-friendly APIs and SDKs, allowing the tracking of user interactions with content and marketing initiatives.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine server-side event tracking in Google Analytics offers advantages like extended historical data analysis, the ability to focus on specific key events, and access to a powerful user interface for data visualization and reporting.\u003c/p\u003e\n"],["\u003cp\u003eClient-side analytics collection can be conducted in the web, Android, and iOS environments, as well as in any other environment using the Measurement Protocol.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code shows how to send a server-side event to Google Analytics using App Engine.\u003c/p\u003e\n"]]],[],null,["# Integrating with Google Analytics\n\nThe [Google Analytics Platform](/analytics/devguides/platform)\nlets you measure user interactions with your business across various devices and\nenvironments. The platform provides all the computing resources to collect,\nstore, process, and report on these user-interactions.\n\n[Analytics collection](/analytics/devguides/collection)\ncan take place on both the client and server side. Google Analytics provides\neasy to use APIs and SDKs to send data to Google Analytics. In addition to\nthose, we have developed code that you can use in your App Engine applications\nto easily send server-side analytics to Google Analytics.\n\nClient-side analytics collection\n--------------------------------\n\nWith the collection APIs and SDKs, you can measure how users interact with your\ncontent and marketing initiatives. Once implemented, you will be able to view\nuser-interaction data within Google Analytics or through the Reporting APIs.\nFor more details on client-side analytics collection select the link\nbelow based on the type of your client:\n\n- [Web Tracking (analytics.js)](/analytics/devguides/collection/analyticsjs) - Measure user interaction with websites or web applications.\n- [Android](/analytics/devguides/collection/android) - Measure user interaction with Android applications.\n- [iOS](/analytics/devguides/collection/ios) - Measure user interaction with iOS applications.\n- [Measurement Protocol](/analytics/devguides/collection/protocol/v1) - Measure user interaction in any environment with this low-level protocol.\n\nApp Engine server-side analytics collection\n-------------------------------------------\n\nAlthough App Engine already provides a mechanism for\n\n[logging events](/appengine/docs/legacy/standard/java/logs)\n\nin your application, it may be advantageous to track specific server-side events\nin Google Analytics. Some of the benefits are as follows:\n\n- **Historical data analysis** - App Engine allows you to configure the maximum number of days, or size of your log file. After that time has passed you no longer have access to those log files. Tracking events in Google Analytics provides you a much longer lifespan into the visibility of past events.\n- **Track key events** - Log files can be verbose with various components of your application writing data to them. By using event tracking you can pinpoint just the key events that you are interested in monitoring and track those along with some additional metadata.\n- **Powerful user interface** - Take advantage of the rich user interface that Google Analytics provides to visualize, report and export these server side events.\n\n\nThis can be accomplished easily by integrating the sample source code below\ninto your App Engine application. For additional information\non this approach consult the Google Analytics developers guide for\n[Event Tracking](/analytics/devguides/collection/protocol/v1/devguide#event).\n\n\u003cbr /\u003e\n\n### Sample source code\n\n import com.google.appengine.api.urlfetch.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.urlfetch.URLFetchService.html;\n import com.google.appengine.api.urlfetch.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.urlfetch.URLFetchServiceFactory.html;\n import java.io.IOException;\n import java.net.URI;\n import java.net.URISyntaxException;\n import java.net.URL;\n import javax.servlet.ServletException;\n import javax.servlet.annotation.WebServlet;\n import javax.servlet.http.HttpServlet;\n import javax.servlet.http.HttpServletRequest;\n import javax.servlet.http.HttpServletResponse;\n import org.apache.http.client.utils.URIBuilder;\n\n @SuppressWarnings(\"serial\")\n // With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.\n @WebServlet(\n name = \"analytics\",\n description = \"Analytics: Send Analytics Event to Google Analytics\",\n urlPatterns = \"/analytics\"\n )\n public class AnalyticsServlet extends HttpServlet {\n\n @Override\n public void doGet(HttpServletRequest req, HttpServletResponse resp)\n throws IOException, ServletException {\n String trackingId = System.getenv(\"GA_TRACKING_ID\");\n URIBuilder builder = new URIBuilder();\n builder\n .setScheme(\"http\")\n .setHost(\"www.google-analytics.com\")\n .setPath(\"/collect\")\n .addParameter(\"v\", \"1\") // API Version.\n .addParameter(\"tid\", trackingId) // Tracking ID / Property ID.\n // Anonymous Client Identifier. Ideally, this should be a UUID that\n // is associated with particular user, device, or browser instance.\n .addParameter(\"cid\", \"555\")\n .addParameter(\"t\", \"event\") // Event hit type.\n .addParameter(\"ec\", \"example\") // Event category.\n .addParameter(\"ea\", \"test action\"); // Event action.\n URI uri = null;\n try {\n uri = builder.build();\n } catch (URISyntaxException e) {\n throw new ServletException(\"Problem building URI\", e);\n }\n https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.urlfetch.URLFetchService.html fetcher = https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.urlfetch.URLFetchServiceFactory.html.getURLFetchService();\n URL url = uri.toURL();\n fetcher.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.urlfetch.URLFetchService.html#com_google_appengine_api_urlfetch_URLFetchService_fetch_com_google_appengine_api_urlfetch_HTTPRequest_(url);\n resp.getWriter().println(\"Event tracked.\");\n }\n }\n\n\u003cbr /\u003e"]]