Creating and validating measurement protocol requests through postman
This article is related to measurement protocol in Google Analytics.
If you are brand new to measurement protocol, then read this article first: Understanding Google Analytics measurement protocol.
In this article, I will show you how to send payload data both via GET and POST methods and how to send multiple hits in a single protocol request.
Creating a measurement protocol request
The GA measurement protocol hit builder allows you to send payload data only via the POST method. It won’t let you send payload data via the GET method.
It does not allow you to send multiple hits in a single protocol request. And above all, it does not provide you with the actual code for creating the protocol request.
You can overcome these limitations, by using the Postman Chrome extension.
Through the Postman extension, you can:
- Send payload data both via GET and POST method.
- Send multiple hits in a single protocol request.
- Create the actual code, for creating the measurement protocol request.
In order to understand the usage of this tool, let us try to achieve, the following objectives:
- Send single event hit in protocol request using the GET method
- Send single event hit in protocol request using the POST method
- Send multiple event hits in the protocol request using the POST method.
#1 Sending single event hit in protocol request using the GET method
Follow the steps below:
Step-1: Install the postman chrome extension and then launch it.
Step-2: Append the transport https://www.google-analytics.com/collect? with your payload data. For example:
If your payload data is:
v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-10&ea=play&el=spider%2520man1&ev=100
Then after appending it with the transport: https://www.google-analytics.com/collect? , it will look like the one below:
https://www.google-analytics.com/collect?v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-10&ea=play&el=spider%2520man1&ev=100
Step-3: Select GET method from the drop-down menu and then copy-paste your transport and payload data into the text box (next to the drop-down menu) as shown below:
Step-4: Click on the Send button (shown above).
Step-5: Navigate to Real Time > Events report in Google Analytics to see the event data:
Step-6: Click on the ‘Generate Code’ link in postman tool:
Step-7: Select the programming language, you want to use for creating the measurement protocol request:
Through Postman, you can generate code in several languages including Go, JavaScript, PHP, Python, Ruby, etc.
For example, following is the code for generating measurement protocol request in JQuery:
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.google-analytics.com/collect?v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-10&ea=play&el=spider%252520man1&ev=100",
"method": "GET",
"headers": {
"cache-control": "no-cache",
"postman-token": "cc64366c-34a2-3a5d-656c-a0243cee3881"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
Step-8: Copy this code and send it to your web developer for implementation.
That’s how you can send single event hit in measurement protocol request using the GET method
#2 Sending single event hit in measurement protocol request using the POST method
To send an event hit via POST method, just select POST from the drop-down menu of postman tool:
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.google-analytics.com/collect?v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-10&ea=play&el=spider%252520man1&ev=100",
"method": "POST",
"headers": {
"cache-control": "no-cache",
"postman-token": "d935a8a7-41dd-15f4-ddb0-17c910c96819"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
The rest of the process, of sending the event hit data is the same as in the case of GET method.
#3 Sending multiple event hits in the measurement protocol request using the POST method.
Follow the steps below:
Step-1: Select POST from the drop-down menu of the Postman tool:
Note: Do not use the GET method for sending multiple hits in a single protocol request. It won’t work.
Step-2: Enter the transport https://www.google-analytics.com/batch? in the text box, next to the drop-down menu, as shown below:
Step-3: Click on the ‘Body’ link (shown above) and then the ‘raw’ button (shown below), and then enter your payload for each hit, each payload on its own line:
Step-4: Click on the Send button (shown above).
Step-5: Navigate to Real Time > Events report in Google Analytics to see the event data. You will see three event hits at the same time in real-time reports:
Step-6: Click on the ‘Generate Code’ link in the Postman tool, select the programming language, you want to use for creating a measurement protocol request, copy this code and send it to your web developer for implementation.
For example, following is the code for generating multiple hits, in a single measurement protocol request using JQuery:
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.google-analytics.com/batch",
"method": "POST",
"headers": {
"cache-control": "no-cache",
"postman-token": "0a0530d3-b7de-f031-0911-d28c10c28534"
},
"data": "v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-1&ea=play&el=spider%2520man1&ev=100\r\nv=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-2&ea=play&el=spider%2520man2&ev=100\r\nv=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-3&ea=play&el=spider%2520man3&ev=100\r\n"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
That’s how you can send multiple hits in a single measurement protocol request using the POST method.
Other articles on measurement protocol
- Sending pageview data via measurement protocol in Google Analytics
- Sending campaign data via measurement protocol in Google Analytics
- Sending event data via measurement protocol in Google Analytics
- Sending ecommerce data via measurement protocol in Google Analytics
- Sending social interactions via measurement protocol in Google Analytics
- Understanding measurement protocol validation server
This article is related to measurement protocol in Google Analytics.
If you are brand new to measurement protocol, then read this article first: Understanding Google Analytics measurement protocol.
In this article, I will show you how to send payload data both via GET and POST methods and how to send multiple hits in a single protocol request.
Creating a measurement protocol request
The GA measurement protocol hit builder allows you to send payload data only via the POST method. It won’t let you send payload data via the GET method.
It does not allow you to send multiple hits in a single protocol request. And above all, it does not provide you with the actual code for creating the protocol request.
You can overcome these limitations, by using the Postman Chrome extension.
Through the Postman extension, you can:
- Send payload data both via GET and POST method.
- Send multiple hits in a single protocol request.
- Create the actual code, for creating the measurement protocol request.
In order to understand the usage of this tool, let us try to achieve, the following objectives:
- Send single event hit in protocol request using the GET method
- Send single event hit in protocol request using the POST method
- Send multiple event hits in the protocol request using the POST method.
#1 Sending single event hit in protocol request using the GET method
Follow the steps below:
Step-1: Install the postman chrome extension and then launch it.
Step-2: Append the transport https://www.google-analytics.com/collect? with your payload data. For example:
If your payload data is:
v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-10&ea=play&el=spider%2520man1&ev=100
Then after appending it with the transport: https://www.google-analytics.com/collect? , it will look like the one below:
https://www.google-analytics.com/collect?v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-10&ea=play&el=spider%2520man1&ev=100
Step-3: Select GET method from the drop-down menu and then copy-paste your transport and payload data into the text box (next to the drop-down menu) as shown below:
Step-4: Click on the Send button (shown above).
Step-5: Navigate to Real Time > Events report in Google Analytics to see the event data:
Step-6: Click on the ‘Generate Code’ link in postman tool:
Step-7: Select the programming language, you want to use for creating the measurement protocol request:
Through Postman, you can generate code in several languages including Go, JavaScript, PHP, Python, Ruby, etc.
For example, following is the code for generating measurement protocol request in JQuery:
var settings = { "async": true, "crossDomain": true, "url": "https://www.google-analytics.com/collect?v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-10&ea=play&el=spider%252520man1&ev=100", "method": "GET", "headers": { "cache-control": "no-cache", "postman-token": "cc64366c-34a2-3a5d-656c-a0243cee3881" } } $.ajax(settings).done(function (response) { console.log(response); });
Step-8: Copy this code and send it to your web developer for implementation.
That’s how you can send single event hit in measurement protocol request using the GET method
#2 Sending single event hit in measurement protocol request using the POST method
To send an event hit via POST method, just select POST from the drop-down menu of postman tool:
var settings = { "async": true, "crossDomain": true, "url": "https://www.google-analytics.com/collect?v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-10&ea=play&el=spider%252520man1&ev=100", "method": "POST", "headers": { "cache-control": "no-cache", "postman-token": "d935a8a7-41dd-15f4-ddb0-17c910c96819" } } $.ajax(settings).done(function (response) { console.log(response); });
The rest of the process, of sending the event hit data is the same as in the case of GET method.
#3 Sending multiple event hits in the measurement protocol request using the POST method.
Follow the steps below:
Step-1: Select POST from the drop-down menu of the Postman tool:
Note: Do not use the GET method for sending multiple hits in a single protocol request. It won’t work.
Step-2: Enter the transport https://www.google-analytics.com/batch? in the text box, next to the drop-down menu, as shown below:
Step-3: Click on the ‘Body’ link (shown above) and then the ‘raw’ button (shown below), and then enter your payload for each hit, each payload on its own line:
Step-4: Click on the Send button (shown above).
Step-5: Navigate to Real Time > Events report in Google Analytics to see the event data. You will see three event hits at the same time in real-time reports:
Step-6: Click on the ‘Generate Code’ link in the Postman tool, select the programming language, you want to use for creating a measurement protocol request, copy this code and send it to your web developer for implementation.
For example, following is the code for generating multiple hits, in a single measurement protocol request using JQuery:
var settings = { "async": true, "crossDomain": true, "url": "https://www.google-analytics.com/batch", "method": "POST", "headers": { "cache-control": "no-cache", "postman-token": "0a0530d3-b7de-f031-0911-d28c10c28534" }, "data": "v=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-1&ea=play&el=spider%2520man1&ev=100\r\nv=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-2&ea=play&el=spider%2520man2&ev=100\r\nv=1&t=event&tid=UA-1500844-18&cid=98880ed4-c224-4b3c-b2e2-35a491373751&ec=videos-3&ea=play&el=spider%2520man3&ev=100\r\n" } $.ajax(settings).done(function (response) { console.log(response); });
That’s how you can send multiple hits in a single measurement protocol request using the POST method.
Other articles on measurement protocol
- Sending pageview data via measurement protocol in Google Analytics
- Sending campaign data via measurement protocol in Google Analytics
- Sending event data via measurement protocol in Google Analytics
- Sending ecommerce data via measurement protocol in Google Analytics
- Sending social interactions via measurement protocol in Google Analytics
- Understanding measurement protocol validation server
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.