GA4 - Measurement Protocol Issue - gtag + client_id + session_id not merge on reports - google-analytics

We have migrated the UA to GA4. We use gtag.js for most of the events on the website and the Measurement Protocol for the purchase.
We noticed that the measurement protocol event has a problem with reporting at the sessions level on channels grouping because everything is classified as "not set", and we have a significant amount of purchases that are not linked to client_id. We are collecting a unique hit with the purchase (print screen attached).
We followed all the requirements on the documentation, and after discussions with other web analytics, it should be an issue with the Measurement Protocol.
We need your assistance to find a solution to this tracking problem.
url = "https://www.google-analytics.com//mp/collect?api_secret=API_Secrect&measurement_id=G-0000000000"
payload = {
"client_id": "685297041.1666940000",
"user_id": "#1234",
"non_personalized_ads": 'false',
"user_properties":{
"cust_numb":{
"value":"#1234"},
"internal_user":{
"value":"false"}},
"events": [
{
"name": "purchase",
"params": {
"items": [
{
"price": 3.35,
"quantity": 1,
"item_id": "#1062",
"item_name": "White Fine Filters",
"affiliation": "client.com",
"currency": "USD",
"discount": 0.5,
"item_variant": "NA",
"item_category": "Filters",
"item_brand": "Generic",
"index": 0,
"item_category2": "One_Time",
"item_category3": "simple_product",
"item_category4": "full_price",
"item_category5": "in stock"
},
{
"price": 15.95,
"quantity": 1,
"item_id": "#1068",
"item_name": "Black Filters for PR",
"affiliation": "client.com",
"currency": "USD",
"discount": 5.8,
"item_variant": "NA",
"item_category": "Supplies/Filters/Sale 2021",
"item_brand": "Generic",
"index": 1,
"item_category2": "one_time",
"item_category3": "simple_product",
"item_category4": "Discounted",
"item_category5": "in_stock"
}],
"affiliation": "",
"coupon": "ALL10",
"currency": "USD",
"transaction_id": "#2_02022",
"shipping": 5,
"tax": 0.35,
"value": 15,
"session_id": "1666947000",
"timestamp_micros": "1666948174531000",
"engagement_time_msec": "1000"
}
}
]
}
requests.post(url,data=json.dumps(payload))
enter image description here
I tested everything.
Could you let me know if you are facing the same issue?
I noticed this on the documentation, but it's not detailed what partial reporting is.
"Full Server-to-Server
While it is possible to send events to Google Analytics solely with measurement protocol, only partial reporting may be available. The purpose of the measurement protocol is to augment existing events collected via gtag, GTM, or Firebase. Some event and parameter names are reserved for use via automatic collection and cannot be sent through the measurement protocol."
Thank you,

Related

Ecommerce purchase value is not decreased after a refund event in GA4

I'm migrating from UA to GA4 for ecommerce tracking.
I'm testing buy-and-refund scenario with GA: I sent a purchase event to GA4 via measurement protocal; After I ensured the purchase event is received (value showed in Ecommerce Purchases), I sent a refund event with the same transaction ID (through measurement protocal as well). I waited a day, but the value of purchase values in "GA4 Monetization -> Ecommerce Purchases" didn't decrease.
I'm sure the refund event is received (from Realtime report and Explore) by GA4. Is this a bug or expected behaviour? I didn't see it is described anywhere. Did I make any mistakes in event payload?
Here are my event payloads:
{
"name": "purchase",
"params": {
"items": [
{
"item_id": "L-6",
"item_name": "Product Report - 1775",
"item_category": "Report",
"quantity": 1,
"price": 60,
"currency": "CNY"
}
],
"currency": "CNY",
"transaction_id": "LP-6",
"value": 60
}
{
"name": "refund",
"params": {
"currency": "CNY",
"transaction_id": "LP-6",
"value": 60
}
}
When I was using UA, I could send negative revenue in transaction hit and negative quality in transaction_item hit in order to refund and decrease reveune. It seems this doesn't work in GA4? Should I should negative value in refund event? I didn't see any docs about it.
As far my tests showed, GA4 just increments the metric "Refunds" by 1 after a full refund.
If you just need total number of purchases or E-commerce revenue, you could filter all the transactions that have refunds=0 and read the totals from "E-commerce revenue" or "E-commerce purchases", but I found that when you combine item-related dimensions or metrics (i.e. item name, item revenue, etc) the metric "Refunds" is showing as 0 even for refunded transactions.
Something is not quite right here.

How can I place two orders in a transaction with Enhanced Ecommerce?

One of my customers has a problem with Enhanced Ecommerce through GTM.
This customer has two groups of products:
- Group A: products that my customer distributes directly to their clients
- Group B: product that my customer distributes through a wholesaler.
When a client orders one product from Group A and another produt from Group B, my client receives 2 different orders.
My client wants to be able to measure those transaction orders separately and extract reports from GA.
I have currently considered double push of the "purchase" script on the thankyou page, one for each order with its corresponding products (Group A & Group B).
Do you think it is the best option?
Or would a single generic push of the transaction be best? Using a secondary dimension within the products I could separate it by order-1 (Group A) and order-2 (Group B)?
Regards.
You could distinguish them with the “Category” parameter within the scripts then in GA you would segment by category is Product Group A
gtag('event', 'purchase', {
"transaction_id": "24.031608523954162",
"affiliation": "Google online store",
"value": 23.07,
"currency": "USD",
"tax": 1.24,
"shipping": 0,
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Product Group A",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
},
{
"id": "P67890",
"name": "Flame challenge TShirt",
"list_name": "Search Results",
"brand": "MyBrand",
"category": "Product Group B",
"variant": "Red",
"list_position": 2,
"quantity": 1,
"price": '3.0'
}
]
});

How to get Google Analytics dimension/metric description in multi-language?

I am using this API to get a list of dimensions/metrics from Google Analytics: https://developers.google.com/apis-explorer/#s/analytics/v3/analytics.metadata.columns.list?reportTy..., however, I just realized the API only supports 'uiName', 'description' in English! is that true? is there any work around to support multi-language? Thanks!
"items": [
{
"id": "ga:userType",
"kind": "analytics#column",
"attributes": {
"type": "DIMENSION",
"dataType": "STRING",
"group": "User",
"status": "PUBLIC",
"uiName": "User Type",
"description": "A boolean, either New Visitor or Returning Visitor, indicating if the users are new or returning.",
"allowedInSegments": "true",
"addedInApiVersion": "3"
}
That is true the Meta data api only returns data in english. You are going to have to translate the metadata names to your chosen language yourself after you have downloaded the data you need

GA: How to access Cohort Analysis via Analytics API?

Cohort dimensions and metrics are listed here. Yet, when I try to query it using API (e.g. using Query Explorer) an error 400 occurs.
One of queries I've tried is: metrics = ga:cohortActiveUsers and dimensions = ga:cohortNthDay .
Is is possible to query Cohort Analysis report via API?
The problem you are having is because the Query explorer uses the v3 of the Google Analytics API. If you look at the Dimensions and Metrics Explorer you will notice that these dimensions were added in the Analytics Reporting API V4.
The error message you are getting is incorrect and should be corrected soon. It should state something more like This metric cannot be used in Version 3 of the API. You caught this while we where in the process of rolling out the new API. Which has now been officially released see change log
To make use of these new dimensions and metrics you must construct a V4 cohort request:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests": [{
"viewId": "XXXX",
# No date range is required in the request
"dimensions": [{"name": "ga:cohort" },{"name": "ga:cohortNthDay" }],
"metrics": [
{"expression": "ga:cohortActiveUsers" },
{"expression": "ga:cohortTotalUsers"}
],
"cohortGroup": {
"cohorts": [{
"name": "cohort 1",
"type": "FIRST_VISIT_DATE",
"dateRange": { "startDate": "2015-08-01", "endDate": "2015-08-01"}
},{
"name": "cohort 2",
"type": "FIRST_VISIT_DATE",
"dateRange": {"startDate": "2015-07-01", "endDate": "2015-07-01"}
}]
}
}]
}
It is possible to compose a cohort requests by using the Request Composer tool, in the Cohort Request tab.
As you select the options in the Set query parameters section, the request payload is shown below.
Hope it helps.

Google Analytics Experiments always chooses original variation?

I'm setting up a multivariate test through Google Analytics. I created the experiment through the API, and everything is looking like its running, however, only the original is being selected and the variants aren't being served.
I've tried using incognito windows, and had a few other people visit the page as well, but everyone receives a page with ?utm_expid=XXXXXXXX-XX.YYYYYYYYYYYYYYYYYY.0 on the end, where the .0 seems to indicate "show original."
Any ideas why an experiment might always show the original? Here's my experiment as retrieved through the API.
{
"id": "YYYYYYYYYYYYYYYYYYYYY",
"kind": "analytics#experiment",
"accountId": "AAAAAAAA",
"webPropertyId": "UA-ZZZZZZZZZ-0",
"profileId": "XXXXXXXX",
"name": "Product Page - Grid Content",
"description": "Test of product page grid content.",
"created": "2013-11-22T15:53:32.634Z",
"updated": "2013-11-22T16:27:15.406Z",
"objectiveMetric": "ga:timeOnSite",
"optimizationType": "MAXIMUM",
"status": "RUNNING",
"startTime": "2013-11-22T16:00:37.367Z",
"rewriteVariationUrlsAsOriginal": true,
"winnerConfidenceLevel": 0.95,
"minimumExperimentLengthInDays": 7,
"trafficCoverage": 1,
"equalWeighting": true,
"variations": [{
"name": "Newest Products (Original)",
"url": "http://mystore.com/product/pastel-lipstick",
"status": "ACTIVE",
"weight": 0
}, {
"name": "Most Popular Products",
"url": "?",
"status": "ACTIVE",
"weight": 0
}, {
"name": "Related Products",
"url": "?",
"status": "ACTIVE",
"weight": 0
}],
"servingFramework": "REDIRECT",
"editableInGaUi": true
}
UPDATE:
I've suspected this might have something to do with those weight: 0 fields under variations[]. I'm not entirely sure why they appear as weight: 0, or whether that actually prevents variations from showing.
Originally, I wanted to set url: "?" for my variations because I wanted to avoid polluting my query string. Instead of using different URLs/query string variables to determine which variation to show, I used the utm_expid query string variable the GA Experiment redirect adds to determine which variation to show. Although the API accepted these URLs without issue, I'm not sure they're actually considered 'valid.' So I tried changing the URLs to be ?mvt=1 and ?mvt=2 respectively, and saw the weights changed to 0.3333 and variations serve.
Although changing the URL seems to work, does anyone have a thorough explanation for what or why this is happening?
There is an open issue on this https://code.google.com/p/analytics-issues/issues/detail?id=377. If you subscribe to that then you'll get notified when it's fixed.

Resources