Date of first session segment using Analytics V4 - google-analytics

Does anyone know how to build a dynamic segment, using Google Core Reporting API V4, that gets only users that had a given event action, and for which the first session was recorded on DD/MM/YYY.
Ex: looking for all users who "installed" (first session) the (mobile) app on Dec 14, and have generate at least one event "clicked xxxx".
No way to find this in docs.
On google analytics dashboard, this can be achieved by creating a segment with a "Date of first session" value.
Thanks a lot,

You cant do this with a segment but i'll give you another option:
You can take advantage of the 'ga:sessionCount' parameter. Just make a query for all sessions en X day and another one of all N events in Y day. Finally, cross the data of X and Y day and you will end up with every user that had his first session on X day and made N events on Y day.
(Use ClientID as KEY when crossing the data)

Related

How can I only fire a tag from Monday to Friday 09.00-17.00?

We only want to show our live chat tag Monday to Friday, from 09.00 until 17.00. Is this possible with Google Tag Manager please?
Thanks!
Preferred solution
The best solution is probably to get the current date on the server side and push to the datalayer a variable that determines whether the chat tag should be triggered or not depending on this date.
Alternative
The alternative is to retrieve the date on the client side which won't be 100% reliable. In order to use this solution, you need to create a Custom Javascript variable with the following code (replace "America/New_York" by your business' timezone) :
function (){
const currentDate = new Date(new Date().toLocaleString("en-US", {timeZone: "America/New_York"}));
const day = currentDate.getDay()
const hours = currentDate.getHours()
return day > 0 && day < 6 && hours >= 9 && hours < 17
}
Then, trigger your chat tag only when this variable's value is "true".
If you want to get a consistent, reliable date, ListenLayer.com returns a timestamp with every data dataLayer push. The time can appear in a single account timezone based on your account settings, so if you align your ListenLayer timezone to your chat time zone it will work.
You can then write rules in the platform to determine if the time returned should allow for chat. You will output a yes/no into a new data layer variable based on the rule. Then you will register this variable in GTM and use it to determine if the chat tag should fire.
Here is the process I would use at a high level
Create an account and set the account time to match your chat timezone
Turn on the User Source Listener and all it's features,
enable it to push on every page load This will push the user's traffic source into the data layer, along with a bunch of other structured data on each page load. You could use another listener, but this one will allow us to ensure it pushes on every page load (container load) so that GTM will know on every page load whether to trigger the chat script.
Create a custom data layer variable called chatTime. We will write a rule in ListenLayer to push a yes or a no into this variable based on the time that is returned in the userSource data layer event. This will happen in real time, in the same event in the data layer.
Publish everything in listenlayer and then go to your website with the console open (the data layer is written there for ease). You'll see the userSource dataLayer event in the console on every page load. It will contain an eventTimestamp. You want the data that is inside the listenlayerAccountTime node because it will match your ListenLayer timezone, which should match the timezone you operate your chat hours from (or if all of this is based on the user's time zone, use that one to be localized to them). You will need to focus on these two variables that are automatically provided because we will write a rule based on them in step 5:
sourceAutomaticValues.eventTimestamp.listenlayerAccountTime.time.timeOfDay
sourceAutomaticValues.eventTimestamp.listenlayerAccountTime.time.dayOfWeek
Here is a visual showing those variables I have given a path to above. One of the day of the week and one is the time of day.
Inside ListenLayer, under the User Source listener you will create two rules, they will be lookup table rules. The first rule will run first, then the second. If a match is found, they will stop. This means we can write the first rule to basically just look at the day of the week and set chatTime to no if the value is Sat or Sun. The second rule will then focus on the time of the day since this rule will only be reached if it is not Saturday or Sunday. In this rule we will look at the first part of the timeOfDay variable using simple ReGex. Our rule has 24 rows for each hour of the day and will return a yes only for the hours you are open for chat. Certainly this rule could be made simpler with some additional regex, but this gives a better illustration. There is an import export so you could spin up the 24 row rule in a csv file and import it.
After you save and publish this simple logic, your website will have a value in the data layer telling google tag manager whether chat should be on. It will appear in the data layer every time the userSource event is pushed, which is every page load.
I assume things are easy from here. You would create a data layer variable inside GTM referencing sourceCustomValues.chatTime You'll also create a custom event trigger referencing userSource and only firing if chatTime = yes. Then you will set your chat tag to fire on this trigger.

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.

Percentage of returning visitors in google data studio

Here what I want is get the number of returning visitor in percentage in scorecard.What I tried is tried creating calculating filed but didn't able to succeed
What I tried is applied the usertype = "returning visitor" filter but it shows only number and I want percentage.
Expected result is %returning visitors
Unfortunately, this method isn't entirely accurate. GA double counts a user if they are both a returning user and new user if they complete more than 1 session within the time period that you have listed.
My work around is to blend a data source with itself: 1 with a Google segment for returning users, 1 without.
The formula for the calculated field should use these two metrics:
ga:users (Users): total number of users
ga:newUsers (New Users): total number of new users
ga:newUsers/ga:users will give you the percentage of new users, the rest would be return. So just subtract the % from 1. Like so
Returning visitor in data studio
Showing the total number of returning visitors via the Scorecard
There is 2 ways to make it
1
Step 1
usertype = "returning visitor" pie chart or in table
Just make a new Pie chart or table then add to demensions Usertype
Step 2:
Add a new scoreboard
Make a filter for scoreboard just to show Returning of New visitors.
Done !! Showing the total number of returning visitors via the Scorecard.
Step 3 showing as a %
Add a new scoreboard without any filter and just show session.
Click at Scoreboard which shows Returning or New visitors. Click also in sametime at the scoreboard which shows session.. then right click on the mouse, choise the Merge data options.
Data studio makes automaticly percentage of both data. You get it!!!!
Second Way
You'll need to create a segment for in Google Analytics to use in Data Studio
Make a segment for returning visitors in Google Analytics.
Add a new scoreboard in data studio, choose just made segment. You will see the total Returning visitors in scoreboard.
follow step 2 and 3 ..
Good luck..

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 ?

Deleting intermediate record from Google Calendar recurring event

I am working with Google calendar recurring events. I created a recurring event and by using GData library, in response i get the the perimeters "COUNT", "FREQ" , "UNTIL" etc... where COUNT=5.
The problem is, when I delete an instance from this recurring event(total instance are 5 in this case), 4 instances are left in google calendar. but in response COUNT is still 5, it should be 4 now. Also in response i am not getting any details about that deleted instance.
Can any one help me in this regards.
I am very thankful in advance!!!
waiting for your reply!
This is working as intended. If the count indeed changed that would mean that the last instance should not be there anymore. While you could have deleted the second instance. In the v3 API the deletion of the second instance will be represented by an event with status=cancelled and "recurringEventId" + "originalStartTime" set to point to that specific instance.
There is a handy instances() call if you want to see all the instances of a recurring event.

Resources