Difference between Google Analytics API v4 (no result) and dashboard - google-analytics

I'm trying to retrieve separately ga:userAgeBracket and ga:userGender using Google Analytics Report API v4 using a filter on eventCategory and eventAction.
From GA Dashboard, i'm able to retrieve the data even if there is only ~ 2.4k users and ~5.6k sessions. The repartition is 178 Males and 142 Females.
I'm trying to get the same result with the API but it's return nothing. I'm testing with https://ga-dev-tools.appspot.com/query-explorer with the same filters ect.
Is there any limit on the API ONLY when there is a small amount of data ? or another reason ?
EDIT: With another account with more data, and i still have the issue. Here are some screenshots

You created a segment in GA webUI and is comparing the results to "filters" in the explorer. You should be applying the same segment instead for consistency. Once you save the segment in webUI, it should be available in the "segment" field as a selection.
Your filtering also uses the "=~" regex match operator instead of the "=#" contains operator. Try this and you should have results.

Related

Google Analytics API and UI Report Users data not matching

I've extensively searched in forum and after that putting this question so that someone might be able to help me.
Scenario:
In Google analytics dashboard, we have created logical categories based on keywords within PagePath. For instance, if my PagePath contains keyword \sports\ we call it Sports Section category.
We capture the User count weekly from UI as shown below :
I am now trying to move this data in MySQL db using Talend Open Studio Data Integration.
I am using a componenttgoogleanalyticsinput where I can feed Dimensions and Metrics.
Problem:
I analyzed 2 days of data and found the following observation:
Date All User Sports Auto
01-Jun 2220088 325174 51825 (visible in image chart)
02-Jun 2950015 256390 80472 (not visible in above chart)
Total 5170103 581564 132297 (sum of above)
API : 5170103 581564 132297 (received from API)
UI : 4910532 553400 129652 (shown in UI)
So, the data on chart matches with what I'm getting from API BUT they both do not match with what is shown in UI number.
I visited this link to understand what those numbers mean on Google UI.
Problem is, what dimension and metrics should I take so that my API values matches with UI number?
I tried to take ga:PagePath, ga:Date as dimension and ga:Users, ga:pageViews as metrics but they're not working for me.

Google Analytics Custom Data Studio Field: Unknown dimension or metric ID: _ga____campaign_

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!

Backwards Facing Content Grouping

Need to group some pages on my site together but apparently content grouping would only be forward facing. Is there a way to apply content grouping to prior data or create a calculated column as such which would allow GA to filter and group older data?
Is there a way to apply content grouping to prior data?
No, content grouping only applies going forward.
or create a calculated column as such which would allow GA to filter
and group older data?
No, any data you add to GA is only available as of the moment you create it.
What you can do:
GA:
Use Query Filters (not view filters) or segments: filters/segments don't create any data, they just filter it. So if you create 1 filter/segment per group and query the data, you will effectively have the same data as if you had done content grouping
Use Regex: GA supports regular expression which might help you create the filters you need
Use the API: since applying filters/segments might be tedious to do (and repeat) via the UI, you might want to use the API, for instance via the Google Sheets GA API add-on (see further details below)
Example of Google Sheets GA API add-on query to group some content that would match all pages which start with /foo or /bar (see list of API dimensions and metrics, see legacy filters syntax):
ga:pagePath=~^/(foo|bar)
Once you have figured out 1 query for 1 group you can clone them, query all your data, and then reaggregate it.
Google Data Studio:
GDS has a feature called Calculated fields which effectively allows you to create content groupings which apply to both historical and new data. Most likely you want to do this with a CASE statement:
CASE
WHEN REGEXP_MATCH(Page,'^/(foo|bar)') THEN "Group A"
WHEN REGEXP_MATCH...
ELSE "Other"
END

Google Analytics - How to filter by page, group by query string value?

I have a site with a store search that posts in the following format.
www.site.com/store-locator?city=&province=&zip[postal_code]=68123
I am trying to configure GA to give me feedback on people visiting this page and a count of specific zips searched.
example report data
/store-locator?city=&province=&zip[postal_code]=68123 1000 visits
/store-locator?city=&province=&zip[postal_code]=68456 768 visits
/store-locator?city=&province=&zip[postal_code]=68789 221 visits
note: the 'city' and 'province' values may also be populated (and I will want to mod GA to give similar data on these too).
Can anyone give feedback on how to configure GA to give me data similar to this?
Thanks!
As far as I know, the only way to look at this type of segment historically is using individual segments, which doesn't work well for an arbitrary number of zip codes. However, you can collect this data more effectively as described for new traffic. This comes up often with information like categories, tags, dates, query string variables, etc.
You can create Segments for each zip. This will work for historical analysis, but is impractical beyond a few. https://support.google.com/analytics/answer/3124493?hl=en&ref_topic=3123779
You can also use Content Grouping to create groups. This will not work historically. https://support.google.com/analytics/answer/2853423
The way I've handled this is using Custom Dimensions, which replaced Custom Variables when Universal came out. This also only works for future data.
To use Custom Dimensions, you would pass the zip code to google analytics explicitly when calling the analytics javascript code.
You can pull querystrings with javascript, or echo the parameter using something like PHP as follows:
<?php
if (array_key_exists("zip",$_GET)) { $theZip = $_GET["zip"]; }
else { $theZip = "nozip"; }
?>
And, sending the custom dimension --
ga('create', 'UA-XXXXX');
ga('set', {'dimension1': '<?php echo $theZip; ?>'})
ga('send', 'pageview');
You also need to setup the custom dimension in the Analytics Profile. Docs on custom dimensions https://developers.google.com/analytics/devguides/platform/customdimsmets
/store-locator?city=&province=&zip[postal_code]=68123 1000 visits
Step 1: In GTM, create a new macro. I called mine {{province}}
Macto Type = URL
Component Type = Query
Query Key = province
This will populate the Macro with the value of province from the query string.
Step 2: In your Google Analytics property, define a custom dimension called "province". This will assign an index key to the dimension.
Step 3: In your GTM tag for Google Analytics, you will find Custom Dimensions under more settings. Add a new dimension, apply the index number from #2 and for the dimension select the macro you created from #1
Publish and you are all set.
Now when you look in Google Analytics, you can add a secondary dimension and choose your newly created custom dimension.

Google Analytics API: how to get non-US visitors

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.

Resources