How to delete orphaned Google Calendars + Events? - google-calendar-api

My app performs a one-way sync to Google Calendar. As in, if you create an event in my app it will be added to Google Calendar, but you can't update that event from Google Calendar.
I store all the Google Calendar IDs and Event IDs that their API gives me back so that I can update the calendars + events later.
However, I'm concerned about orphaned records. If, for example, someone deletes an event in my app but either the API request fails to delete the corresponding event from Google Calendar or my app has a bug in it, then that record will become orphaned -- it will exist on Google Calendar but I will have no reference to it.
So what's the best way to delete orphaned records?
Here are my ideas:
Download a list of every single event ID in Google Calendar, fetch all the event IDs out of my database, do a set subtraction to determine which ones are orphaned, and then delete those one-by-one.
Delete the entire calendar if I notice a mishap, and then re-sync all the events.
The problem with (1) is that it might get quite memory intensive once I've accumulated a lot of events. The problem with (2) is that a full re-sync can take awhile and those events will be missing from Google Calendar while the sync is happening. Plus, I might have a race-condition if users are creating new events during the sync.
What's the best approach? Are there any other solutions?

Related

Getting programmatic access to Firebase Analytics trending events

I have a mobile app which plays audio tracks. It uses Firebase Analytics to record events such as 'track names' played. Within the Firebase 'StreamView' one can access trending events and see which are the most popular tracks being played at any given moment. I would like to gain access to this list to and use it within my app to display a list of "tracks being played now".
I've looked into gaining access to Analytic trending event data and think Firebase Cloud Functions may provide a method of extracting the information I need. However, I'm not certain this is the correct, or easiest, method.
Could someone let me know whether extracting trending events is possible and, if so, point me in the correct direction?
Thanks
EDIT - Actually, there is a much better and easier way to get access to real-time events that have occurred in your app over the last 30 minutes. You can do so using the Google Analytics Data API.
Using the API you can filter through the event data for the past 30 mins, and inspect relevant custom dimensions on the play_track event for the track that was played (or provide a custom dimension filter to further specify the event data you get back).
This would be the ideal way to achieve what you're looking for. You might still want to use Cloud Firestore if you'd like to keep a longer record of trending tracks being played (e.g. in the last hour, last 24 hours, etc... though). Also note that the API is still in alpha.
-- END OF EDIT
Other Solutions
Option 1 - Use Cloud Firestore
This is probably the easiest solution - you can create a record of which tracks are being played whenever the event occurs by creating a simple collection in Cloud Firestore, and updating records for tracks being played there. It would require additional effort in logging and retrieving which tracks are played beyond just using Google Analytics, but should be straightforward to implement.
Note you'll probably want to check out the Firestore pricing guide first before selecting this option.
Option 2 - Using Firebase Cloud Functions
You can trigger a Cloud Function each time a play_track event is logged. The event will need to be marked as a conversion event in order for it to trigger a Cloud Function, and within the Cloud Function you can access the event parameters to identify which track is being played, and over time maintain a record somewhere for which tracks are being played to determine the most trending tracks. To maintain state you could use something like Firestore to keep track of which "tracks" are being played at the moment.
A couple of caveats about this approach:
You'll want to check out the Cloud Functions for Firebase pricing guide to make sure it falls within an acceptable range for your needs.
Cloud Functions triggers for analytics events currently only works for Android and iOS apps (no support for web apps).
Google Analytics triggers for Cloud Functions is currently in beta.
Option 3 - Using BigQuery for your analytics data
This option requires a bit more effort to setup, but you can export your Google Analytics data to BigQuery, and query the generated intraday tables to see which tracks are trending as well as a lot more additional insights.
The caveat with this approach are that you'll also need to check the pricing guide for using BigQuery to make sure it falls within your needs, and you'll need to make a call to execute the query and retrieve the list of tracks (or get a cached result).

How to find out deletion time of an event with CalDAV?

Problem description
I am using CalDAV to sync events between Google Calendar and my own calendar application. Right now i am trying to implement Deletion and Restore functionality:
Every time something is synced between my two systems, i write (meta)info about the synced event in a json file. So using that file i am able to tell in a particular moment which event were synced already and are not anymore present in the CalDAV side (Google Calendar in my current case, but could be any Calendar service that support CalDAV). So, telling if an already-synced event was deleted on the CalDAV side is no problem. Now i would like to know WHEN did the deletion take place.
What i have tried
So far i tried simply retrieving all events with
<?xml version=\"1.0\" encoding=\"utf-8\"?><d:propfind xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\"><d:prop><d:getetag /></d:prop></d:propfind>
But this only returns information about the existing (not deleted) items.
Also i tried retrieving the deleted event using its id with:
<?xml version=\"1.0\" encoding=\"utf-8\"?><c:calendar-multiget xmlns:d=\"DAV:\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\"><d:prop><d:getetag /><c:calendar-data/></d:prop><d:href>{eventName}</d:href></c:calendar-multiget>
But this returns HTTP 404.
Does anyone know (or has any suggestion on) how to find out the deletion time of an event using CalDAV?
UPDATE
I found out that using Google Calendar API it is possible to retrieve a list of all the documents, and this list could include deleted ones by setting the property showDeleted to true.
But the question remains:
Does anyone know how could i implement something like this with CalDAV?
Deletion is a peculiarity of Google Calendar, and not necessarily supported by all other calendars, that is why it is not possible to obtain deletion information using just CalDAV.
You could use GoogleCalendar API to take advantage of the deletion information for that particular case while implementing CalDAV in your application: It would be something like Server-Specific functionality.

Sending custom event data to Google Analytics

I need to track events in Google Analytics from a server through the Measurement Protocol. I can do this just fine, but my problem is that I want to send additional/custom data along with the event. Specifically, I want to send a UUID along with the event so that it is possible for me to fetch data from the Google Analytics API in the future and correlate events with rows in a relational database.
Is there any decent way to send custom data along with events? I looked at using the event value, but it must be an integer, and it is not intended for things like this. The event category, action, and label are reserved for other purposes.
I am not that proficient in Google Analytics, so the solutions off the top of my head would be:
Send an additional event containing the UUID in the event label or something like that. Seems like a bit of a hack/workaround to send two events, with one being used exclusively behind the scenes.
Perhaps using a custom dimension or metric. I am not 100% sure about the implications of this and if that's a decent approach or not.
So basically my question is: what would be the best way for me to send a UUID along with a Google Analytics event from a server, taking into consideration that I cannot use the event category, action, and label for the current event? Is there any other way in which I could link events retrieved from the Google Analytics API to rows in a database?
So let's say I trigger a "Completed Order" event to GA, and I also have orders in a MySQL database. So what I want to do, is to link an event to an order row in the database.
There are several things that you can do and it pretty much depends on what you want to do with the information you are storing. For starters, all your requests should include the uid field with the value being the user ID within your system. This way all Google Analytics data will be calculated on the same user. Note: this is an internal value used within Google Analytics and you won't be able to see it.
Second, I would create a custom dimension of the name user_id and store the user information in that. You will then be able to use this information within your reports to see what each user is doing. Note: it's against TOS to send user name, email, or any other PII (personally identifiable information) to Google Analytics. But you can send your internal user ID.
I have done both of these in the past and found it to work quite well.
More info on User-ID.

How to delete an Analytics Event from Firebase

How can I delete an Analytics Event from Firebase?
While I am testing I wrote some events in Firebase Analytics. Firebase by default orders all events alphabetically. So these testing events interrupts with original events.
I could arrange them by count to push all the testing events to last. But it makes difficult to find the main events since those are not alphabetically sorted.
I didn't find any options in Firebase dashboard to delete a event. Is there a way to delete the old events from firebase?
There is currently no way to delete events once they are logged into Firebase Analytics that I am aware of. However, the events will drift out of the default view (which is set to "last 30 days") as time goes on, or you can switch the time period to a shorter time. As you mentioned, you can also click a column header to sort by some other value or "add filter" to filter by an audience or user property.
You can create a new Firebase project if you want to start from scratch. It's also a fairly common practice to use one project for experimentation and validation of your analytics implementation and then to switch to your production Firebase project when everything looks good.
It is not possible to delete analytics events AFAIK, but on some views you can set up the time interval with the filter at the right-top corner to limit the listed events. In the audience set up you need to rely on typing, I am afraid.
As of 31 May 2018, there is an API for this. Doesn't delete individual events, but you should be able to use it to delete all the events collected by a particular app instance:
User Deletion API v3 (UserDeletion.userDeletionRequest)
It was introduced in this blog post and the intended purpose (user privacy) is described here (last paragraph).
Unfortunately, based on my own question, no one seems to have figured out how to get it to work :(
EDIT
Turns out that, according to Google, this API does delete events (which technically is what the OP was asking), but since the aggregate total remains visible on the Firebase console, it won't help with the OP's specific use case.
As Steve Ganem suggested the simplest thing you can do to reset the Firebase Analytics data is to register new Firebase project and that in your app. You can also keep the old project around for debugging/development.

Copy Event from One Calendar to another

I am creating an app in asp.net for Google calendar integration. When we insert a particular event to the calendar then at the same point i want to copy the same calendar event in to another calendar and i want to do the same process in a single request. So may any one please guide me for this problem. I am using google calendar version 3 for this. Thanks in advance
Is it necessary that they be two separate Calendar events? If not, you should be adding the second calendar as an attendee of the event rather than creating a copy of the event. See the events reference and look for the attendees list attribute. This can be achieved in a single API call.
If it is indeed necessary that the events are entirely separate and independent of each other, it will require two events.insert() operations, one on each calendar. However, as long as the user you are authenticating as has access to both calendars, it should be possible to batch the two operations into a single HTTP call.

Resources