Getting Google Calendar event by id with Python and gdata library - google-calendar-api

How could I get an event from a specific Google Calendar using gdata library and knowing the event id? I can't see an example like that in the documentation.
I know I can (and should) use v3 API and python-api-client, but I want to add and modify events in all the users's calendars from a Google Apps domain, without user's intervention. Is there a better way to do this?
Thanks in advance, and best regards

Self-response:
from gdata.calendar.client import *
from gdata.calendar import *
gdclient = gdata.calendar.client.CalendarClient(source = 'testing')
gdclient.ClientLogin(ADMIN_USER_LOGIN, ADMIN_USER_PASSWORD, gdclient.source)
feed_uri = gdclient.get_calendar_event_feed_uri(calendar = THE_USER_EMAIL)
event_uri = feed_uri + '/' + THE_EVENT_ID
calendar_entry = gdclient.get_calendar_entry(event_uri, desired_class=gdata.calendar.data.CalendarEventEntry))
One thing I've realized is there's no way to change the event's color (or, at least, I've not found it). This is possible with Google Calendar API v3.

Related

missing custom event in GA4 through Google Analytics Data API v4

We have a website with GA4 and want to set up data collection using Google Analytics Data API v4. We can see all custom events we defined show up Google Analytics UI under Engagement/Events. But when we call https://analyticsdata.googleapis.com/v1beta/ some of them are missing.
To be specific we are running the following to get list of all dimensions and metrics:
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import GetMetadataRequest
property_id = "PROPERTY_ID"
client = BetaAnalyticsDataClient()
request = GetMetadataRequest(name=f"properties/{property_id}/metadata")
print(client.get_metadata(request=request))
Does anyone know why some events are not showing up with the above code?
Thank you!
EDIT:
I found that only events marked as conversion (Configure/Events) show up in the metadata. But why?
EDIT2:
According to https://developers.google.com/analytics/devguides/reporting/data/v1/advanced#event-scoped_custom_dimensions https://analyticsdata.googleapis.com/v1beta/properties/GA4_PROPERTY_ID/metadata only returns metrics and dimensions. So I guess I need to use something else to retrieve all events?

Setting up Adobe Analytics eCommerce tracking in GTM

I am currently in the process of setting up Adobe Analytics on a website that is currently using GTM & GA (universal analytics). Ideally I want to leverage the existing data layer to pass values to the Adobe evars/props but the one question I have was how to handle the products field? Adobe requires the products field to be in a very specific format (category;product;qty;total).
Can I build this product string in GTM? Or do I need the developers to hard code this string? I might be overthinking this but I have never installed Adobe thru GTM before
You can use a custom javascript variable (GTM "variables" used to be called "macros" which was a lot less confusing) of the type "custom javascript function" to loop through the products array and assemble the product string.
That is you'd first create a dataLayer variable that returns the product array from the dataLayer and then do a loop; a custom javascript variable in GTM is an anonymous function that returns a value. This would look a bit like that (from top of my head, not exact code; the thing in curly brackets is the datalayer products variable you need to create first):
function() {
var products = {{products}};
var productAdobe = [];
for(i=0;i<products.length;i++) {
prod = products[i];
productAdobe.push(prod[i].category + ";" + prod[i].id + ";" + prod[i].quantity + ";" + prod[i].quantity*prod[i].price);
}
return productAdobe.join("\n");
}
Like I said this is not exactly working code, but should be enough to give you an idea.
Having said that having your developers pass on a proper product string is a much better idea. Using GTM for programming tasks is error prone and makes maintenance hard (and tag management should make your life easier, not harder). And if you already have Adobe Analytics you should have free Access to Adobe DTM which might a better choice to deploy Adobe Analytics (for one thing you cannot host s_code within GTM, as the custom HTML tag has a length limit that is exceeded by the Adobe Tracking code).

How to create tracking pixel with Google Analytics for 3rd party site?

We need to track conversions that happen on a 3rd party site. The only thing we can place on that site is an image pixel and maybe some JS logic for when to fire it.
I know it is possible to fire a conversion using the Measurement Protocol: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#visitor
Ideally, I'd just give the 3rd party an IMG url and that would be it. The problem is the CID (unique client id).
I can try passing the CID from our site to the 3rd party via URL parameter. However, there are many cases where its not available (e.g., IMG pixcel will be in an email, the goal URL is on printed literature) or the 3rd party is not willing to go through the hassle. Is it best practice to pass this CID in this way?
I can try generating a CID, but I can't find a dead simple way of doing that e.g., var CID = generateCID(). The 3rd party site has its own GA on the page. Can I just take their Google Analytics CID and use it in the image pixel URL?
What the best way to do this? Thank you!
If the 3rd-party site has analytics.js already running then using that client ID is probably best. You can get it by doing the following:
var cid;
ga(function(tracker) {
cid = tracker.get('clientId'));
});
If analytics.js is not running, or if you can't access the ga variable for some reason, you can just generate the client ID randomly. This is approximately what Google does. It's a random 31-bit integer with the current date string appended:
var cid = Math.floor(Math.random() * 0x7FFFFFFF) + "." +
Math.floor(Date.now() / 1000);
Only to complement #Philip Walton excellent answer, Google Analytics expects a random UUID (version 4) as the Client ID, according to the official Documentation.
Client ID
Required for all hit types.
This anonymously identifies a particular user, device, or browser
instance. For the web, this is generally stored as a first-party
cookie with a two-year expiration. For mobile apps, this is randomly
generated for each particular instance of an application install. The
value of this field should be a random UUID (version 4) as described
in http://www.ietf.org/rfc/rfc4122.txt
#broofa provided a simple way to generate a RFC4122-compliant UUID in JavaScript here. Quoting it here for the sake of completeness:
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});

How to Track Store Locator Search terms in Google Universal Analytics

I am in the process of setting up enhanced Ecommerce for GA and have had a few requests of additional of what else the client would like to see in their reports. Once of which is
"Where can i see a report if the locations that a use types in when they use the store locator"
There is already an internal search functionality thats been set up and is tracking the search terms people are typing when looking for products, but i'm not sure if i would need to set this up as a second search terms report or if it's something different?
The URL of the page is different to the internal search results and is www.domain.com/store-locator#wales|GB|0|0|0
Any insight into this would be really helpful.
Thanks,
Roxi
As to me knowledge, you are not able to use bookmarks (#something) in GA for internal site search setup. Only GET and POST parameters are allowed. In your situation I think the best solution is to use GA events to send the data about used location each time the user is using this functionality. You need to include addition ga() function call to track those events. Info about how to set it up you could find here: event tracking. After setting things up, you will see all the info about number and type of called events in Behavior -> Events reports section in GA.
Example code:
<button onlick="var hash_location=window.location.hash;ga('send','event','Locator',has_location)">Click me</button>
With such function new event will be send to GA with Event Category=Locator and Event Action=hash in the url. You have some complicated hash, so most probably you need to extract first some info from this using regular expression. Example to get first item from |-separated list in the hash:
var pattern = new RegExp('[^#|]+');
var hash_location = pattern.exec(window.location.hash)[0];

Integrate optimizely into google analytics

I have been trying to integrate optimizely into google analytics and it has proved a bit difficult than I anticipated. I am doing it through gtm which makes it slightly complicated. I have created a macro
function() {
dimension = optimizely.allExperiments[experimentId].universal_analytics.slot;
experimentIds = optimizely.activeExperiments;
variationName = optimizely.variationNamesMap;
experimentDetails = variationName + "|" + experimentIds;
return experimentDetails;
}
and joined it to a custom dimension in universal analytics tag which means this will be fired on every page but the dimension always comes back as:
'Running command: ga("set", "dimension14", undefined)'
I will really some help on this as I am struggling and the optimizely team dont know what to do either.
Thanks.
While Optimizely is best installed directly onto your page, it is possible to install Optimizely using Google Tag Manager (GTM), which is discussed here, with a complete walk through. This will ensure Optimizely fires before GA (or any other tag):
https://help.optimizely.com/hc/en-us/articles/200040095-Implementing-the-Optimizely-Snippet#tag_manager
The next part is troublesome - how can you integrate Optimizely with Google Analytics? To do so, you must insert a line of code before the GA tracking call is made ( ga('send','pageview') ). To do this, you must modify the JS in the GA call to look like the code below.
Please note, unless GTM allows you to modify their GA add on, you will need to add a custom integration in GTM for GA to place the modified code.
// Optimizely Universal Analytics Integration code
window.optimizely = window.optimizely || [];
window.optimizely.push(['activateUniversalAnalytics']);
ga('send', 'pageview');
The 'activateUniversalAnalytics' call is similar to the macro you've written above, where all it does is pass your experiment ID# (or name) and the variation # (or name) to the custom Dimension you've assigned to GA in Optimizely. One benefit of using Optimizely's integration is you can change the Dimension number per experiment inside Optimizely without making any changes to your page's source code.
If you need further assistance with this, please contact support#optimizely.com (full disclosure, I am an Optimizely employee).

Resources