Java 8 has reached end of support
and will be deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Java 8
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Java
8 applications will continue to run and receive traffic after their deprecation date
. We recommend that
you migrate to the latest supported version of Java
.
Integrating with Google Analytics
Stay organized with collections
Save and categorize content based on your preferences.
The Google Analytics Platform
lets you measure user interactions with your business across various devices and
environments. The platform provides all the computing resources to collect,
store, process, and report on these user-interactions.
Analytics collection
can take place on both the client and server side. Google Analytics provides
easy to use APIs and SDKs to send data to Google Analytics. In addition to
those, we have developed code that you can use in your App Engine applications
to easily send server-side analytics to Google Analytics.
Client-side analytics collection
With the collection APIs and SDKs, you can measure how users interact with your
content and marketing initiatives. Once implemented, you will be able to view
user-interaction data within Google Analytics or through the Reporting APIs.
For more details on client-side analytics collection select the link
below based on the type of your client:
- Web Tracking (analytics.js)
-
Measure user interaction with websites or web applications.
- Android
-
Measure user interaction with Android applications.
- iOS
-
Measure user interaction with iOS applications.
- Measurement Protocol
-
Measure user interaction in any environment with this low-level protocol.
App Engine server-side analytics collection
Although App Engine already provides a mechanism for logging events
in your application, it may be advantageous to track specific server-side events
in Google Analytics. Some of the benefits are as follows:
- 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.
- 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.
- Powerful user interface- Take advantage of the rich user interface
that Google Analytics provides to visualize, report and export these server side
events.
This can be accomplished easily by integrating the sample source code below
into your App Engine application. For additional information
on this approach consult the Google Analytics developers guide for Event Tracking
.
Sample source code
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-29 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[[["\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"]]