Google Calendar API V3: Identifying edited one-offs of recurring events? - google-calendar-api

I am currently listing all events from a Google Calendar using the "singleEvents" parameter set to true, which splits recurring events into individual events – which is good. However, I'm running into an issue when an instance of a recurring event is edited, and the edits are saved with the "Only this event" option in the Calendar UI.
What I need to do is be able to identify which of these recurring event instances have been edited, and which have not. It seems the API response data does not provide any indications of whether this is an instance of the unedited recurring event, or an edited one-off. The response for an unedited instance of a recurring event and an edited instance are more-or-less the same, save the description field, which was edited.
The reason I need to differentiate edited versus unedited recurring event instances is that I am dynamically creating event detail pages from the list of single events. I would like to have one page be for the recurring event itself, and another for a "one-off" of that recurring event. E.g:
allmyevents.com/events/my-recurring-event --> page showing recurring event with recurrence information
allmyevents.com/events/my-recurring-event/16-4-2020 --> page showing specific instance of recurring event, which has been edited
Currently, I'm able to do this by creating an entirely new event at the same date and with the same title as the recurring event instance I want to replace, and writing hacky comparison logic to tell if this is a replacement event, but this is counter-intuitive for event/content management.

Answer:
You can use the Calendar API Events: instances endpoint to return all instances of a recurring event. All the events which have been edited on their own will not be returned.
More Information:
The Events: instances endpoint of the Calendar API will return all instances of a recurring event for a calendarId and eventId specified. Any of these that have been edited are omitted.
It's a bit of a workaround, as these events can't be obtained directly, but by obtaining the list of events as you have already been doing and then removing the events which are returned by Events: instances, you can build a list of all the events which have been edited with the 'Only this event' option.
Psuedo-code:
You can do something like this:
eventsList = Calendar.Events.List(calendarId, singleEvents=true)
eventsInstances = Calendar.Events.Instances(calendarId, recurringEventId)
singleEvents = eventsList
for each instance in eventsInstances :
if eventsList.items contains instance :
singleEvents.remove(instance)
return singleEvents
Where the returned singleEvents variable will be a list of all the events that have been edited manually.
References:
Events: instances | Calendar API | Google Developers
Recurring Events | Calendar API | Google Developers

I've been puzzling through this same issue, and I think I've found a way forward that doesn't involve going through every single instance to check if they've been moved/edited:
Each event returned by the Calendar API has an iCalUID field. For a standalone event, this should match the event's id, with an #google.com suffix. e.g. an event with the id of abcdef has an iCalUID of abcdef#google.com.
When it comes to recurring series, every single instance of that event has the same iCalUID value - and, most importantly, you can use iCalUID as a filter when listing events, which will return the main recurring series event and all modified instances. Unmodified instances are not returned.
Tracking which instances have been deleted is slightly more fiddly. They might be returned in the list with the matching iCalUID, but with a status set to cancelled. Or, they may be specified within the recurrence property (an array of strings) on the main series event as timestamps (within the given time-zone, which should match whichever time-zone the main series event uses):
[
"RRULE:FREQ=WEEKLY,COUNT=5",
"EXDATE;TZID=Australia/Melbourne:20211227T110000,20220103T110000"
]
I haven't figured out why some recurring events use the specific-instances-as-cancelled approach, and others use the EXDATE approach (and I think they can also be combined, so don't presume the presence of one rules out the other). Given both are possible, you'll have to allow for that.

Related

Outlook events sent to a google calendar - event ids change unexpectedly?

I am creating a meeting series from an outlook client, on an office365 mailbox.
The invited user is on g-suite (email, calendar...).
My code connects to google calendar via the API and periodically checks of event changes \ new events \ cancelled etc.
I store the event ids in my database and use them to match to the event IDs I read from google calendar.
When a whole meeting series is changed - for instance a weekly series gets a new starting time - the event IDs returning from google calendar APIs - change!
I am not sure if the IDs are generated by office\outlook or by g-suite.
I am not sure what's the right way to match the events I stored with their old IDs, to the new events coming in.
If you read the Google API Documentation, it states that recurring events are composed of instances. The recurring event is a parent and individual instances are its children. Each child has a recurringEventId which identifies its parent. Their individual instance ids might change when they are changed.
See the following: https://developers.google.com/calendar/recurringevents#modifying_or_deleting_instances

Firebase + Tag Manager: Fetch variable from previously sent event

With the previous version of Tag Manager (dataLayer), it was easy to fetch variables sent within previous events, when those variables weren't sent with the current.
How to persist parameters with the Firebase version of GTM?
For example, previously, I could send an event with a user_id variable at the start of the session or as soon as the user logs in. I would then create a "Data Layer Variable" in GTM and use it to get this user_id at any subsequent point in the session. For instance, to send it as a GA custom dimension on a purchase event possibly made later.
Now, if I push a Firebase event with a custom parameter user_id and then create an "Event Parameter" variable in GTM, it will only be available within this event.
Same if I send a user property with Firebase and register a "Firebase User Property" variable in GTM. I won't be able to use this variable within an event at a later point in the session
Is there a way to persist user properties and event parameters?
Unfortunately, we all miss the data layer like approach.
I got a confirmation that the only way to "persist" data between events using Firebase SDK is to use user properties, which function like "sticky" events within Firebase. Otherwise, the parameter would need to be sent anew with a future event.
Combined with a limitation of only sending string and numbers but not dictionaries makes this a bit less convenient.

Find an event in a calendar

I'm writing an app that reads a Google Sheet that I have read access to. This is working just fine. It contains upcoming dates for things. The sheet contains usually no more than 20 - 30 upcoming events. Events that have passed are ignored.
I need to take these upcoming events and add them to a calendar. Adding events is ok. The problem is that if the app runs again say a week later, the events that are already on the sheet are added again, so I need a way of searching for an event in a calendar based on the date of the event. If I find an event at that date and time, then I can ignore it and move to the next one. It seems that searching for an event requires a calendar ID and an event ID. Is there a way to search for an event by giving a date and time, and say a partial summary?
Failing that, any other options? The data in the Google Sheet I have read access to only. My app doesn't store anything locally. The intention is to read the sheet and add events but not add duplicate events.
To get events you either use events.get where you provide the calendarId and eventId to fetch a specific event or Events.list to get all events.

Google Analytics: How to associate an event with an individual session

I have a variable that's being laoded on my page and then being reported back to GA via the event tracking api. Is there a way for this "event" to be associated with the flow of an individual session?
For example: If I have a variable that gets reported as "eligible", can I then associate this event with the session and page flows?
Yes, you can create an advanced segment. That is a way to filter sessions (visits) according to certain criteria. In this case, your criterion would be "Include: Event Label = 'the name of the label of your event'".
Note that it is against the terms of use of GA though to report data on an indidivual basis, i.e. it is not allowed to create an event label that allows you to identify each single session.

Google Calendar API: Editing a single occurrence of a recurring event

Using the Google Calendar API, how can I edit a single occurrence of a recurring event? (the web interface allows me to do that)
Reading through some of the google forums on this I came across an answer from a google employee:
What you can also do is to retrieve
the events by adding the query
parameter 'singleevents=true' to the
feed URL. This will expand the
recurring events into multiple events.
http://code.google.com/apis/calendar/data/2.0/reference.html#Parameters
You will just have to modify the
desired events and it will create the
exception.
About the "Forbidden g:originalEvent
[2010-02-08 06:00:00] does NOT
correspond to an instance of the
recurring event": this mean that the
When object set in the OriginalEvent
doesn't match the time of the
occurrence of the recurring event.

Resources