Hide

Measurement Protocol Developer Guide

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-XXXX-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 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 / 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 / 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.

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-XXXX-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.

Measuring Actions

v=1                                  // Version.
&tid=UA-XXXX-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.
    

Combining Impressions and Actions

v=1                                  // Version.
&tid=UA-XXXX-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.
   

Measuring Purchases

v=1                                  // Version.
&tid=UA-XXXX-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.
    

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-XXXX-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.
    
// Refund a single product.
v=1                                  // Version.
&tid=UA-XXXX-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.
    

Measuring the Checkout Process

1. Measuring Checkout Steps
v=1                                  // Version.
&tid=UA-XXXX-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.
    
2. Measuring Checkout Options
v=1                                  // Version.
&tid=UA-XXXX-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.
    

Measuring Internal Promotions

Promotion Impressions
v=1                                     // Version.
&tid=UA-XXXX-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.
    
Promotion Clicks
v=1                                  // Version.
&tid=UA-XXXX-Y                       // Tracking ID / Property ID.
&cid=555                             // Anonymous Client ID.
&t=event                             // Event hit type
&ec=Internal%Promotions              // 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.
    

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 / 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 / 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 / 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 / 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 / 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 / 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 / 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.