I need to query the Google Analytics API to reproduce the following view:
In my Python code I have a list of dimensions and metrics that I want to query:
'metrics': [{'expression': 'ga:productListClicks'}],
'dimensions': [{'name': 'ga:landingPagePath'}],
My problem is that I do not know the name of the columns in the format 'ga:...' and in the Query Explorer there are multiple names for a given column.
Is there a way to see the name of the columns in the format 'ga:...' directly in GA?
If not, how can I find the right names?
If you use the GA query builder, you can use the type ahead/search feature of the tool to find these attributes.
You'll find the query explorer here:
https://ga-dev-tools.appspot.com/query-explorer/
This is what it looks like when you find these:
Some of the ones you're looking for are:
ga:impressions
ga:adClicks
ga:CTR
ga:sessions
ga:bounceRate
etc.
The benefit of doing this in the query builder, is you can then test it before going back to python. There are a lot of complications of mixing metrics and dimensions, and making sure what you're doing is valid here first will save headaches!
Related
There is a slight difference in the account names in Google Ad Words and Google Analytics: AdWords will have a campaign called "*Brand_Campaign [Ex]" while the name in Google Analytics is "Brand_Campaign_Ex"
If I want to stitch these together, I need to replace all the symbols and convert the entire campaign name to lower case. I'm trying to create a new field in the Google Analytics data using this formula:
REGEXP_REPLACE(Campaign,'_','')
But Google Data Studio returns an error message saying
Unknown dimension or metric ID: _ga____campaign_.
The campaign dimension is definitely in the table. The same formula works to create a new dimension, but I cannot join on dimensions created on the fly. I have been able to do this exact thing for the Google AdWords table, but the Analytics table is returning this strange error. Please help!
Not 100% sure if this applies here but I had a similar problem. My problem was that the columns in my postgresSQL database contained special characters like - or /. I know that one should never use such characters but anyways - changed that and reconnected the database and everything worked fine!
Hope this helps!
I'm trying to filter website conversions from Google Analytics for a dashboard. However since it is a mixture of third party leads, events, and page path that contribute to the leads, I have to combine different types of filters. However combining folling metrics, the https://ga-dev-tools.appspot.com/query-explorer/ shows me the value 0 even if that's not correct.
Metrics: ga:totalEvents
Dimension:ga:date
ga:pagePath=#DialogNavigatorVertical,ga:eventAction==Texting form submit
I have tried multiple solutions, but can't figure out how to get the correct data. Can I not combine pagePath and evenAction?
Thank you so much for all your kind help,
Anna
Events by definition are not page views. This means that an Event dimension (category, action, label) can't have page view metrics such as page views or average time on the page because that information does not relate to the specific event.
But you can definitely combine pagePath and evenAction. You are getting wrong results because of one of the following reasons
In your filter, ga:pagePath=#DialogNavigatorVertical is wrong, it must be either == or !=. it cant be an assignment operator
IF you wish to combine two filter conditions using AND that means both must be true, use ;. Semicolon is used for AND operator in filters
IF you wish to combine two filter conditions using OR that means both must be true, use ,. Comma is used for OR operator in filters
In case you are using core reporting api from a backend script, please URL encode the call before hitting. like == must be %3D%3D, space must be %20 and so on.
Please have a look into settings here : https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters
I wanted to fetch the document which have the particular element attribute value.
So, I tried the cts:element-attribute-value-query but I didn't get any result. But the same element attribute value, I am able to get using cts:element-attribute-range-query.
Here the sample snippet used.
let $s-query := cts:element-attribute-range-query(xs:QName("tit:title"),xs:QName("name"),"=",
"SampleTitle",
("collation=http://marklogic.com/collation/codepoint"))
let $s-query := cts:element-attribute-value-query(xs:QName("tit:title"),xs:QName("name"),
"SampleTitle",
())
return cts:search(fn:doc(),($s-query))
The problem with range-query is it needs the range index. I have hundreds of DB's in multiple hosts. I need to create range indexes on each DB.
What could be the problem with attribute-value-query?
I found the issue with a couple of research.
Actually the result document is a french language document. It has the structure as follows. This is a sample.
<doc xml:lang="fr:CA" xmlns:tit="title">
<tit:title name="SampleTitle"/>
</doc>
The cts:element-attribute-value-query is a language dependent query. To get the french language results, then language needs to be mentioned in the option as follows.
cts:element-attribute-value-query(xs:QName("tit:title"),xs:QName("name"), "SampleTitle",("lang=fr"))
But cts:element-attribute-range-query don't require the language option.
Thanks for the effort.
The metrics for my Query is as below:
ga:eventValue
The dimensions for my query is as below:
ga:eventLabel,ga:eventAction,ga:year,ga:month,ga:day,ga:hour,ga:minute
Now when I apply a filter with ga:hour==13 then I get the results filtered out for ga:hour=13 which is perfectly fine.
But When I query using multiple filters ga:eventAction==xxx,ga:hour==13 the result is not displayed correctly. My expectation is that I should be getting the results where the hour is 13 and eventAction=xxx but it gives a lot more results.
How the filters work when we have multiple filters? What is the maximum number of filters allowed? Does always the filter needs to be a dimension or metric?
Thanks a lot for your time.
Your filter (ga:eventAction==xxx,ga:hour==13) is using a comma to separate the two conditions. With GA filters, the comma is the logical OR. If you use a semicolon instead, that will be the logical AND, which should give you want you want.
You can read more on the filter syntax here. It should answer all your other questions:
https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters
I have been using visitors with ga:country filters to get specific country's visitors. For example to get the number of visitors from US, I used the filter of 'ga:country==United%20States'. But I am wondering if I can do something like 'ga:country!=United%20States'? I guess I can subtract ga:country==United%20States from total visitors but I am wondering.
The easet way of doing this is to create a filter ga:country. A filter will let you remove a subset of the data returned by a query. Think of it like a where clause in SQL.
Filter=ga:country!%3DUnited%20States
That translates to
Filter=ga:country != United States
I made a simple report on my personal dashboard the Google Analtyics to test it.
Added info on filtering:
You can add more then one filter by seprateing
OR operator is defined using a comma (,).
AND operator is defined using a semi-colon (;).
You can mix and match Metric and Dimensions in the same filter.