I want to build an API to retrieve the Conversion Rates of Purchases via Google Analytics 4. (I understand after reading blogs these are now called 'Key Events')
I am new to GA4 so learning as I go.
I'm using the GA4 Query Explorer to test and build the request:
https://ga-dev-tools.google/ga4/query-explorer/
How do I specifically retrieve the 'Key Event: Purchase' conversion rate? Ideally as a percent but this can be calculated later if not possible?
I've set the parameters like this:
And the response is this:
Am I missing anything? Are those numbers returned just the total purchases for each day? Would it be possible to retrieve the % Conversion Rate for Purchase? I'm guessing I would need to also track all users who visit the checkout page - how would I do this?
I got it working with the below JSON POST Request - this the E-Commerce Conversion rate with user scope. Amend the start and end dates to your requirements:
URL:https://analyticsdata.googleapis.com/v1beta/properties/[YOUR PROPERTY NUMBER]:runReport
BODY:
{
"dimensions": [
{
"name": "eventName"
},
{
"name": "firstUserDefaultChannelGroup"
}
],
"metrics": [
{
"name": "ecommercePurchases"
},
{
"name": "totalUsers"
},
{
"name": "userKeyEventRate"
}
],
"dateRanges": [
{
"startDate": "yesterday",
"endDate": "yesterday"
}
],
"dimensionFilter": {
"filter": {
"fieldName": "eventName",
"inListFilter": {
"values": [
"session_start",
"purchase"
]
}
}
},
"metricAggregations": [
"TOTAL"
]
}
Hopefully this will help someone else.