How to set User Agent in Measurement Protocol (Google Analytics 4) - google-analytics

How to set or override User Agent value in Measurement Protocol (Google Analytics 4)?
It was easy with previous Measurement Protocol (Universal Analytics): https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters?hl=en#ua
But it is not clear to me how to send User Agent to Google Analytics v4.

If you check the documentation at the top of the page Measurement Protocol (Google Analytics 4)
You will see that this protocol is still in alpha and is extremely limited there is a lot we cant do with it.
As of the time of posting this answer the answer is you cant. I suggest you wait a while as time goes on the team will begin to add new features.

Related

UTM params for GA4 measurement protocol

How do I send UTM params or any campaign data to google analytics 4 using measurement protocol? Their GA4 documentation does not mention anything about this.
At the time of writing the Measurement Protocol (Google Analytics 4) is still in beta.
There are limitations in what it supports and what it will support in the future.
UTM parameters are text strings that you can append to URLs that allow you track those URLs when they get clicked on. UTM parameters make Universal analytics Google Analytics pick up on the data in the code and log it with the pageview. The resulting data is visible in Universal analytics Google Analytics, meaning you can track traffic in terms of where it came from and how it got to you.
At the time of writing there is no mention of UTM support in Google analytics GA4

Recommended way to setup server-side event tracking for Google Analytics 4?

We've setup a property in Google Analytics a while ago, to track a web-based app. Since it was the default option, this property is using Google Analytics 4 instead of Universal Analytics.
Now we wanted to implement server-side event tracking, e.g. for sign-ups and were pretty surprised that the GA4-version of the "Measurement Protocol" is still in Alpha and not recommended for production use.
Since we need server-side event tracking urgently, we are wondering how to deal with the situation. I guess we can't just "go back" to Universal Analytics without losing our tracking data.
So we dug into the GA4 Measurement Protocol, but stumbled upon some weird stuff. For instance, this protocol requires a "client_id" to be sent along with the events, which makes no sense at all in a server-to-server scenario. There is no such thing as a "unique client" in this case. The old UA protocol did not require this.
I am wondering if there is any best-practices for sending server-side events to GA4 at the moment? Any tutorials? Is there a way to use the "old" UA Measurement Protocol for GA4? I guess not, because even the Tracking ID format is different.
Any pointer to useful information would be appreciated. Thanks.
You can't use "old" measurement protocol for GA4, anyway the measurement protocol v2 is working. You can see it in action in this video of mine: https://www.youtube.com/watch?v=WSxdrG1G_yE
Concerning GA4 events, relative tag is built-in in GTM server-side.
You can see this video of Simo Ahava about server-side Tagging In Google Tag Manager: https://www.youtube.com/watch?v=6OGbOh216mU

Google Measurement Protocol advanced e-commerce hits not showing up in Analytics

I'm having issues with tracking advanced e-commerce transactions through Google Measurement Protocol. I want to use this because we can track sales with the most accuracy if it is done server-side. So we take over the cid from the frontend and track a sale as soon as the payment has been done. I have done this before in the exact same way but for some reason it doesn't work this time, or only works around 50% the time, depending on the tracking ID we use.
I am sending the following payload to: https://www.google-analytics.com/collect (changede UA code for the example):
v=1&t=event&tid=UA-MYCODEHERE-1&cid=532571481.1547156684&el=91901.000001&pr1ca=weekendje-weg&ni=1&uid=1337&pr2qt=1&tr=64.65&pr1br=Some%20Location&pr2va=3%20dagen%20-%20Standaardkamer&pr2id=DRTA-4379&ea=purchase&pr1va=3%20dagen%20-%20Standaardkamer&cu=EUR&ta=Some%20Location&pr2ca=weekendje-weg&pr2nm=Some%20Location%20Somewhere&ec=checkout&pr2br=Some%20Location&pr1pr=158.00&pr1qt=1&ti=91901.000001&pr1id=DRTA-4379&pr1nm=Some%20Location%20Somewhere&pa=purchase&pr2pr=158.00&ts=0
This validates in the Hit builder and using the Debug URL, I log all outgoing measurement protocol hits and they are always triggered and always return a status code 200, I have enhanced e-commerce tracking enabled for the tracking id and no filters there (brand new Analytics account) but my hits never show up for this account in Analytics (even after waiting for days still no single measure).
I'm not sure what's going on, I did this before like this and it always worked fine. Am I missing something? I tried switching to measurement protocol via http or https, GET or POST, etc, it all doesn't help. I did have this exact code working for a older property but it wasn't reliably tracking all transactions, now it's just tracking none. I think I tried everything I could, is this a Google Measurement Protocol/Analytics bug or am I missing something?

What type of Google Analytics Property for Measurement Protocol?

When setting up Google Analytics Measurement Protocol what type of Google Analytics Property should I create?
There does not seem to be a "Universal Analytics" or "Measurement Protocol" option, which is the source of my confusion and the reason for my question.
The two choices are Web Site and Mobile Application, and both seem to need configuration beyond what is suggested as the requirements in the Measurement Protocol page.
The Measurement Protocol is property-agnostic. If you go to this hit-builder site, https://ga-dev-tools.appspot.com/hit-builder/, you will notice that it doesn't ask what type of property you are using (ie. UA vs classic GA). It just needs to know the property ID, type of hit, client ID, and version number.

Measurement protocol not working for mobile app

I am trying to send data about screenview in my account Google Analytics, using measurement protocol.
But i don't see data in the Real Time reports.
string request:
http://www.google-analytics.com/collect?v=1&tid=UA-55175445-4&cid=666&t=screenview&an=HelloWorld
where is a problem?
I had same problem and apparently if you're using mobile app version of analytics you have to send application name (an) and application id (aid), otherwise the hit is ignored.
Here are some bullets you might want to consider.
1) Make sure that you are using google universal. (How?)
2) For new google analytics accounts it will take up to 48 hours until you can start using the measurement protocol.
3) Make sure you are setting the User-Agent with the request
4) Make sure cid is a random UUID (version 4) as described in http://www.ietf.org/rfc/rfc4122.txt

Resources