Measurement protocol for Google Analytics 4 (GA4) is a set of rules which your application must follow in order to send event data directly to the Google Analytics servers from any device/system which can be connected to the internet.
This device can be a POS (point of purchase systems), cash counter machine, slot machine etc.
However, you would need to format your event data according to the measurement protocol before you can send it to the Google Analytics server. Without such formatting, you can’t send event data to GA4.
Through measurement protocol, you can implement cross-device tracking and measure offline conversions online.
Thus the use of measurement protocol helps in understanding the purchase journey of your customers and in fixing online-offline attribution issues.
Note: You don’t need measurement protocol if you just want to send event data from your website or mobile app. Use gtag.js or Google Tag Manager for that purpose.
The basic understanding of how measurement protocol works can help you greatly in building your foundation in GA4 and in debugging GA4 events set up.
Introduction to Measurement Protocol Request
The measurement protocol request is the HTTP POST request your application makes to the Google Analytics server. This request is made every time your application wants to send a hit to the GA server.
We send raw event data to GA servers via a hit.
In order to see how a measurement protocol request looks like, follow the steps below:
Step-1: Navigate to your GA4 reporting view.
If you have not installed GA4 then check out this article: How to upgrade to Google Analytics 4 (GA4)
Step-2: Take a note of your measurement ID:
In order to find your measurement ID follow the steps mentioned in this article: Understanding Measurement ID in GA4 (Google Analytics 4)
Step-3: Open Google Chrome and then navigate to the web page where you have installed Google Analytics 4.
Step-4: Right-click on the web page and then select ‘Inspect’:
You should now see the Google developer console window:
Step-5: Click on the ‘Network‘ tab:
Step-6: Select the two checkboxes ‘Preserve log‘ and ‘Disable cache‘:
Step-7: Refresh your web page.
Your Google developer console window would now look, something like the one below:
Step-8: Enter your measurement ID in the ‘Filter’ text box:
All the network requests starting from collect?v= are measurement protocol requests.
Step-9: Click on one of the protocol requests. On the right-hand side of the developers’ window, you should now be able to see the full measurement protocol request:
Here is how the full measurement protocol request looks like:
“https://analytics.google.com/g/collect?v=2&tid=G-7KE5STV3EN>m=2oebu0&_p=1938363182&sr=1920×1080&ul=en-gb&cid=1589083120.1608140081&_s=1&dl=https%3A%2F%2Fwww.optimizesmart.com%2Fhow-to-import-conversions-from-ga4-property-to-your-google-ads-account%2F&dr=&dt=How%20to%20import%20conversions%20from%20GA4%20property%20to%20your%20Google%20Ads%20account%20-%20Optimize%20Smart&sid=1608140080&sct=1&seg=1&en=page_view”
Each measurement protocol request is made up of ‘transport’ and ‘payload data’.
Transport defines where and how to send the payload data.
Following is an example of transport:
https://analytics.google.com/g/collect
Here is how the transport looks like (highlighted text) in the measurement protocol request:
“https://analytics.google.com/g/collect?v=2&tid=G-7KE5STV3EN>m=2oebu0&_p=1938363182&sr=1920×1080&ul=en-gb&cid=1589083120.1608140081&_s=1&dl=https%3A%2F%2Fwww.optimizesmart.com%2Fhow-to-import-conversions-from-ga4-property-to-your-google-ads-account%2F&dr=&dt=How%20to%20import%20conversions%20from%20GA4%20property%20to%20your%20Google%20Ads%20account%20-%20Optimize%20Smart&sid=1608140080&sct=1&seg=1&en=page_view”
A Transport is made up of:
#1 POST method – which defines how to send the payload data.
#2 Location of the GA server – which defines where to send the payload data. For example https://analytics.google.com/g/
#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. Example of URL endpoints ‘/collect‘, ‘/debug‘, ‘/batch‘.
Payload data is the data you send to the Google Analytics server using the measurement protocol.
Following is an example of payload date
v=2&tid=G-7KE5STV3EN>m=2oebu0&_p=1938363182&sr=1920×1080&ul=en-gb&cid=1589083120.1608140081&_s=1&dl=https%3A%2F%2Fwww.optimizesmart.com%2Fhow-to-import-conversions-from-ga4-property-to-your-google-ads-account%2F&dr=&dt=How%20to%20import%20conversions%20from%20GA4%20property%20to%20your%20Google%20Ads%20account%20-%20Optimize%20Smart&sid=1608140080&sct=1&seg=1&en=page_vie
Here is how the payload data looks like (highlighted text) in the measurement protocol request:
https://analytics.google.com/g/collect?v=2&tid=G-7KE5STV3EN>m=2oebu0&_p=1938363182&sr=1920×1080&ul=en-gb&cid=1589083120.1608140081&_s=1&dl=https%3A%2F%2Fwww.optimizesmart.com%2Fhow-to-import-conversions-from-ga4-property-to-your-google-ads-account%2F&dr=&dt=How%20to%20import%20conversions%20from%20GA4%20property%20to%20your%20Google%20Ads%20account%20-%20Optimize%20Smart&sid=1608140080&sct=1&seg=1&en=page_view
As you can see, 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. 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.
Syntax of payload data:
parameter1¶meter2¶meter3
or
key1=value1&key2=value2&key3=value3
Now lets breakdown our payload data into ‘key=value’ pairs with each pair appearing on a separate line:
v=2
tid=G-7KE5STV3EN
gtm=2oebu0
_p=1938363182
sr=1920×1080
ul=en-gb
cid=1589083120.1608140081
_s=1
dl=https%3A%2F%2Fga4guide.com%2Fhow-to-import-conversions-from-ga4-property-to-your-google-ads-account%2F
dr=
dt=How%20to%20import%20conversions%20from%20GA4%20property%20to%20your%20Google%20Ads%20account%20-%20Optimize%20Smart&sid=1608140080
sct=1
seg=1
en=page_view
Here, the following are examples of keys (highlighted in bold text):
v=2
tid=G-7KE5STV3EN
gtm=2oebu0
_p=1938363182
sr=1920×1080
ul=en-gb
cid=1589083120.1608140081
_s=1
dl=https%3A%2F%2Fwww.optimizesmart.com%2Fhow-to-import-conversions-from-ga4-property-to-your-google-ads-account%2F
dr=
dt=How%20to%20import%20conversions%20from%20GA4%20property%20to%20your%20Google%20Ads%20account%20-%20Optimize%20Smart&sid=1608140080
sct=1
seg=1
en=page_view
The following are examples of values (highlighted in bold text):
v=2
tid=G-7KE5STV3EN
gtm=2oebu0
_p=1938363182
sr=1920×1080
ul=en-gb
cid=1589083120.1608140081
_s=1
dl=https%3A%2F%2Fga4guide.com%2Fhow-to-import-conversions-from-ga4-property-to-your-google-ads-account%2F
dr=
dt=How%20to%20import%20conversions%20from%20GA4%20property%20to%20your%20Google%20Ads%20account%20-%20Optimize%20Smart&sid=1608140080
sct=1
seg=1
en=page_view
Note: All values you sent via measurement protocol to GA, must be both UTF-8 encoded and URL encoded.
Step-10: In order to better understand the measurement protocol request, scroll down the right-hand side window until you see the ‘Query String Parameters‘ section:
Step-11: Click on the link ‘View decoded‘:
Step-12: Drag your developer console window as high as possible so that you can see a larger portion of your console.
You should now be able to easily read all the parameters in your measurement protocol request:
Measurement Protocol Rules
As mentioned earlier, the ‘Measurement protocol’ is a set of rules which your application must follow in order to send event data directly to the Google Analytics servers from any device/system which can be connected to the internet.
Now since we have briefly covered what transport and payload data are, we are now in a better position to understand the measurement protocol rules.
The 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
When you understand all these rules, you can use the measurement protocol to send event data directly to the Google Analytics servers from any device/system which can be connected to the internet.
Caveat
The measurement protocol in GA4 is still in Alpha and not ready for production. Any content on this topic is for information purpose only.