Google Analytics

Measurement Protocol Developer Guide

This document describes how to send common hits to the Measurement Protocol.

  1. Overview
  2. Sending Required Values
  3. Sending Common Hit Types
    1. Page Tracking
    2. Event Tracking
    3. Ecommerce Tracking
    4. Social Interactions
    5. Exception Tracking
    6. User Timing Tracking
    7. App / Screen Tracking
  4. Using a Proxy Server

Overview

This document demonstrates how to format HTTP requests to send common hit types to the Google Analytics Measurement Protocol. Read the:

Sending Required Values

To send user interaction data, make an HTTP POST request to this endpoint.

POST /collect HTTP/1.1
Host: www.google-analytics.com

payload_data

The following parameters are required for each payload:

v=1             // Version.
&tid=UA-XXXX-Y  // Tracking ID / Web property / Property ID.
&cid=555        // Anonymous Client ID.
&t=             // Hit Type.

Each payload must contain a valid hit type and each hit type has it's own set of required fields. So to send a pageview for the /home page, you would use the following payload:

v=1&tid=UA-XXXX-Y&cid=555&t=pageview&dp=%2Fhome

The sections below give examples of common hit types.

Sending Common Hit Types

Below are examples of how to send common hit types to Google Analytics. Besides these examples, you can mix and match various parameters to achieve new data relationships. For example, to understand on which page an event occurred, send the pagePath parameter, p, along with event tracking parameters as described below.

Read the parameter reference for a full list of all the parameters you can send to Google Analytics.

Page Tracking

v=1             // Version.
&tid=UA-XXXX-Y  // Tracking ID / Web property / Property ID.
&cid=555        // Anonymous Client ID.

&t=pageview     // Pageview hit type.
&dh=mydemo.com  // Document hostname.
&dp=/home       // Page.
&dt=homepage    // Title.

Event Tracking

v=1             // Version.
&tid=UA-XXXX-Y  // Tracking ID / Web property / Property ID.
&cid=555        // Anonymous Client ID.

&t=event        // Event hit type
&ec=video       // Event Category. Required.
&ea=play        // Event Action. Required.
&el=holiday     // Event label.
&ev=300         // Event value.

Ecommerce Tracking

To send ecommerce data, send one transaction hit to represent an entire transaction, then send an item hit for each item in the transaction. The transaction ID ti links all the hits together to represent the entire purchase.

Transaction Hit

v=1              // Version.
&tid=UA-XXXX-Y   // Tracking ID / Web property / Property ID.
&cid=555         // Anonymous Client ID.

&t=transaction   // Transaction hit type.
&ti=12345        // transaction ID. Required.
&ta=westernWear  // Transaction affiliation.
&tr=50.00        // Transaction revenue.
&ts=32.00        // Transaction shipping.
&tt=12.00        // Transaction tax.
&cu=EUR          // Currency code.

Item Hit

v=1              // Version.
&tid=UA-XXXX-Y   // Tracking ID / Web property / Property ID.
&cid=555         // Anonymous Client ID.

&t=item          // Item hit type.
&ti=12345        // Transaction ID. Required.
&in=sofa         // Item name. Required.
&ip=300          // Item price.
&iq=2            // Item quantity.
&ic=u3eqds43     // Item code / SKU.
&iv=furniture    // Item variation / category.
&cu=EUR          // Currency code.

Social Interactions

v=1             // Version.
&tid=UA-XXXX-Y  // Tracking ID / Web property / Property ID.
&cid=555        // Anonymous Client ID.

&t=social       // Social hit type.
&sa=like        // Social Action. Required.
&sn=facebook    // Social Network. Required.
&st=/home       // Social Target. Required.

Exception Tracking

v=1             // Version.
&tid=UA-XXXX-Y  // Tracking ID / Web property / Property ID.
&cid=555        // Anonymous Client ID.

&t=exception      // Exception hit type.
&exd=IOException  // Exception description.
&exf=1            // Exception is fatal?

User Timing Tracking

v=1             // Version.
&tid=UA-XXXX-Y  // Tracking ID / Web property / Property ID.
&cid=555        // Anonymous Client ID.

&t=timing       // Timing hit type.
&utc=jsonLoader // Timing category.
&utv=load       // Timing variable.
&utt=5000       // Timing time.
&utl=jQuery     // Timing label.

// These values are part of browser load times

&dns=100        // DNS load time.
&pdt=20         // Page download time.
&rrt=32         // Redirect time.
&tcp=56         // TCP connect time.
&srt=12         // Server response time.

App / Screen Tracking

v=1                        // Version.
&tid=UA-XXXX-Y             // Tracking ID / Web property / Property ID.
&cid=555                   // Anonymous Client ID.

&t=screenview              // Screenview hit type.
&an=funTimes               // App name.
&av=4.2.0                  // App version.
&aid=com.foo.App           // App Id.
&aiid=com.android.vending  // App Installer Id.

&cd=Home                   // Screen name / content description.

Using a Proxy Server

Some environments are not able to send hits to Google Analytics directly. Examples of this are older mobile phones that can't run JavaScript or corporate intranets behind a firewall. In these cases it's common to send requests to a proxy server that then uses the Measurement Protocol to forward the hits on to Google Analytics.

To collect the IP and user agent from the client device and not the proxy server, you can specify both values in the measurement protocol, and they will override the values Google Analytics normally obtains from the request headers.

v=1             // Version.
&tid=UA-XXXX-Y  // Tracking ID / Web property / Property ID.
&cid=555        // Anonymous Client ID.

&t=pageview     // Pageview hit type.
&uip=1.2.3.4    // IP address override.
&ua=Opera/9.80  // User agent override.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.