Google analytics Calculated Metric using case when - google-analytics

I am targeted to research whether this is doable:
To create a calculated metric (Order Submit) in google analytics (https://analytics.google.com/). I am using UA (not GA4). So I am going to create it in a view.
Order Submit:
Before 2021/12/18: [ga:eventAction] like '%Submit Button Click%'. value should be sum of [ga:uniqueEvents];
After 2021/12/18: [ga:eventAction] like ‘%checkout%’ and [ga:eventLabel] like ‘%2%’,value should be sum of [ga:totalEvents];
The ultimate goal is going to use the field via Google analytics API v4 in python. I know how to get the calculated metric via API once it's defined. But I couldn't figure out how to do the case statement for the calculated metric. It looks it can only handle simple operation on existing metrics, e.g. metric 1/ metric 2.
If that's not possible, any workaround?
BTW, I know in google data studio I can possibly create something like that using case statement, but it can not be used in google API v4 I suppose?

This is not possible with calculated metric. The walkabout is to get all related dimensions and metrics in a table. Then you can calculate by yourself using SQL or whatever language depending on where you stored the data.

Related

Getting dimension data from Google analytics even when the data for that dimension is not available

I am using the Google Analytics reporting tool in PHP.
I am having trouble when i am Querying the data when the Dimension data is not available.
For example :
These are the dimension
ga:date,ga:countryIsoCode,ga:eventCategory,ga:eventAction,ga:eventLabel which i have.
These are the metrics
ga:totalEvents which i have.
But the problem is that for some data ga:eventLabel is present and for some ga:eventLabel is not Present.
When i query using the dimension and metrics in the result set data does not include the data which does not have ga:eventLabel.
How can i get the data even when the ga:eventLabel is missing?
This is how GA reporting works.
Empty dimensions will almost always filter away the other dimensions. (few exceptions where GA uses (not set))
You either need to always add a value to the ga:eventLabel upstream while tracking or do the hard query work.
1. ga:eventCategory
2. ga:eventCategory,ga:eventAction
3. ga:eventCategory,ga:eventAction,ga:eventLabel
Then you - intelligently - stitch the dataset together.
You need to make sure you don't use result from 1 that is drill down in 2 etc.

Google Analytics Reporting API - ga:mobileDeviceInfo dimension

I am trying to obtain session data from the Google Analytics API (v3), however am getting some very strange results.
If I use the ga:sessions measure and ga:dateHourMinute dimension; I am able to obtain correct results.
However - if I add ga:mobileDeviceInfo as another dimension to the query, I receive a reduced dataset (based upon total of ga:sessions)
Is anyone able to assist?
It appears that non-mobile devices (rather than populating ga:mobileDeviceInfo as null) will be excluded from the results when including this dimension. This does not appear in the documentation.

Is it possible to use a specific event in calculated metrics in Google Analytics

I am setting up a report based on a calculated metric in Google Analytics. I would like to divide the total number of a specific event action with the number of users. Something similar to:
{{Total Events (MyEventCategory / MyEventAction)}} / {{Users}}
I have tried to find documentation on this feature. The autosuggestion when creating the calculated metric do not suggest the above is possible, but I would like to shout out and hear if anyone out there know whether or not this is possible.

Google Analytics, calculating an average for a custom metric

In Universal GA there are a number of pre-set metrics available to you that represent averages; things like 'avg time spent on page' and 'avg Bounce rate'. However when I create a custom metric, it seems there is no way to calculate the average of it, you always see the sum.
Is there a way to view the average of a metric rather than just the sum ?
I understand that Universal GA is still in public beta, is this just a feature that has been missed out ?
In the current version of Analytics you can now use "Calculated Metrics". Those can be used for creating averages, among other things. You cannot use them for min/max though, it is limited to rather simple calculations.
So if your CustomMetric is gathered at hit-level, you want to define your calculated metric CustomMetricAvg as
{{CustomMetric}} / {{Page Views}}
You didn't miss anything. Calculated metrics are not available.
There's now a Google Analytics feature request for this, please star it or add your comment (hopefully Google Analytics team will notice).
The other option is to export the data and do the calculations outside of Google Analytics. You could do a normal CSV/Excel export, use the Core Reporting API, or try the Magic Script.

Is it possible to segment visits by goal completions in Google Analytics?

I have a website, and want to use the Google Analytics API to give me data that only includes visits with a specific goal completion (say goal 2). I'm trying to use the ga:goal(2)Completions metric in a segment to get this data like this:
segment=dynamic::ga:goal(2)Completions!=0
However, whenever I try this in the Query Explorer I'm told this is an invalid segment value. I don't see goal(n)Completions as a disallowed metric for use in segments in the documentation (https://developers.google.com/analytics/devguides/reporting/core/v3/reference#segment), so what's the problem here? Is there a different way to get this data segment?
It is because of
you shouldn't use "segment="
(n) value should be with out brackets.
ids= ga:XXXXXXXX
start-date= 2012-01-01
end-date= 2012-01-31
metrics= ga:visits
segment= dynamic::ga:goal2Completions!=0
I have tested and the sample above should work fine.
And if you want to do the opposite use
segment= dynamic::ga:goal2Completions==0
You can double-check it by running the query without segmentation - both above should sum up the the latest one.
Cheers

Resources