Google Analytics Cheatsheet

Google Analytics lets you measure your end user interactions on your websites and mobile apps. Google Analytics records all interactions and provides meaningful insights.

Available Platforms

  1. Web
  2. Android
  3. iOS

Adding Google Analytics to your Web application

Google analytics can be added to web applications by including the following script in head tag.

<!-- Google Analytics-->
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', 'UA-xxxxx-x', 'auto');
  ga('send', 'pageview');

Adding Google Analytics to your Android application

1. Add google-services to your build.gradle

dependencies {
  classpath ''

2. Add play-services-analytics to your app/build.gradle

dependencies {
  compile ''

3. Create app/src/res/xml/global_tracker.xml to configure your Google Analytics tracker id

<?xml version="1.0" encoding="utf-8"?>
  <string name="ga_trackingId" translatable="false">UA-xxxxx-x</string>

4. Create AnalyticsApplication by extending


public class AnalyticsApplication extends Application {
  private static GoogleAnalytics googleAnalytics;
  private static Tracker tracker;

  public void onCreate() {
    googleAnalytics = GoogleAnalytics.getInstance(this);

  synchronized public Tracker getDefaultTracker() {
    if (tracker == null) {
      tracker = googleAnalytics.newTracker(R.xml.global_tracker);
    return tracker;

5. Start tracking your activities

AnalyticsApplication application = (AnalyticsApplication) getApplication();
tracker = application.getDefaultTracker();
tracker.send(new HitBuilders.ScreenViewBuilder().build());

┬ęCopyright 2020 OneCompiler | Privacy Policy | Terms & Conditions