Google Analytics events sequence - google-analytics

I want to get from google analytics the list of events for all my users. And I want to be able to say "this event occured before this event", it means I want to know the sequence of the events, the order in which they were triggered.
I could already retrieve the list of events per user by doing a query that looks like this :
ids = foo
start-date = foo
end-date = foo
metrics = ga:sessions
dimensions = ga:dimensionX (dimensionX being user_id), ga:screenName,
ga:eventCategory, ga:eventLabel, ga:eventAction,
ga:date,ga:hour, ga:minute
With this I get the list of events by user_id, by screen, and by the time (up to the minute).
But ... minutes are not enough to be sure about the sequence of events. Moreoever, I couldn't find any ga:seconds dimension (does it exist ?), so I'm not sure if trying to get the sequence by time is a good thing. That is why I was wondering if there were a way to get a kind of "id" for the event, in order to sort them by the order in which they were triggered.
If there is no such thing, I was wondering if adding an ga:eventValue and setting the value to a timestamp would be a good thing ?
Thanks in advance !

Related

Google Analytics: How to properly filter ga:1dayUsers and ga:30dayUsers

Question: What is the right way to filter active users based on the presence of an event?
I'm trying to report on a count of users that have performed a particular action (purchased an item) on my site.
The aim is to have a Daily Unique Buyer (akin to DAU or 1dayUsers) and Monthly Unique Buyer (akin MAU or 30dayUser) metric.
For the Daily Unique Buyer metric I have tried two separate approaches and I am getting different results for both.
Approach 1) Use ga:Users metric and apply filter ga:eventCategory=="Purchase"
Approach 2) Create custom Segment, Ensure that Advanced Filter condition is for Users (not Sessions) and set the same filter ga:eventCategory=="Purchase"
The first approach seems to yield the desired result when compared to the second.
Unfortunately, the first approach does not extend to computing the same metric for Monthly Unique Buyers.
Most post on StackOverflow suggest that creating a segment (approach 2) is the right way forward. This however, yields more users than events, which can't be correct.
Even more perplexing - Applying the segment in Audience -> Active Users interface yields a different result to programmatic app-script query below
const optArgs = {
'dimensions': 'ga:date',
'sort': '-ga:date','
start-index': '1',
'max-results': 250,
'segment: 'gaid::xxxx',
}
Analytics.Data.Ga.get(
myViewId, startDate, endDate, 'ga:1dayUsers', optArgs
);
update: For those that struggled with this. I don't claim to understand why, but I was able to get the correct number by querying the desired metrics 1dayUsers and 30dayUsers one date at a time.
Running the report over a date range failed. I checked this with the list of actual active users (under User Explorer in the interface) and both 1 day and 30 day metrics are correct.
Would love for someone to explain why this is needed.

Google analytics API: different sum of sessions with 'ga:eventLabel' function and without it

I added 'ga:eventLabel' function to my script and sum of sessions decreased from 2238 to 994. Why?
I expect the same result from both script
dim=['ga:eventLabel', 'ga:source','ga:sourceMedium']
met=['ga:sessions', 'ga:users']
start_date='2019-07-01'
end_date='2019-07-03'
transaction_type='Goal'
goal_number=''
refresh_token=token
condition=''
data_2=google_analytics_reporting_api_data_extraction(viewID,dim,met,start_date,end_date,refresh_token,transaction_type,goal_number,condition)
viewID='*********'
dim=['ga:source','ga:sourceMedium']
met=['ga:sessions', 'ga:users']
start_date='2019-07-01'
end_date='2019-07-03'
transaction_type='Goal'
goal_number=''
refresh_token=token
condition=''
data=google_analytics_reporting_api_data_extraction(viewID,dim,met,start_date,end_date, refresh_token,transaction_type, goal_number,condition)```
Here are the results:
--
The two queries have two different meanings, and won't give you the same result, unless you have a data set, where all sessions have at least one event type hit associated with them.
The first query says: count all my users and sessions for the given date range, breaking it down by event label, source, source/medium and date. So in this case, you implicitly filter for any known event labels, where (not set) is an empty, but existing label for a recorded event. Sessions without any events are excluded.
The second query says: count all my users and sessions for the given date range, breaking it down by source, source/medium and date (regardless, if they had any events).
You can verify this behavior, if you create these custom reports in Google Analytics web UI. It is similar to querying custom dimensions: if no value was set for a given custom dimension, those records are excluded.

Google Analytics: UniqueEvents affected by different EventValues?

Does UniqueEvent also consider the EventValue field?
Let's make an example.
In the same user session, these two analytics are sent:
1)
EventCategory = "UI"
EventAction = "Click"
EventLabel = "Result"
EventValue = 5
2)
EventCategory = "UI"
EventAction = "Click"
EventLabel = "Result"
EventValue = 3
do they count for 1 or 2 UniqueEvent?
I have been assuming so far that EventValue is irrelevant for the UniqueEvent, and it could even be used for sending the current timestamp.
The Unique Event definition is:
Unique Events: The number of times during a date range that a session
contained the specific dimension or combination of dimensions.
One important thing to notice is that Unique Events has nothing to do with Events. If this sounds confusing is because it is, but stay with me.
Unique Events is a special metric in Google Analytics it is context dependent. The number of unique events will depend on the dimension, or combination of dimensions you use.
Want proof that unique events has nothing to do with events? Go to an account with a bunch of pageviews and 0 events, and try to create a report of any dimension by page, the number you see should be close to unique pageviews (but not quite).
Event Value is a metric not a dimension, so it can never influence unique events.
Now to your question on whether your example counts as 1 or 2 unique events, the answer is not defined unless you define the actual report you are trying to do.

Working with event stat in google analytics api

I have the website where merchants sell some stuff. Each item has stats like unique views during last 24 hours, a week and a month and a number of visitors that clicked on "show contacts" button. Uniqueness based on IP. This works, there're huge tables that collects all (IP,item_id) pairs during the last month, and there're a lot of updates.
Today I dig into google analytics api, I would like to know if it's possible to use it instead of my system.
The fact is all this stat is private, available only for merchant, so I don't need to have all stat at a time (it's not compared etc.). So it might be requested on demand for the specific item.
I created service account, connected it to analytics data and it seems export works (based on this example). Then enabled event tracking for "show contacts" button.
For example, when user click on "show contacts" where should I add item_id? Is it eventLabel or eventValue? So, for item_id=1234 it should be
ga("send","event","Contacts","show","",1234) or ga("send","event","Contacts","show",1234)?
I'm confused with eventValue column in Top Events report (it seems that eventValue keeps a sum of all eventValues and even caculates Avg.Value). Does it mean item_id should be stored in eventLabel as string?
I added second, nonInteraction event for collecting item views, ga("send","event","Data","show","1234",1,{nonInteraction:true}). It count all events, but I need only unique ones (performed by unique visitors) in specified period of time (day, week, month). Is it possible?
1) The parameters are category, action, label and value. "Value" is a metric and is expected to be an integer. Since it's a metric it will be added up. So if you do
ga("send","event","Contacts","show","",1234)
you will increment a metric by 1234, not store an id. You do not want this (especially if you have a linked adwords account, since this will be used to calculate your "return on advertising spent").
You want to use your item_id as label, however label is a string. So what you need to do is:
ga("send","event","Contacts","show","1234")
i.e. wrap the value for your label in quotes.
2) Is there anything wrong with ga:uniqueEvents for your purposes ?

google ga api multiple dimensions value, return less data than I expected

Possible similar question: GA total results is significantly less with hour dimension than with date dimension
-hour-dimension-than-with-date-dimens
but i use samplingLevel=HIGHER_PRECISION
I am registering my events as follows:
ga('send', 'event', 'search_event_category', 'search_term', 'location');
category = search_event_category
action = search_term
label = location
I would pull a report via the ga api to return me on the rows the relationship between action and label:
["search_event_category",
"search_term",
"location",
"2"]
I got this return using the following parameters in the query:
metrics=ga:totalEvents
dimensions=ga:eventAction,ga:eventLabel
&filters=ga:eventCategory==search_event_category
&samplingLevel=HIGHER_PRECISION
&start-index=1
&max-results=10000
But I realized that the total results is less than I expected:
totalsForAllResults": {
"ga:totalEvents": "57623"
}
I expected totalEvents 80832. In GA interface, i get this value
when I send "dimensions=ga:eventAction" i get "totalsForAllResults": {"ga:totalEvents": "80832"}
when I send "dimensions=ga:eventLabel" i get "totalsForAllResults": {"ga:totalEvents": "57623"}
when I send "dimensions=ga:eventLabel,ga:eventAction" It looks like it does a 'inner join' and i get "totalsForAllResults": {"ga:totalEvents": "57623"}
I'm doing the right way?
UPDATE 1
I know how difficult without help data, but put here pictures that prove that there is in ga relationship that was not returned by the query
evidence that the relationship exists in ga
If you're sending events to GA that don't include an event label, then when you query for events and specify the ga:eventLabel dimension, events without a label will be dropped from the returned result set. That's the most likely reason for the number discrepancy.
To avoid this problem, I'll sometimes set the event label to "(not set)" to mimic how GA internally indicates that a dimension value is unknown.

Resources