Working with the Measurement Protocol

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

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-XXXXX-Y  // Tracking ID / Property ID.
&cid=555         // Anonymous Client ID.
&t=              // Hit Type.

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

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

The sections below give examples of common hit types.

Batching multiple hits in a single request

To send multiple hits in a single request, use the /batch endpoint instead of /collect and specify each payload on its own line.

For example, to send pageview hits for the "Home", "About Us", and "Contact" pages of a website, you could send the following batch request.

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

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

Batch limitations

In addition to the standard limitations of Measurement Protocol hits, batch requests have the following additional limitations:

  • A maximum of 20 hits can be specified per request.
  • The total size of all hit payloads cannot be greater than 16K bytes.
  • No single hit payload can be greater than 8K bytes.

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-XXXXX-Y  // Tracking ID / Property ID.
&cid=555         // Anonymous Client ID.

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

View this hit in the Measurement Protocol Hit Builder.

Event Tracking

v=1              // Version.
&tid=UA-XXXXX-Y  // Tracking ID / 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.

View this hit in the Measurement Protocol Hit Builder.

Enhanced Ecommerce Tracking

Enhanced Ecommerce hits should be used in place of Ecommerce hits. If you've already implemented Ecommerce tracking and want to start using Enhanced Ecommerce tracking there are two options:

Use a new property

You can create a new property and send Enhanced Ecommerce hits to the new property.

Migrate an existing property

Migrate any Ecommerce hits to Enhanced Ecommerce hits, following the examples below. Transaction and item data previously collected using Ecommerce hits will not be affected and will remain available in the properties and views to which they were originally sent.

Measuring Impressions

v=1                                      // Version.
&tid=UA-XXXXX-Y                          // Tracking ID / Property ID.
&cid=555                                 // Anonymous Client ID.
&t=pageview                              // Pageview hit type.
&dh=mydemo.com                           // Document hostname.
&dp=/home                                // Page.
&dt=homepage                             // Title.

&il1nm=Search%20Results                  // Impression list 1. Required.
&il1pi1id=P12345                         // Product Impression 1 ID. Either ID or name must be set.
&il1pi1nm=Android%20Warhol%20T-Shirt     // Product Impression 1 name. Either ID or name must be set.
&il1pi1ca=Apparel%2FT-Shirts             // Product Impression 1 category.
&il1pi1br=Google                         // Product Impression 1 brand.
&il1pi1va=Black                          // Product Impression 1 variant.
&il1pi1ps=1                              // Product Impression 1 position.
&il1pi1cd1=Member                        // Custom dimension.

&il2nm=Recommended%20Products            // Impression list 2.
&il2pi1nm=Yellow%20T-Shirt               // Product Impression 1 name.
&il2pi2nm=Red%20T-Shirt                  // Product Impression 2 name.

View this hit in the Measurement Protocol Hit Builder.

Measuring Actions

v=1                                   // Version.
&tid=UA-XXXXX-Y                       // Tracking ID / Property ID.
&cid=555                              // Anonymous Client ID.
&t=event                              // Event hit type.
&ec=UX                                // Event Category. Required.
&ea=click                             // Event Action. Required.
&el=Results                           // Event label.

&pa=click                             // Product action (click). Required.
&pal=Search%20Results                 // Product Action List.
&pr1id=P12345                         // Product 1 ID. Either ID or name must be set.
&pr1nm=Android%20Warhol%20T-Shirt     // Product 1 name. Either ID or name must be set.
&pr1ca=Apparel                        // Product 1 category.
&pr1br=Google                         // Product 1 brand.
&pr1va=Black                          // Product 1 variant.
&pr1ps=1                              // Product 1 position.
    

View this hit in the Measurement Protocol Hit Builder.

Combining Impressions and Actions

v=1                                   // Version.
&tid=UA-XXXXX-Y                       // Tracking ID /  Property ID.
&cid=555                              // Anonymous Client ID.
&t=event                              // Event hit type.
&ec=UX                                // Event Category. Required.
&ea=click                             // Event Action. Required.
&el=Results                           // Event label.

&pa=detail                            // Product action (detail). Required.
&pr1id=P12345                         // Product 1 ID. Either ID or name must be set.
&pr1nm=Android%20Warhol%20T-Shirt     // Product 1 name. Either ID or name must be set.
&pr1ca=Apparel                        // Product 1 category.
&pr1br=Google                         // Product 1 brand.
&pr1va=Black                          // Product 1 variant.
&pr1ps=1                              // Product 1 position.

&il1nm=Related%20Products             // Impression list.
&il1pi1id=P12345                      // Product Impression 1 ID.
&il1pi1nm=Android%20Warhol%20T-Shirt  // Product Impression 1 name.
&il1pi1ca=Apparel%2FT-Shirts          // Product Impression 1 category.
&il1pi1br=Google                      // Product Impression 1 brand.
&il1pi1va=Black                       // Product Impression 1 variant.
&il1pi1ps=1                           // Product Impression 1 position.
   

View this hit in the Measurement Protocol Hit Builder.

Measuring Purchases

v=1                                   // Version.
&tid=UA-XXXXX-Y                       // Tracking ID / Property ID.
&cid=555                              // Anonymous Client ID.
&t=pageview                           // Pageview hit type.
&dh=mydemo.com                        // Document hostname.
&dp=/receipt                          // Page.
&dt=Receipt%20Page                    // Title.

&ti=T12345                            // Transaction ID. Required.
&ta=Google%20Store%20-%20Online       // Affiliation.
&tr=37.39                             // Revenue.
&tt=2.85                              // Tax.
&ts=5.34                              // Shipping.
&tcc=SUMMER2013                       // Transaction coupon.

&pa=purchase                          // Product action (purchase). Required.
&pr1id=P12345                         // Product 1 ID. Either ID or name must be set.
&pr1nm=Android%20Warhol%20T-Shirt     // Product 1 name. Either ID or name must be set.
&pr1ca=Apparel                        // Product 1 category.
&pr1br=Google                         // Product 1 brand.
&pr1va=Black                          // Product 1 variant.
&pr1ps=1                              // Product 1 position.
    

View this hit in the Measurement Protocol Hit Builder.

Measuring Refunds

If you need to send refund data using an event and the event is not part of normally measured onsite behavior (i.e. not user initiated), then it’s recommended that you send a non-interaction event. This will prevent metrics such as bounce rate, session duration, etc. from being affected by the event.

 // Refund an entire transaction and send with a non-interaction event.
v=1                                   // Version.
&tid=UA-XXXXX-Y                       // Tracking ID / Property ID.
&cid=555                              // Anonymous Client ID.
&t=event                              // Event hit type.
&ec=Ecommerce                         // Event Category. Required.
&ea=Refund                            // Event Action. Required.
&ni=1                                 // Non-interaction parameter.

&ti=T12345                            // Transaction ID. Required.
&pa=refund                            // Product action (refund). Required.
    

View this hit in the Measurement Protocol Hit Builder.

 // Refund a single product.
v=1                                   // Version.
&tid=UA-XXXXX-Y                       // Tracking ID / Property ID.
&cid=555                              // Anonymous Client ID.
&t=event                              // Event hit type.
&ec=Ecommerce                         // Event Category. Required.
&ea=Refund                            // Event Action. Required.
&ni=1                                 // Non-interaction parameter.

&ti=T12345                            // Transaction ID. Required.
&pa=refund                            // Product action (refund). Required.
&pr1id=P12345                         // Product 1 ID. Required.
&pr1qt=1                              // Product 1 quantity. Required.
    

View this hit in the Measurement Protocol Hit Builder.

Measuring the Checkout Process

1. Measuring Checkout Steps
v=1                                   // Version.
&tid=UA-XXXXX-Y                       // Tracking ID / Property ID.
&cid=555                              // Anonymous Client ID.
&t=pageview                           // Pageview hit type.
&dh=mydemo.com                        // Document hostname.
&dp=/checkout                         // Page.
&dt=Checkout                          // Title.

&pa=checkout                          // Product action (checkout).
&pr1id=P12345                         // Product 1 ID. Either ID or name must be set.
&pr1nm=Android%20Warhol%20T-Shirt     // Product 1 name. Either ID or name must be set.
&pr1ca=Apparel                        // Product 1 category.
&pr1br=Google                         // Product 1 brand.
&pr1va=Black                          // Product 1 variant.
&pr1pr=29.20                          // Product 1 Price.
&pr1qt=1                              // Product 1 quantity.
&cos=1                                // Checkout step #1.
&col=Visa                             // Checkout step option.
    

View this hit in the Measurement Protocol Hit Builder.

2. Measuring Checkout Options
v=1                                   // Version.
&tid=UA-XXXXX-Y                       // Tracking ID / Property ID.
&cid=555                              // Anonymous Client ID.
&t=event                              // Event hit type
&ec=Checkout                          // Event Category. Required.
&ea=Option                            // Event Action. Required.

&pa=checkout_option                   // Product action (checkout_option).
&cos=2                                // Checkout step.
&col=FedEx                            // Checkout step option.
    

View this hit in the Measurement Protocol Hit Builder.

Measuring Internal Promotions

Promotion Impressions
v=1                                      // Version.
&tid=UA-XXXXX-Y                          // Tracking ID / Property ID.
&cid=555                                 // Anonymous Client ID.
&t=pageview                              // Pageview hit type.
&dh=mydemo.com                           // Document hostname.
&dp=/home                                // Page.
&dt=homepage                             // Title.

&promo1id=PROMO_1234                     // Promotion 1 ID. Either ID or name must be set.
&promo1nm=Summer%20Sale                  // Promotion 1 name. Either ID or name must be set.
&promo1cr=summer_banner2                 // Promotion Creative.
&promo1ps=banner_slot1                   // Promotion Position.
    

View this hit in the Measurement Protocol Hit Builder.

Promotion Clicks
v=1                                   // Version.
&tid=UA-XXXXX-Y                       // Tracking ID / Property ID.
&cid=555                              // Anonymous Client ID.
&t=event                              // Event hit type
&ec=Internal%20Promotions             // Event Category. Required.
&ea=click                             // Event Action. Required.
&el=Summer%20Sale                     // Event label.

&promoa=click                         // Promotion action (click). Required.
&promo1id=PROMO_1234                  // Promotion 1 ID. Either ID or name must be set.
&promo1nm=Summer%20Sale               // Promotion 1 name. Either ID or name must be set.
&promo1cr=summer_banner2              // Promotion Creative.
&promo1ps=banner_slot1                // Promotion Position.
    

View this hit in the Measurement Protocol Hit Builder.

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-XXXXX-Y   // Tracking ID / 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.

View this hit in the Measurement Protocol Hit Builder.

Item Hit

v=1               // Version.
&tid=UA-XXXXX-Y   // Tracking ID / 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.

View this hit in the Measurement Protocol Hit Builder.

Social Interactions

v=1              // Version.
&tid=UA-XXXXX-Y  // Tracking ID / 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.

View this hit in the Measurement Protocol Hit Builder.

Exception Tracking

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

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

View this hit in the Measurement Protocol Hit Builder.

User Timing Tracking

v=1              // Version.
&tid=UA-XXXXX-Y  // Tracking ID / 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.

View this hit in the Measurement Protocol Hit Builder.

App / Screen Tracking

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

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

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

View this hit in the Measurement Protocol Hit Builder.

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-XXXXX-Y  // Tracking ID / 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.

View this hit in the Measurement Protocol Hit Builder.