Python 2.7 has reached end of supportand will bedeprecatedon January 31, 2026. After deprecation, you won't be able to deploy Python 2.7applications, even if your organization previously used an organization policy tore-enable deployments of legacy runtimes. Your existing Python2.7 applications will continue to run and receive traffic after theirdeprecation date. We recommend thatyoumigrate to the latest supported version of Python.

Integrating with Google Analytics

TheGoogle Analytics Platformlets you measure user interactions with your business across various devices andenvironments. The platform provides all the computing resources to collect,store, process, and report on these user-interactions.

Analytics collectioncan take place on both the client and server side. Google Analytics provideseasy to use APIs and SDKs to send data to Google Analytics. In addition tothose, we have developed code that you can use in your App Engine applicationsto 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 yourcontent and marketing initiatives. Once implemented, you will be able to viewuser-interaction data within Google Analytics or through the Reporting APIs.For more details on client-side analytics collection select the linkbelow 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 forlogging eventsin your application, it may be advantageous to track specific server-side eventsin Google Analytics. Some of the benefits are as follows:

  • Historical data analysis - App Engine allows you to configure themaximum number of days, or size of your log file. After that time has passed youno longer have access to those log files. Tracking events in Google Analyticsprovides you a much longer lifespan into the visibility of past events.
  • Track key events - Log files can be verbose with various componentsof your application writing data to them. By using event tracking you canpinpoint just the key events that you are interested in monitoring and trackthose along with some additional metadata.
  • Powerful user interface - Take advantage of the rich user interfacethat Google Analytics provides to visualize, report and export these server sideevents.

This can be accomplished easily by integrating the sample source code belowinto your App Engine application. For additional informationon this approach consult the Google Analytics developers guide forEvent Tracking.

Sample source code

deftrack_event(category,action,label=None,value=0):data={'v':'1',# API Version.'tid':GA_TRACKING_ID,# Tracking ID / Property ID.# Anonymous Client Identifier. Ideally, this should be a UUID that# is associated with particular user, device, or browser instance.'cid':'555','t':'event',# Event hit type.'ec':category,# Event category.'ea':action,# Event action.'el':label,# Event label.'ev':value,# Event value, must be an integer}response=requests.post('http://www.google-analytics.com/collect',data=data)# If the request fails, this will raise a RequestException. Depending# on your application's needs, this may be a non-error and can be caught# by the caller.response.raise_for_status()@app.route('/')deftrack_example():track_event(category='Example',action='test action')return'Event tracked.'

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.