Display only Team Drives in Drive Picker Widget - google-app-maker

I am creating an application where I need to provide Drive Picker widget so that users can upload some files. Now I want to restrict users so that they can only select files from their "Team Drives" and not from anywhere else.
I've tried adding method in onPickerInit event.
Here's my function which is getting called in onPickerInit event,
function fetchFolder(widget, pickerBuilder) {
pickerBuilder.addView(new google.picker.DocsView()
.setParent('TeamDriveId')
.setIncludeFolders(true));
}
This method restricts users to select only from particular Team Drive, however my question is how can I give dynamic option so that users can select from any of their Team Drives and not limited to one Team Drive. Also they should not be able to select from their own Google Drives.

It seems that this case requires low level Drive Picker tuning, so lets start from removing all settings that App Maker gives us out of the box:
Remove all features
Remove all views
Then add the following script to the onPickerInit event
// Enable Team Drives
pickerBuilder.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES);
// Let users to select files from any Team Drive
var multiTeamDrive = new google.picker.DocsView();
multiTeamDrive.setIncludeFolders(true)
.setEnableTeamDrives(true);
pickerBuilder.addView(multiTeamDrive);
// This feature need to be set to force `setParent` work.
// Seems to be Drive Picker's bug
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);
// Force users to upload files to a specific Team Drive
var uploadView = new google.picker.DocsUploadView();
uploadView.setParent('Fancy KEY from Team Drive folder URL')
.setLabel('Upload to Team Drive XXX');
pickerBuilder.addView(uploadView);
Result
Notes
I didn't find a way to hide the tab for the Personal Drive upload. It is strange that App Maker adds it by default and there is no option to remove it.
I also recommend to add server side validation for the files selected by users to ensure that they originate from Team Drive.
Similar/related answer: https://stackoverflow.com/a/49677679/454137

Related

Accessing User ID as a variable in Google Tag Manager for mobile

I'm getting started with Google Tag Manager for Android/iOS, and can't find a way to access the User ID as a variable. I can access Firebase User Properties and Event Parameters just fine.
So far, I've tried setting it using FirebaseAnalytics.setUserId and trying to access it as a User Property called user_id / userId.
Some workarounds I've thought of:
Using a CustomVariableProvider (preferred)
Setting the User ID as an Event Parameter (this wouldn't work with built-in events)
I'm just trying to make sure there's no built-in way of doing this before I resort to workarounds. Thanks!
I was not able to find the User ID (or UID) in the list of built-in variables, see this screenshot
There is a built-in way, but it requires quite a sophisticated setup.
In GA version 4 the path is changed comparing to the previous version, where the same could be done much easier via "Tracking Info".
Here are the starting steps in GA4:
Open https://analytics.google.com/analytics/web
Bottom-left corner -> Admin -> Setup Assistant -> Advanced setup -> User ID
Follow the instruction
After that UserID will be available in GTM.
Video guide for exact steps: https://www.youtube.com/watch?v=TVJMFVOXFUQ

How to find which TVs are currently using my app?

I am developing an app for Android TV is it possible to know, on which TV my app is running or what action is performed on it?
Thank you.
To review your app's supported devices:
Sign in to your Play Console.
Select an app.
On the left menu, click
Release management > Device catalog. If you haven't already, review
and accept the Terms of Service.
Select the All, Supported, or
Excluded tabs. If you want to download a list of devices as a CSV
file, near the right side of the page, click Download device list.
For more infos:
https://support.google.com/googleplay/android-developer/answer/7353455
To track action performed on your app, you can use Fabric's Answers plug in.
Here is a sample code you'll need to add in your code to track events in Answers:
public void onKeyMetric() {
// TODO: Use your own string attributes to track common values over time
// TODO: Use your own number attributes to track median value over time
Answers.getInstance().logCustom(new CustomEvent("Video Played")
.putCustomAttribute("Category", "Comedy")
.putCustomAttribute("Length", 350));
}
For more infos:
https://fabric.io/kits/android/answers

Google App maker multiple files drive upload

We are going to use drive picker as attachement field, so whenever an user uploads a file or multiples files to drive we have to get the links of the files and show it to the user in the form.
Here is a code sample with following assumptions:
you have Master and Attachment models with One-to-Many relation
datasource of the current page is set to record from the Master model
datasource is in Auto Save mode
// onDocumentSelect Drive Picker's event handler
var create = widget.root.datasource.relations.Attachments.modes.create;
result.docs.forEach(function(doc) {
create.item.Url = doc.url;
create.createItem();
});
This code will make N requests to the server, where N is number of attachments. You can use google.script.run to make a single call and handle creating new attachment records and relations on server, but then you'll need manually reload relation to show changes to user.

Google analytics user explorer get user report

How do I get user report from user explorer, using GA API. Didn't manage to find any information about it here https://developers.google.com/analytics/. For instance in user explorer (audiences section) you can see a list of records having ids like 11111111111.2222222222 and I want to get information about user activity on the website for record with id 11111111111.2222222222 using GA API
While the latest GA release notes says the client ids have been "surfaced" (i.e. made visible) it is (at least currently) not available as a dimension via the API. So if you want to use it you'd have to add the client id as a custom dimension to your reports yourself. Off the top of my hat this should look something like this:
ga(function() {
var trackers = ga.getAll();
trackers.forEach(function(tracker) {
tracker.set('dimension1',tracker.get('clientId'));
});
});
Put before the pageview this would write the client id to your custom dimension with the index 1 (which you need to create in advance via the interface in properties->custom definitions). Should also work with multiple trackers on the same page.
This will of course not help you with data that's already been collected.

Google Analytics - Track multiple subdirectories

I have a website where users can create subdirectories and files, and I need to be able to track each subdirectory separately as it's created.
For example: if my site is www.domain.com
User 1 creates www.domain.com/user1/index.html
User 2 creates www.domain.com/user2/index.html
I need to be able to automatically track subdirectories user1 and user2. I can't manually go into GA admin panel and add a segment/filter each time a new subdirectory is created to track it. I also need to be able to display this data back to the users.
Is this possible with Google Analytics?
Managed to do this very easily.
1) Programatically added the google analytics code to each new page the user creates. This automatically tracks traffic to individual subdirectories.
2) Used oocharts.js to display the data individually, by passing in a filter like so.
var timeline1 = new oo.Timeline("12345678", "30d");
timeline1.addMetric("ga:visits", "Visits");
timeline1.query.setFilter('ga:pagePath=~/user1/');
timeline1.draw('chart1');
var timeline2 = new oo.Timeline("12345678", "30d");
timeline2.addMetric("ga:visits", "Visits");
timeline2.query.setFilter('ga:pagePath=~/user2/');
timeline2.draw('chart2');

Resources