What is considered a segment in google analytics API? - google-analytics

I am querying the google analytics API and get an error response saying:
Selected dimensions and metrics cannot be queried together.
Using the dimensions-metrics-explorer I can find which dimensions and metrics can be queried together. https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/
The dimension and metric I want to combine should be possible according to the explorer (CM Impressions and CM Campaign (CM Model))
However, if I tick the box Only show fields that are allowed in segments both those options disappear. So I assume that I am using segments in my request but I do not understand if I truly do or what a segment is.
These are the parts of my query:
auth: <auth>,
'max-results': 10000,
quotaUser: <quotaUserId>,
metrics: [ 'ga:dcmImpressions' ],
dimensions: [ 'ga:dcmLastEventCampaign', 'ga:date' ],
'start-date': <rangeStart>,
'end-date': <rangeEnd>,
id: [ <analyticsViewIds> ],
Am I using segments and if so, what is the segment?

Am I using segments?
No, you're making a regular query
what is the segment?
Segments are a special data querying feature:
More advanced querying: regular queries work on a per-session/hit level just inspecting actual rows of data and returning what matches. With segments you can go further:
User Scope include data for users who meet certain conditions (regular queries are all session/hit based), thus allowing you to filter data on criteria which span across sessions
Session Sequencing include/exclude data based on a series of action users took during their session (first this, then that, then immediately that...)
Complement cohort by using dynamic segments and the not option, allowing you to compare to mutually exclusive segments of user (eg compare users who performed a goal vs users who didn't to understand what gets people to convert)
Available in both UI and API
Predefined or dynamic: you either create your segment in the UI and refer to it from the API via its segmentId or create a dynamic segment via the API directly
Sampling might apply so make sure you check for samplingSpaceSizes to see sampling rate (if any)
Deciding whether to use segments per se is pretty simply:
if you can query what you want without segments don't use them
if you need them to query what you want, use them
The challenging part is knowing what you need to query:
Business side: being able to formulate a hypothesis that makes sense
GA side: being able to translate that into a query, which implies an understanding of the scopes

Related

how many values can a custom dimension take in google analytics?

To anonymously analyze users flow and engagement I want to use the ClientID, as identifier of each user, as a value of a custom dimension. I have two questions regarding this idea:
How many values can be associated to a custom dimension? This will determine the feasibility of this approach or not.
Is there any other approach to track individually, yet anonymously, users activity?
I'm not aware of a limit though for custom dimension length. But storing userId, sessionId customerId and timestamps for all hits in custom dimensions is not all that unusual these days. Here is a link to a post by Simo Ahava's post Improve Data Collection With Four Custom Dimensions on how to set it all up in google tag manager.
For hit based custom dimension you can store as many values as there are hits. The problem is not storage, the problem is that the interface will not show more than 50 000 rows with distinct values (any additional value will go into a row labeled "other"). Also some of the reports (namely demographics) will not work with very small segments.
I cannot think of any other way to track users individually (and if you are interested in opinions, I blogged about how I do not understand why people want to do this). The interface is not very well suited for this kind of "atomic" information, so I think the approach is more useful for API integrations that can properly visualize information on a per user basis.

Huge difference in Advanced segment and Custom Report

Why is the advanced segment and custom report in the below scenario not matching. Need your valuable suggestions from you all.
I have created a custom report to get sessions. I have done this by using the below query
Dimension as Device category
Metrics sessions
filters as page matches regex /products/phone/xperia-z
iam getting figues as mobile(sessions) = 869,908
However when i use a advanced segment on Audience-->Mobile--> overview. The query used in the advanced segment is
condition
Filter session using page matchesregex /products/phone/xperia-z
mobile(session) = 1,187,560
Could you please let us know why there is such a huge difference in custom report and advanced segment, though iam only interested in sessions
Comparing segments with custom reports is not a correct way of populating data. Whenever you apply a segment, it gives data for all the sessions in which your specified page was visited. Whereas in Custom Report, the filter works like a secondary dimension i.e. number of sessions from Mobile in which users directly landed on your page.
Try and using secondary dimension in Audience > Mobile report and your data will match.
// Hiren :P

Analytics API doesn't match web data

I understand that this is a question which has been asked elsewhere, but I haven't yet found an answer which is especially helpful.
The problem I'm having is that the data on the regular web version of analytics doesn't match the data I've pulled from the API.
From what I've read, this can sometimes be an issue with the type of query being used. Here's what I've been using:
var requiredArguments = {
'dimensions':'ga:medium',
'metrics': 'ga:users, ga:sessions, ga:uniquePageviews, ga:newUsers',
'sort': 'ga:medium',
'start-index': '1',
'max-results': '1000',
'sampling-level': 'DEFAULT',
};
and then...
var results = Analytics.Data.Ga.get(
tableId,
startDate,
finishDate,
'ga:users, ga:sessions, ga:uniquePageviews, ga:newUsers',
requiredArguments);
Sessions, across a month, for instance, can sometimes vary by other 1000. I've tried using different sampling types; I don;t think it's that, because I'm not going over 50,000 sessions in a query.
Any help on this is much appreciated.
You need to check the result returned if the data is sampled it will tell you the data is sampled.
"containsSampledData":false
samplingLevel
samplingLevel=DEFAULT Optional. Use this parameter to set the sampling
level (i.e. the number of sessions used to calculate the result) for a
reporting query. The allowed values are consistent with the web
interface and include: DEFAULT — Returns response with a sample size
that balances speed and accuracy. FASTER — Returns a fast response
with a smaller sample size. HIGHER_PRECISION — Returns a more accurate
response using a large sample size, but this may result in the
response being slower. If not supplied, the DEFAULT sampling level
will be used. See the Sampling section for details on how to calculate
the percentage of sessions that were used for a query.
Sampling should return results that are close but not exactly the same as the website. The only way to completely remove sampling from the API is to have a Premium Google Analytics Account
Also remember to consider processing latency. If you request data that is under 48 hours old it will also be different from the website.

Google geocode API results - storing the data

This is a question specifically for the Google Developer Relations team. I have read the Geocode API T&Cs and I am aware that I am not allowed to store data except by way of a temporary cache (e.g. for performance). Is this the end of the matter? I am developing a product which requires a search with results sorted by distance from a place, meaning that all my records need a lat/long. I was intending to use the Geocode API to get the lat/long when a user adds a record, and then adding that lat/long info to the record. We would then use the Haversine formula to calculate the relative distances and sort the results.
If I follow this approach, will I be in breach of the T&Cs? If so, is there another approach using the Geocode API which will allow me to hold onto lat/long data so that I can sort my results by distance, within the letter of the T&Cs?
For anyone else commenting, please observe the following restrictions: (1) we don't have a budget to buy a postcode-lat/long dataset; (2) we don't want to use a static dataset of our own, eg GeoNames, because we don't want to have to maintain data which is, effectively, public; (3) we have to support users who have javascript disabled.
To be absolutely clear, what I need here is to have the lat/long for all of my records in hand so that I can do effective searching and sorting by distance relative to another lat/long as provided, e.g. by a user searching.
Google Team, please respond to this message with contact details so we can speak.

Can I find the most popular keyword for a particular page using the google analytics api?

I was hoping to to use the analytics api to find out the most popular search terms (organic) that lead to a particular page.
Is this possible?
I've trawled the documentation and found this which looks as if it outlines all possible data I can retrieve from the API and I can't see this information here.
http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html
If this is the case, is there any reason that the API isn't complete? I would assume if I can access the data using the analytics interface then I should be able to query for it using the API - is this assumption incorrect?
Yes, this is possible. For example, if you wanted to see what keywords led to how many entrances to index.html,
Set:
Dimensions: ga:keyword
Metrics: ga:entrances
Segment: gaid::-5
Filters: ga:landingPagePath==/index.html
Sort: -ga:entrances
(Segment gaid::-5 segments the data to only include visits referred from Organic Search; sorting by -ga:entrances will order the number of visits in descending order).
Try it out here: http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html?dimensions=ga%253Akeyword&metrics=ga%253Aentrances&segment=gaid%253A%253A-5&filters=ga%253AlandingPagePath%253D%253D%252Findex.html&sort=-ga%253Aentrances&start-date=2010-09-23&end-date=2010-10-07&max-results=50

Resources