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

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.

Related

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

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,

Why Google Analytics "minute" dimension doesn't work?

I try to execute the following request usign Google Reporting API:
"reportRequests": [
{
"metrics": [
{
"expression": "ga:sessions"
}
],
"dimensions": [
{
"name": "ga:date"
},
{
"name": "ga:minute"
}
],
"dateRanges": [
{
"startDate": "2018-01-02",
"endDate": "2018-04-17"
}
],
"viewId": "validViewId",
"hideValueRanges": true,
"hideTotals": true
}
]
Unfortunately I get no data. But when I use only "date" dimension, without "minute", I get some data in response.
Could someone please explain such a weird behavior?
As you are querying historical data (here > 2 years) the level of granularity of your data would be impacted by the retention period defined on property level. Meaning that beyond the retention period you can only query a combination of dimensions that are covered by Google Analytics standard aggregated tables (GA Help Center)
In your case the combination "Session | Date | Minute" is not part of Google Analytics aggregated tables, however "Session | Date" is.
You can recreate this phenomenon by using your query on different time ranges: within the retention period vs. outside the retention period.

Google Analytics API Revenue Discrepances

I have discrepancies in the revenue metric, between the data I collect from the Google Analytics API and the custom reports in the user interface.
The discrepancies for each value maintain the same rate, where the data collected through the API is greater than the data in the custom reports.
This is the body of the request I'm using:
{
"reportRequests":[
{
"viewId":"xxxxxxxxxx",
"dateRanges": [{"startDate":"2017-07-01","endDate":"2018-12-31"}],
"metrics": [
{"expression": "ga:transactionRevenue","alias": "transactionRevenue","formattingType": "CURRENCY"},
{"expression": "ga:itemRevenue","alias": "itemRevenue","formattingType": "CURRENCY"},
{"expression": "ga:productRevenuePerPurchase","alias": "productRevenuePerPurchase","formattingType": "CURRENCY"}
],
"dimensions": [
{"name": "ga:channelGrouping"},
{"name": "ga:sourceMedium"},
{"name": "ga:dateHour"},
{"name": "ga:transactionId"},
{"name": "ga:keyWord"}
],
"pageSize": "10000"
}]}
This is an extract of the response:
{{
"reports": [
{
"columnHeader": {
"dimensions": [
"ga:channelGrouping",
"ga:sourceMedium",
"ga:dateHour",
"ga:transactionId",
"ga:keyWord"
],
"metricHeader": {
"metricHeaderEntries": [
{
"name": "transactionRevenue",
"type": "CURRENCY"
},
{
"name": "itemRevenue",
"type": "CURRENCY"
},
{
"name": "productRevenuePerPurchase",
"type": "CURRENCY"
}
]
}
},
"data": {
"rows": [
{
"dimensions": [
"(Other)",
"bing / (not set)",
"2018052216",
"834042319461-01",
"(not set)"
],
"metrics": [
{
"values": [
"367.675436",
"316.55053699999996",
"316.55053699999996"
]
}
]
},
...
So, if I create a custom report in the Google Analytics user interface and look for the transaction ID 834042319461-01, I get the following result:
google Analytics custom report filtered by transaction id 834042319461-01
In the end I have a revenue value of 367.675436 in the API response, but a value of 333.12 in the custom report, its a 10.37% more in the value of the API. I get this 10.37% increase for all values.
¿Why I'm having these discrepance?
¿What would you recomend to do in order to solve these problem?
Thanks.
My bet is that you're experiencing sampling (is your time range in the UI lower than in the API?): https://support.google.com/analytics/answer/2637192?hl=en
Sampling applies when:
you customize the reports
the number of sessions for the overall time range of the report (whether or not your query returns less sessions) exceeds 500K (GA) or 100M (GA 360)
The consequence is that:
the report will be based on a subset of the data (the % depends on the total number of sessions)
therefore your report data won't be as accurate as usual
What you can do to reduce sampling:
increase sample size (will only decrease sampling to a certain extend, but in most cases won't completely remove sampling). In UI it's done via the option at the top of the report, in the API it's done using the samplingLevel option
reduce time range
create filtered views so your reports contain the data you need without needed to customize reports
Because you are looking at a particular transaction ID, this might not be a sampling issue.
If the ratio is consistent, from your question it seems to be 10.37%. I believe this is the case of currency that you are using.
Try using local currency metric API calls when making monetary based calls.
For example -
ga:localTransactionRevenue instead of ga:transactionRevenue

Google Analytics not displaying Category

After much pain and weeping and gnashing of teeth, I finally managed to get my website to talk to GTM and GTM to send data to Analytics.
I can see revenue and conversion rates and transaction results in Analytics, but not the product category.
I have my GTM tag set to use the Transaction track type along with the data layer.
My test code is:
dataLayer.push({
'transactionId': 'OnClickTransactionDataLayerPushID', // Transaction ID - Type:String - Required
'transactionAffiliation': 'OnClickTransactionDataLayerPushAffiliation', // store name - Type:String - Optional to use
'transactionTotal': 45, //total revenue - Type:Numeric - Required
'transactionTax': 5, // Tax amount for transaction - Type:Numeric - Optional to use
'transactionShipping': 5, // Shipping cost - Type:Numeric - Optional to use
'transactionProducts': [{
'sku': 'SKU456789', // Product SKU - Type:String - Required
'name': 'OnClickTransactionDataLayerPushName', // Product Name - Type:String - Required
'category': 'OnClickTransactionDataLayerPushNameCategory', // Product Category - Type:String - Optional to use
'price': 35, // Product Price - Type:Numeric - Required
'quantity': 1 // Product Quantity - Type:Numeric - Required
}]
});
In the GA Debugger I can see that the category is being sent as: ec:item variation (&iv) OnClickTransactionDataLayerPushNameCategory
The only problem is that this isn't a true variation. A variation would be something like color or size, not whether an item belongs to a t-shirt category or whatever. In any event, if this information is being sent over, why can't I see it in Analytics?
EDIT
After trying the Enhanced ECommerce code again as below, I see that the product names are hitting the top products list, but no monetary amounts or quantities are displayed. I can see that being sent in the GA debugger though?
dataLayer.push({
"event": "addToCart",
"ecommerce": {
"currencyCode": "USD",
"add": {
"products": [{
"id": "b55da",
"name": "Flexigen T-Shirt",
"price": "16.00",
"brand": "Flexigen",
"category": "T-Shirts",
"variant": "red",
"dimension1": "M",
"position": 0,
"quantity": 1
}]
}
}
});
Your code is standard e-commerce and the report says enhance e-commerce.
Standard
https://support.google.com/tagmanager/answer/6107169?hl=en
Enhance
https://developers.google.com/tag-manager/enhanced-ecommerce
Disable the enhance e-commerce in you view configuration, tab e-commerce and try to look again.

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.

Resources