I have events from:
11:30 AM to 1:30 PM
3:45 PM to 5:45 PM
7:00 PM to 12:00 AM
I am trying to get all the empty calendar slots in within the timeMin and timeMax duration.
Yet when I do at freebusy API:
{
"timeMin": "2021-03-25T11:42:20.698908-04:00",
"timeMax": "2021-03-25T22:42:20.698908-04:00",
"calendarExpansionMax": 10 #doesn't make any difference
}
I get:
{
"kind": "calendar#freeBusy",
"timeMin": "2021-03-25T15:42:20.000Z",
"timeMax": "2021-03-26T02:42:20.000Z"
}
which I don't know what it even represents nor does it make it clear. I am not sure why it's even going post the timeMax duration I allowed by going to the next day (26th).
If the freebusy api isn't the solution, has anyone built a solution for it in python, as there are many SO answers and libs for javascript.
You have missing parameter item[] in your request. This is where you put the calendar id which the request will do its query.
Your request parameter should look like this:
{
"timeMin": "2021-03-25T11:42:20.698908-04:00",
"timeMax": "2021-03-25T22:42:20.698908-04:00",
"timeZone": "UTC-4",
"items": [
{
"id": "insert the calendar id here"
}
]
}
Output:
{
"kind": "calendar#freeBusy",
"timeMin": "2021-03-25T03:42:20.000Z",
"timeMax": "2021-03-25T14:42:20.000Z",
"calendars": {
"calendar id here": {
"busy": [
{
"start": "2021-03-25T11:42:20+08:00",
"end": "2021-03-25T13:30:00+08:00"
},
{
"start": "2021-03-25T15:45:00+08:00",
"end": "2021-03-25T17:45:00+08:00"
},
{
"start": "2021-03-25T19:00:00+08:00",
"end": "2021-03-25T22:42:20+08:00"
}
]
}
}
}
Since it only return the busy time range, you have to calculate the free time in your script.
Related
My goal is to pull in purchase transaction count and transaction revenue from a client, segmented by Google Ads campaign ID. My current query looks like the following:
{
"propertyId": "*********",
"query": {
"dateRanges": [
{
"startDate": "2022-09-30",
"endDate": "2022-10-06"
}
],
"dimensions": [
{
"name": "googleAdsCampaignId"
},
{
"name": "googleAdsCampaignName"
}
],
"metrics": [
{
"name": "advertiserAdClicks"
},
{
"name": "advertiserAdCost"
},
{
"name": "transactions"
},
{
"name": "purchaseRevenue"
}
],
"dimensionFilter": {
"andGroup": {
"expressions": [
{
"filter": {
"fieldName": "googleAdsCustomerId",
"stringFilter": {
"matchType": "EXACT",
"value": "*********",
"caseSesnsitive": false
}
}
}
]
}
}
}
}
What I expect when querying the 'transactions' dimension is, as the API schema describes, "The count of transaction events with purchase revenue. Transaction events are in_app_purchase, ecommerce_purchase, purchase, app_store_subscription_renew, app_store_subscription_convert, and refund."
The response from my query comes back with these numbers, for an example campaign:
{
"dimensionValues": [
{
"value": "***********",
"oneValue": "value"
},
{
"value": "Example Campaign",
"oneValue": "value"
}
],
"metricValues": [
{
"value": "2482480",
"oneValue": "value"
},
{
"value": "6492393600000",
"oneValue": "value"
},
{
"value": "331",
"oneValue": "value"
},
{
"value": "31374.205645000002",
"oneValue": "value"
}
]
}
However, if, in the GA4 dashboard, I attempt to view a report of purchase conversions by campaign over the same date range, this is what is displayed for the 'example campaign':
6 Example Campaign 239.47 31,981.63
Where 239.47 is the number of transactions, and 31,981.63 is the event value (transaction revenue). Notably, the transactions are off by over 25%. The revenue/event value is similar but also off by a slight amount. This is consistent for all campaigns under the client, with the API response being significantly (but by varying percentages) higher. The dashboard value is always lower. These numbers don't change if the report is run on different dates.
Additionally, I suspected that there may be some additional event being tracked under the transactions api field that was not displaying in the dashboard, so I also tried adding this filter to my query:
{
"filter": {
"fieldName": "eventName",
"stringFilter": {
"matchType": "EXACT",
"value": "purchase",
"caseSesnsitive": false
}
}
}
the transactions field still came back as 331.
What I want to figure out is if I'm querying the wrong field, the frontend is under reporting data, or the API is over reporting data. I found that I was not able to post on the official GA4 Issue tracker so I've come here.
Someone better versed in GA4 at my company explained that the issue here had to do with dimension scopes. The transactions field is session scoped, but the dimensions I was pulling in were event scoped. This means that the numbers being output were basically meaningless. As a matter of fact through the dashboard, it won't let you create a free-form explore report using the combination of fields that I did in my query, explaining that the metrics are incompatible. It appears to just be a bug that the API would allow that to happen.
As an alternative, I'm now pulling the conversions field, with a filter on eventName as listed above, including only purchase events.
In my Google calendar, which is in the America/Toronto timezone, I have an event that is marked as an all day on the 13 April 2022, but it is coming back as starting on 2022-04-13 and ending on 2022-04-14. I have some other all day event behaving in the same way.
This is happening from my code, but also when I try with the API test form here:
https://developers.google.com/calendar/api/v3/reference/events/list
With parameters:
timeMin: 2022-04-10T18:36:39.000Z
timeMax: 2022-04-17T18:36:39.000Z
This returns me the following response (certain fields masked):
"kind": "calendar#events",
"etag": "\"p328ftm5rim7ve0g\"",
"summary": "My Test Calendar",
"updated": "2022-04-12T18:36:40.074Z",
"timeZone": "America/Toronto",
"accessRole": "owner",
"defaultReminders": [],
"nextSyncToken": "xxx-xxxx_cCEJD-2LuVj_cCGAUg8t3t0QE=",
"items": [
{
"kind": "calendar#event",
"etag": "\"3299577200148000\"",
"id": "xxxxga02nqb11ub6dm29dgg9t",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=xxxxxxnYTAybnFiMTF1YjZkbTI5ZGdnOXQgY19uZ2hqOXFzb25tYjRtNDRqN2doaTNxNzY5a0Bn&ctz=UTC",
"created": "2022-04-12T18:36:39.000Z",
"updated": "2022-04-12T18:36:40.074Z",
"summary": "Dummy Event",
"creator": {
"email": "xxxxxx",
"displayName": "xxxxxx"
},
"organizer": {
"email": "xxxxxxx#group.calendar.google.com",
"displayName": "My Test Calendar",
"self": true
},
"start": {
"date": "2022-04-13"
},
"end": {
"date": "2022-04-14"
},
"transparency": "transparent",
"iCalUID": "xxxxx#google.com",
"sequence": 0,
"reminders": {
"useDefault": false
},
"eventType": "default"
}
]
}
I tried providing both 'America/Toronto' and 'UTC' as timeZone parameters in the request, but this does not change anything.
Can anyone suggest how to get an all day event to span only the day it is meant to be happening on?
BTW below you can see the event was only on a single day:
This is an expected behavior from the Calendar API. All day event last for 24 hours. Lasting from midnight of start date to midnight of the next day.
It is also written in the Event Resource that end is exclusive.
An alternative solution to this is to -1 the end date of the response body or manually plot the time. But if you try to manually create an All day event by plotting the time, It can only last for 23.5 hrs.
I'm currently fetching data from google calendar freebusy endpoint: https://www.googleapis.com/calendar/v3/freeBusy with the following request object:
{
"timeMin": "2021-12-31T10:30:00.000z",
"timeMax": "2022-01-12T09:30:00.000z",
"calendarExpansionMax": 11,
"groupExpansionMax": 11,
"items": [
{
"id": "ali.mojiz1#gmail.com"
}
]
}
I want to change the dates dynamically in the aforementioned object so that I can get data from the last and next 30 days based on current date for e.g. timeMin changes to 22nd December'21 and timeMax changes 22nd Feb'22.
I've tried the following to get data for the next 30 days from today but it doesn't work:
{
"timeMin": "2022-01-22T10:30:00.000z",
"timeMax": "{date.add(30).format('yyyy-MM-ddT23:59:59Z')}",
"calendarExpansionMax": 11,
"groupExpansionMax": 11,
"items": [
{
"id": "ali.mojiz1#gmail.com"
}
]
}
Any help would be appreciated. Thanks!
the following goes back to 30 days from today for e.g. today's 25th Jan'22 so this will give you 25th Dec'21.
"timeMin": {
"function": "concat",
"args": [
{
"function": "date",
"args": [
"Y-m-d",
{
"function": "strtotime",
"args": [
"-30 days",
{
"function": "time"
}
]
}
]
},
"T00:00:00-04:00"
]
I'm trying to make calls the Analytics Reporting API V4 and keep getting back unspecific error messages when trying to use certain dimensions and metrics. For example, I consistently get
{
"error": {
"code": 400,
"message": "Unknown dimension(s): ga:acquisitionTrafficChannel",
"status": "INVALID_ARGUMENT"
}
}
when passing ga:acquisitionTrafficChannel, despite it being documented as a valid dimension. Similarly, I get
{
"error": {
"code": 400,
"message": "Selected dimensions and metrics cannot be queried together.",
"status": "INVALID_ARGUMENT"
}
}
when passing ga:acquisitionSourceMedium (documented here), even when not passing any metrics whatsoever.
Are the docs out of date? Is there some documentation elsewhere about valid combinations of dimensions and metrics?
All the Lifetime Value reports and thus ga:acquisition... dimensions are only valid for App views not web views.
Secondly the cohort/LTV dimensions can only be queried in within a cohort requests for example:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests": [
{
"viewId": "XXXX",
"dimensions": [
{
"name": "ga:cohort"
},
{
"name": "ga:acquisitionTrafficChannel"
}
],
"metrics": [
{
"expression": "ga:cohortSessionsPerUser"
}
],
"cohortGroup": {
"cohorts": [
{
"name": "cohort 1",
"type": "FIRST_VISIT_DATE",
"dateRange": {
"startDate": "2015-08-01",
"endDate": "2015-09-01"
}
},
{
"name": "cohort 2",
"type": "FIRST_VISIT_DATE",
"dateRange": {
"startDate": "2015-07-01",
"endDate": "2015-08-01"
}
}
],
"lifetimeValue": true
}
}
]
}
The error messages should probably be a bit clearer.
I ran into this problem as well. When I was in the Google Analytics Dashboard, I clicked on Acquisition->All Traffic->Channels and was fooled into thinking that I needed to combine the ga:acquisitionMedium dimension and ga:newUsers metric together.
When I clicked on ga:acquisitionMedium, it said that combining it with ga:newUsers was valid, despite the error that you mentioned in your question! In reality, I just needed to combine ga:medium and ga:newUsers together.
I know this is not the exact query that you were doing, but here is an example of how I queried New Users count where the dimension channel equaled "organic" (note that I am forming the JSON request with Javascript and then using JSON.stringify(req) to send it):
var req = {
reportRequests: [{
viewId: '<Your Google Analytics view ID>',
dimensions: [{ name: 'ga:medium' }],
dimensionFilterClauses: [{
filters: [{
dimensionName: 'ga:medium',
operator: 'EXACT',
expressions: ['organic']
}]
}],
dateRanges: [{ startDate: '2019-11-01', endDate: '2019-11-30' }],
metrics: [{ expression: "ga:newUsers" }]
}]
};
The above query returns 5,654, which is the same as seen in the "Acquisition" section of Google Analytics.
I definitely think the documentation and error message around this could be improved.
I want to query Google Calendar though its REST API. After having authenticated I request events between timeMin and timeMax. In the case below, this is +/- 7 days from 'now' (between 2015-09-30T14:19:46.595026+02:00 and 2015-10-14T14:19:46.594026+02:00):
curl -H 'Authorization: Bearer the-token-I-got-and-which-is-OK' 'https://www.googleapis.com/calendar/v3/calendars/something_correct#group.calendar.google.com/events?timeMax=2015-10-14T14%3A19%3A46.594026%2B02%3A00&timeMin=2015-09-30T14%3A19%3A46.595026%2B02%3A00'
As a result, I get two events - but the times are wrong:
{
"kind": "calendar#events",
(...)
"items": [
{
"kind": "calendar#event",
(...)
"start": {
"dateTime": "2015-01-09T07:00:00+01:00",
"timeZone": "Europe/Paris"
},
"end": {
"dateTime": "2015-01-09T07:15:00+01:00",
"timeZone": "Europe/Paris"
},
(...)
},
{
"kind": "calendar#event",
(...)
"start": {
"dateTime": "2015-01-10T07:30:00+01:00",
"timeZone": "Europe/Paris"
},
"end": {
"dateTime": "2015-01-10T07:45:00+01:00",
"timeZone": "Europe/Paris"
(...)
}
]
}
There are two events from January. They do exist in the calendar and were the first two events in that calendar (they are recurrent events, with no end date).
Why aren't the time constraints effective?
If I remove the time constraints I get more events but still not all of them (which I suppose may be a limitation o the API, requiring some scrolling - I have not investigated that point as my time constraints would match about 10 entries only). The dates are varied, but closer to January than to now.
I was missing the singleEvents parameter, which is False by default.
Whether to expand recurring events into instances and only return
single one-off events and instances of recurring events, but not the
underlying recurring events themselves. Optional. The default is
False.