Through this protocol, you can collect and send raw user interaction data (hits) directly to GA server from any device/system which can be connected to the internet. This device/system can be a smartphone, tablet PC, digital appliances (washing machine, coffee machine, slot machine), point of purchase systems, etc.
However, you need to format your data according to the measurement protocol before you can send it to the Google Analytics server. So for example, if you want to send data from your washing machine to the Google Analytics server, then you first need to format the data according to the measurement protocol.
Similarly, if you want to send data from a cash counter machine, coffee machine or slot machine then you first need to format the data according to the measurement protocol.
Without such formatting, you can’t send data to GA.
Through measurement protocol, you can measure offline conversions in GA.
Thus it helps in understanding the offline behavior of the customers and helps fix attribution modelling issues.
Note: You don’t need measurement protocol if you just want to send hit data from a website or mobile app. Use the Google Analytics tracking code for website/mobile app for that purpose.
You can collect and send only hit data (pageviews, screenviews, events, transactions etc) via the measurement protocol.
You can’t collect and send data in aggregated form (like tables) via measurement protocol.
In order to understand the measurement protocol request, you first need to understand HTTP Requests and HTTP Responses.
All web browsers and web servers communicate with each other by sending HTTP requests and HTTP responses.
A web browser communicates with a web server by sending an HTTP request for each requested resource (like HTML document, image, CSS, etc).
The web server communicates back to the web browser by sending an HTTP response for each HTTP request.
Here is how HTTP request looks like:
Here is how HTTP response looks like:
To see HTTP requests and responses, follow the steps below:
Step-1: Open Google Chrome browser.
Step-2: Navigate to a web page.
Step-3: Right-click on the page and then click on ‘Inspect’ from the drop-down menu. This will open up the ‘Chrome Developers Tool’.
Step-4: Click on the ‘Network’ tab:
On the right-hand side of the developers’ window, you can see all the HTTP request and response headers.
Measurement Protocol Request
In order to make an HTTP request to the GA server (for sending the raw hit data directly), you need to format your HTTP request according to the measurement protocol.
This formatted HTTP request is called the measurement protocol request.
Here is how the measurement protocol request looks like:
The measurement protocol request is made up of user-agent, transport and payload data:
To see the measurement protocol request, follow the steps below:
Step-1: Open Google Chrome browser.
Step-2: Navigate to the web page which has the Google Analytics tracking code installed.
Step-3: Right-click on the page and then click on ‘Inspect’ from the drop-down menu. This will open up the ‘Chrome Developers Tool’.
Step-4: Click on the ‘Network‘ tab:
Step-5: To see the measurement protocol request, type ‘collect’ in the text box (shown below) and then press the enter key.
On the right-hand side of the developers’ window, you can see the measurement protocol request:
Introduction to User-Agent
User-agent is a string that your web browser sends to a web server, in order to identify itself.
Following is an example of user-agent:
Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36
You can see the user-agent in an HTTP Request:
Introduction to Payload Data
Payload data is the data you send to the Google Analytics server using the measurement protocol. In other words, the payload data is the data which has been formatted according to Measurement Protocol.
The payload data resembles a URL query string (query string is the part of the URL which comes after the ‘?’ Character).
Payload data is made up of multiple parameters. Each parameter is made up of ‘key = value’ pairs.
Types of Payloads
There are two types of payloads:
#1 Single hit payload – the payload data in which only one hit is sent to the GA server.
#2 Multiple hits payload – the payload data in which multiple hits are sent to the GA server.
Note: The size of a single hit payload cannot be greater than 8k bytes.
Introduction to Transport
Transport defines where and how to send the payload data. Following is an example of transport:
POST http://www.google-analytics.com/collect
Transport is made up of:
#1 GET/POST method – which defines how to send the payload data
#2 Location of the GA server – which defines where to send the payload data
#3 URL endpoint – this is used to define whether a single or multiple hits should be sent to the GA server or whether to send the payload data to the measurement protocol validation server.
Measurement Protocol Rules
Measurement protocol rules are the rules regarding:
Formatting the protocol requests
Length and format of the payload data
Length and format of each parameter
Parameters which can be sent together and which can’t be sent together
Parameters which are required for particular hit type.
Parameters which can be sent for a particular hit type.
Allowed key and value pairs
Valid keys
Valid hit types
Length and format of each value
Supported data types
Format of transport
How to Use Measurement Protocol
To use the measurement protocol, you need to do the following three things:
#1 Ask your developer to write an application (program) that can pull data from your desired external data source (like a point of purchase system etc):
#2 Your application must convert the retrieved data into the payload data according to the measurement protocol:
#3 Your application must make a HTTP POST/GET request to the endpoint (Google Analytics server) in order to send the payload data to the GA server. The HTTP request should be made up of user agent, transport and payload data:
When GA receives the HTTP request from your application, it tries to process the payload data in the HTTP request.
If GA successfully processes the payload data then its server will send 2XX response code back to your application:
If GA is not successful, in processing the payload data, then its server does not send any error code back to your application.
The diagram below illustrates the whole process of creating a measurement protocol hit:
Measurement Protocol Usage Policy
According to the measurement protocol usage policy set by Google, you should use measurement protocol only when:
You have the permission to use it, from the rightful owners.
You are not going to collect any personally identifiable information (names, email addresses) or any data that can help in identifying a particular user by his/her device.
You have given your end-users, proper notice about the data you are collecting via the measurement protocol and how you will use the data, as well as the option to opt-out from being tracked.
Measurement Protocol Parameters
Payload data is made up of multiple parameters.
Each parameter is separated from another parameter via & character.
Since each parameter is made up of ‘key = value‘ pairs, each ‘key=value’ pair is separated by ‘&’ character.
Note (2): All protocol parameters must be set on the same line. They should not have any spaces between them. Comments are not allowed in protocol parameters.
Measurement Protocol Supported Data Types
The measurement protocol supports the following data types for the values in the ‘key = value’ pairs of the payload data:
Integer – used to represent a number
Text – used to represent a string
Boolean – used to represent a boolean value (true or false)
Currency – used to represent the total value of a currency in up to 6 decimal points.
Required Parameters for Payload Data
Each payload data must contain the following parameters:
#1 Measurement Protocol Version
‘v’ is used to denote the measurement protocol version.
The value of this parameter can be be anyone of the following: ‘pageview’, ‘event’, ‘social’, ‘transaction’, ‘item’, ‘exception’,’appview’ or ‘timing’.
There are rules regarding which parameters can be sent together and which parameters can’t be sent together. There are rules regarding the length and format of parameters.
Each parameter has a specific type that requires a particular format.
Each payload data must contain a valid hit type. Each hit type must have its own set of required parameters set.
For more details, regarding these rules, refer to:
Document Referrer. It is the referral source which sent traffic to your website.
The value of this parameter should be a URL (URL encoded)
dr=http%3A%2F%2Fabc.com
All values of the parameters must be URL encoded before they are sent to the Google Analytics server. For this reason the URL https://abc.com was first encoded to http%3A%2F%2Fabc.com before it is passed as a value to the ‘dr’ parameter.
2
cn
campaign name
The value of this parameter should be a URL encoded text string.
cn=attribution
3
cs
campaign source
URL encoded text string.
cs=%28direct%29
Here the campaign source is ‘(direct)’. But when the text string is URL encoded the opening parenthesis ‘(‘ is replaced by ‘%28’ and the closing parenthesis is replaced by ‘%29’
4
cm
campaign medium
URL encoded text string.
cm=organic
5
ck
campaign keyword
URL encoded text string
ck=event%20education
6
cc
campaign content
URL encoded text string
cc=top%20left
7
dl
document location,
the full URL of the page which contains the contents.
You can send payload data by either using the GET method or POST method.
Google recommends using POST method, as then you can send larger payload data to GA server.
The location of the GA server is: https://www.google-analytics.com
This is where we send the payload data.
The payload data need to be URL encoded if you are making HTTP POST request to the GA server.
The size of Payload data, if you are making HTTP POST request to the GA server can be maximum of 8191 Bytes. However, if you make HTTP GET request to the GA server, then the size of payload data cannot be more than 2000 Bytes.
Write your application to make the following similar HTTP POST request to the GA server in order to send the payload data:
User-Agent: user_agent_string
POST https://www.google-analytics.com/collect?payload_data
Sending Payload Data via the GET Method
If you can’t send payload data via HTTP POST request then write your application to make the following similar HTTP GET requests to the GA server, in order to send the payload data:
GET /collect?payload_data HTTP/1.1
Host: https://www.google-analytics.com
User-Agent: user_agent_string
How to Prevent HTTP GET Requests From Being Cached
Another downside (the first downside is the inability to send large payload data) of making an HTTP GET request to the GA server is that, GET request may get cached and when it get cached, the request is no longer unique and hence subsequent requests are retrieved from the cache and not sent to GA.
To prevent HTTP GET requests from being cached, add the parameter called ‘Z’ at the end of the payload data.
You can use validate measurement protocol hits via:
#1 Chrome developer tool – You can use the ‘console’ or ‘network’ tab of the chrome developer tool, to see the details of the measurement protocol hits, as explained earlier.
Note: GA hit builder use only one URL end point, /collect
#3 Postman chrome extension – Through this extension, you can send payload data via GET or POST method. The GA hit builder allows you to send payload data only via POST method. Through postman extension you can also:
# test sending payload data over secure connection.
# send payload data by using a different URL end point (/debug/collect or /batch)
Frequently asked questions about Measurement Protocol in Google Analytics
What is measurement protocol?
Measurement protocol is a set of rules which your application must follow in order to send raw hit data directly to the Google Analytics server. Measurement protocol is used and beneficial for implementing cross-device tracking.
What data can be collected via measurement protocol?
You can collect and send only hit data (pageviews, screenviews, events, transactions, etc) via the measurement protocol. You can’t collect and send data in aggregated form (like tables) via measurement protocol.
What does a measurement protocol request consist of?
The measurement protocol request is made up of user-agent, transport and payload data.
User-agent is a string that your web browser sends to a web server, in order to identify itself. Transport defines where and how to send the payload data. Payload data is the data you send to the Google Analytics server, formatted according to measurement protocol.
How do you send payload data?
You can send payload data by either using the GET method or POST method. Google recommends using POST method, as then you can send larger payload data to GA server.
Can you send multiple hits in a single measurement protocol request?
Yes, you can use the ‘/batch’ endpoint to send multiple hits in a single HTTP request.
When you are sending multiple hits in a single HTTP request then specify each payload on its own line. The HTTP request which contains /batch end point is called the Batch request. You can send maximum of 20 hits at a time per batch request. The total size of the payload data in a batch request cannot be greater than 16k bytes.
Register for the FREE TRAINING...
"How to use Digital Analytics to generate floods of new Sales and Customers without spending years figuring everything out on your own."
Here’s what we’re going to cover in this training…
#1 Why digital analytics is the key to online business success.
#2 The number 1 reason why most marketers are not able to scale their advertising and maximize sales.
#3 Why Google and Facebook ads don’t work for most businesses & how to make them work.
#4 Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.
#5 The number 1 reason why conversion optimization is not working for your business.
#6 How to advertise on any marketing platform for FREE with an unlimited budget.
#7 How to learn and master digital analytics and conversion optimization in record time.
My best selling books on Digital Analytics and Conversion Optimization
Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.
Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.
Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.
Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.
About the Author
Himanshu Sharma
Founder, OptimizeSmart.com
Over 15 years of experience in digital analytics and marketing
Author of four best-selling books on digital analytics and conversion optimization
Nominated for Digital Analytics Association Awards for Excellence
Runs one of the most popular blogs in the world on digital analytics
Consultant to countless small and big businesses over the decade
Learn and Master Google Analytics 4 (GA4) - 126 pages ebook
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.