I am using Google Calendar API and push notifications to add channels and watch those channels for new events that come in. However while tracking weird behavior with mixing calendar accounts and events I found out that the resource ID that the calendar API responded with is the same across two accounts.
I am not sure if this is the culprit yet but this is the definition of resource-ID from docs
X-Goog-Resource-ID - An opaque value that identifies the watched
resource. This ID is stable across API versions.
In my mind this means it should be unique. Resource-ID and channel-ID are a requirement for stopping channels after all.
Examples of identical resource-ID from google for two different accounts
Account 1
X-Goog-Resource-State: exists
X-Goog-Channel-Token: 56cab177e67348d9a17c7502a4bad513
X-Goog-Resource-ID: 8KXz6YKChAJDYMTUo0SoKqV8_7E
X-Goog-Channel-ID: ++7mlvx6pEIsTNeMpMwNLw==
Account 2
X-Goog-Resource-State: exists
X-Goog-Channel-Token: 4535832bc5cf47f7ae3403c404023bfd
X-Goog-Resource-ID: 8KXz6YKChAJDYMTUo0SoKqV8_7E
X-Goog-Channel-ID: mL+HzrG8/EYc7zRZdQ+6yw==
My question is, is this normal behaviour?
The push notifications channel does not provide updates on individual events. It only tells you when the calendar (collection of events) changed.
To find changes to events, you want to look up syncing.
With syncing, you send in a token you got from the last time you synced to the List API endpoint. Instead of listing all events, it will list only the ones that changed since your last since request, represented by the sync token.
You can POST to the List API any time you want to get changes to events, but the push notifications you described help tell you when there would be a meaningful change to call the sync.
Related
Is it possible to use GA4 Measurement Protocol to send events to Google Analytics and view and analyze them in the GA dashboard without using gtag.js or any other front-end script? The use case would be that some events are being sent to my server and I will just push these events to GA through the API.
One thing that makes me think is that the official Measurement Protocol API say:
In order for an event to be valid, it must have a client_id that has already been used to send an event from gtag.js. You will need to capture this ID client-side and include it in your call to the measurement protocol. In send an event to your property, we use "client_id" as the client_id. You will need to replace this with a real client_id that comes from gtag.js.
(https://developers.google.com/analytics/devguides/collection/protocol/ga4/verify-implementation?client_type=gtag)
That suggests that only events that have a valid client_id that originate from gtag.js will be counted.
I did some experimenting with randomly generated client_ids and what I discovered was that I was able to see my events in the Realtime section of the GA4 console (the Event count by Event name section), but all the other sections would be empty and the Users in last 30 min section would always show 0.
Can someone please explain to me why it's zero and if such a use case is valid at all? Thanks
tl;dr
You can use any value in client_id, as long as it uniquely identifies the user (we use a GUID/UUID), but it seems like you also need to send a value in user_id. We use the same value for both.
Also, you need to add the 'engagement_time_msec' parameter to get any user metrics to register.
Longer answer:
We're trying to do the same, i.e. send all events to the GA4 Measurement Protocol from the server, so that it is not dependent on the current user's GDPR cookie settings.
We currently do this for a Universal Analytics property with no issues, but it seems that Google is trying to prevent this in future, by restricting the scope of the Measurement Protocol in GA4, whilst forcing everyone to move to it by July 1st 2023. See the documentation at https://developers.google.com/analytics/devguides/collection/protocol/ga4#full_server-to-server, where it states:
While it is possible to send events to Google Analytics solely with
measurement protocol, only partial reporting may be available. The
purpose of measurement protocol is to augment existing events
collected via gtag, GTM, or Firebase.
We have something working with GA4, in that the events are being registered on the GA4 property correctly, using a client id that is just a GUID/UUID that we define in our own site cookies. So, any value can be used in the client id, as long as it uniquely identifies the user. The same value is used to populate the user_id parameter.
When sending events, the realtime event details were showing on the GA4 dashboard, but user metrics were not until we also populated the 'engagement_time_msec' parameter, as described in https://stackoverflow.com/a/71482548/7205473
We still have issues with things like getting the user location and the platform details, which previously were automatically populated by passing the IP address and the User Agent, but which seem to no longer work in GA4.
We were also passing page load timing events through the Measurement Protocol, but again, these features seem to have been removed in GA4.
It is possible to use GA4 directly without gtag.ja or the Firebase SDK. Its not supported, so it takes some work. We have this working in a desktop app reasonably well. There a couple things that need to be done.
As stated elsewhere the "engagement_time_msec" param must be set using the "_et" parameter. This is the number of milliseconds between now and the previous event.
The client id "cid" has a specific format; it should be:
"randomNumbers(10).unixTimeStamp()"
The session id "sid" format is:
"randomNumbers(10)"
The "_z" parameter needs to be set. I think this is a cache buster. Looking deep into the gtag.js code it is a url safe base64 encoding of "CCD", which always results in the value "ccd.v9b"
The page hash parameter "_p" can be set to this; not totally sure its correct but it works.
"randomString(3).randomString(3)"
Set the "User-Agent" HTTP request header in whatever framework/lib you are using. GA4 uses this to determine many things including Operating System. You will need to create a fake user agent based on the local device information. This is what we use for a Windows 11 x64:
"myco.testapp/4.0.0 (Windows NT 10.0; Win64; x64)"
The IP will be taken fromn the web request which is where the geolocation data comes from.
Since a full working example is worth 1,000 words of documentation; here is a "test" event with a parameter "animal=dog":
https://www.google-analytics.com/g/collect?cid=0078745494.1659679529&_et=364&_p=pfJ.Aev&seg=1&sid=2678664821&tid=G-???&ul=en&v=2&_z=ccd.v9b&en=test&ep.animal=dog
It's possible to extract outgoing GA4 request from a GTM container debug/preview view and map any GA4 (automatically collected and custom) event.
Example page_view request URL:
https://www.google-analytics.com/g/collect?v=2&tid=G-XXXXXXXXXX>m=3oes1i1&_p=1545013558&_dbg=1&cid=P%2FdJWyULMwcT21TMrzn7pZdlNt%2FxtttGVqGUmqNYbhc%3D.1669722847&ul=nl-nl&sr=2560x1440&uaa=x86&uab=64&uafvl=Not_A%2520Brand%3B99.0.0.0%7CGoogle%2520Chrome%3B109.0.5414.75%7CChromium%3B109.0.5414.75&uamb=0&uam=&uap=Windows&uapv=10.0.0&uaw=0&_s=1&_uip=XXX.XXX.XXX.X&sid=1674235261&sct=1&dl=https%3A%2F%2FXXXXXXXXXX.com%2F%3Fgtm_debug%3D1674235654105&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=OM%20test&jscid=XXXXXXXXXX.1669722847&seg=1&en=page_view
Tip: use Postman to analyse and experiment with parameters
regardless of the platform used to make a call the Measurement Protocol, you should use a client id generated by gtag.js, or the app ID if using Firebase.
I'm using calendar API to pull events of users in an organization that had installed my GSuite app as a service account (it just means that I have access to all the users in the organization).
I noticed some weird behavior - let's say I have an event with 2 participants - a and b (both are users in the company). when I use the calendar API events.list to pull event for a I get this event, and b is listed in the attendee list with responseStatus of 'accepted'.
When I pull the events for the same period of time for user b, I do not get this meeting, nor when I try to pull a specific event using the meeting id (event.get API). I also used showDeleted=True but still didn't get the event back when pulling the events of b (I'm pretty sure if the event would have been deleted then the responseStatus would have been 'decline').
What could be the reason for this behavior? I tried to reproduce it using two emails that I have access to, and I was not successful.
Since those are emails of my client I cannot just come up to them and ask what happened with this meeting.
This is the request I'm making (using python google API client):
from googleapiclient.discovery import build as Build
service = Build("calendar", "v3", credentials=credentials, cache_discovery=False)
service.events().list(calendarId='primary', timeMin=min_time, timeMax=max_time, pageToken=page_token, singleEvents=True).execute()
First I'm building the service using the service account credentials (delegating permissions to the current email), and then making the request to pull the events.
The min_time,max_time are strings like this - 2020-10-19T08:00:00+0000.
The pageToken starts as None but will change if there is a nextPageToken in the response.
This is the request I made to try and get the meeting of the user that appear as an attendee when pulling the event using another user's email & credentials:
service.events().get(calendarId='primary', eventId=<meeting_id>).execute()
But I'm getting 404 event not found response (This API returns deleted events - I've seen it)
I'm pulling all of the events correctly, and only saw this case on small number of the events (less than 5% of the meetings).
Any idea what could cause this?
Thanks!
I'm relatively new to Google Analytics and would like to have some inputs.
So I have a web application that people can install to create a backup and can do restores as well. The application has an API where you can see the statistics of the app i.e. number of backups made, restores made, and the number of clusters connected to this application.
Now I want to send these stats to google analytics with an interval of 10 minutes. I was wondering if I can send the status to Event with a unique UUID as Event Category, the backup/restores, or nodes as Event Labels and the number as Event Actions.
Is this the right approach to using Google Analytics Events? Or is there a better way to do it in GA? My requirement is I have to do it in GA or should I use a different hit type.
Given that we are talking API's you intend to use the Measurement Protocol?
And the UUID refers to the unique user? if so, you should look at the uid https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#uid
As to using Events versus Hits, using hits is probably easier on the reporting.
I've subscribed on google calendar push notifications (PN). Base synchronization processes using PN. I need to know if all events already loaded in calendar scope or not.
Is it possible to have a special marker in my request answer (request events for specified calendar based on subscribed channel information)?
If calendar has too much events, events will be loaded in few push notifications handling. I need marker for UI if calendar is synchronized completely. In my my usual logic I thought that calendar is already synchronized if first PN per calendar already handled. So I need notify my UI client with correct status (calendar_is_synchronnized, calendar_is_not_synchronnized) but I do not have any markers from google if the PN provides me load last events portion in specified calendar scope.
I haven't got elegant solution for my question. But I've solved issue with double call. The is no special API for this purpose, I've used algorithm:
after updating to sync token I try get all events for same calendar just to be able compare new nextSyncToken with current if it is the same.
if token is different if means the calendar sync is not completed yet.
If any better idea(s), you are welcome.
I am setting up Google Analytics Accounts for a Product which have multiple builds as frontend for same user base.
So we have one Product called X and have:
Web Build
Mobile Web
Android App 1
iOS App 1
Android App 2
iOS App 2 6.
The main point is identical APIs and User base is used in all platforms and apps. So if we have a user John Doe he can login in any of the web or apps.
We want to extract following information from Google Analytics.
Under User ID feature want, sessions aggregations of that user around all build and apps, but identifiable. So I can know that user John login to web yesterday and used mobile app today.
Each user belong to a customer (company) in our system. So want to segregate all information based on companies.
I already have achieved point 2 by creating a custom dimension in Google Analytics and believe that's the best way to do it.
Now need suggestions from Gurus on how to acheive point 1 using Google Analytics.
Either use single account and single property for all builds and apps
If yes, then how to identify those apps and builds in sessions
If I use multiple properties/apps in GA account then how to aggregate user sessions among all?
Looking forward to hear how guys around hand or should have handled this scenario. Cheers!
This question is extremely broad, IMO any answer your going to get is going to be primarily opinion based. So here is my opinion and a little extra info to boot.
The first issue you are going to have is that there is a difference between Mobile google analytics accounts and web analytics accounts. The two do not mix. Mobile analytics accounts insert screen views with a screen name. While web accounts insert PageViews with a document location.
There is no way to analyze between two different Google analytics web properties. Unless you intend your android and ios apps to run as websites and send it like its a webpage its not going to work. You could potentially download the data into your own system or big query and analyze it there. Comparing your custom dimension to see what the users have done differently. I would wonder at the quality of the analysis you will get as there will be no real way for you to compare the data and match it up beyond using your custom dimensions user id and possibly date.
I am adding this because I am not sure what your saving in your custom dimension.
The second issue you are going to have is tracking. Google analytics TOS does not allow you to send any identifiable information to Google.
The Analytics terms of service, which all Analytics customers must adhere to, prohibits sending personally identifiable information (PII) to Analytics (such as names, social security numbers, email addresses, or any similar data), or data that permanently identifies a particular device (such as a mobile phone’s unique device identifier if such an identifier cannot be reset).
You could for example send your companies customer id for John as a user_id but user_id is an internal valuable used for internal processing this is not something you can extract out via the api.
The User ID enables the association of one or more sessions (and any
activity within those sessions) with a unique and persistent ID that
you send to Analytics.
To implement the User ID, you must be able to generate your own unique
IDs, consistently assign IDs to users, and include these IDs wherever
you send data to Analytics.
For example, you could send the unique IDs generated by your own
authentication system to Analytics as values for the User ID. Any
engagement, like link clicks and page or screen navigation, that
happen while a unique ID is assigned can be sent and connected in
Analytics via the User ID.
The best you could do would be to create a custom dimension and send that with every hit username=johnscustomerId. Which you appear to have already done. This is what I have done in the past and it works perfectly well.