Google Analytics - Track multiple subdirectories - google-analytics

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');

Related

Display only Team Drives in Drive Picker Widget

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

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.

Tracking a conversion funnel that changes subdomains

I am trying to set up Google Analytics (Universal/analytics.js) to track a user account set-up funnel on a single website with many subdomains. On each subdomain, a user can express interest in creating an account, and then create the account. Once the account is created, they leave the subdomain and arrive on the main domain.
For the subdomain foo, the flow is like this:
foo.maindomain.com - register interest
foo.maindomain.com/inv/acc0unTt0k3n - enter account set-up details
maindomain.com/extra_information - info is supplied
maindomain.com/home - goal end point reached
I have set up a View for each subdomain e.g 'Viewing foo.maindomain.com', and each View has a Filter that accurately shows visits to foo.maindomain.com & foo.maindomain.com/inv/acc0unTt0k3n.
I don't know how to go about tracking traffic through this whole funnel. My ideal end-goal would be to track this funnel for all subdomains combined, but I would be satisfied for now with getting a Goal or Funnel that worked for each subdomain individually.
Inside my 'Viewing foo.maindomain.com' View, I have attempted to create a Goal to track this. I can capture the first two steps by creating:
Goal Type > Destination
Destination: /inv/
Funnel: /
This gives a 20% conversion rate, which matches up with my server data for account creations. But if I try to change the Destination to maindomain.com/boarding, and add /inv/ as another step in the Funnel, it no longer works ("Verify this Goal" returns 0).
How can I create a Goal that captures all of these steps?
Make sure you are using the same UA code on every subdomain.
You should then just be able to see all the subdomains in the standard view out of the box - UA tracks across subdomains automatically. See the Google documentation for details
You don't need to set up a view for each subdomain if you don't need it.
Name your master View "Rollup" if you like.
You can see all subdomains in your "Hostname" report for that view.
You may want to overwrite your pageview names so they also incude the subdomain, so you can tell them apart (if say subdomain1.domain.com/index.html and subdomain2.domain.com/index.html exist, in the standard pagetracking they will be aggregated) - this can be done via filters:
Filter Type: Custom filter > Advanced
Field A: Hostname Extract A: (.*)
Field B: Request URI Extract: (.*)
Output To: Request URI Constructor: $A1$B1

Measuring goals for users who have never logged into my site before

I have a web app. The home page has two main actions:
Sign up to the application
Log into the application
I have a goal set up for sign-ups. I am trying to track the goal conversion rate of users who have never logged into the application before.
The problem I have at the moment is that the conversion rate is being skewed by users who are visiting the homepage simply to log in.
Is there a simple way of doing this?
Thanks very much,
Ben
For the kind of tracking you are looking for, there should be some coding on both your system and Google Analytics.
First, I would recommend you place into your system the intelligence to know the number of log-ins the user has made (As an example, a counter on your database).
Now, to implement that, you will need to set a Custom Var in Google Analytics in a visit level, to segment the users from the non-users, in that CustomVar, you can store both the user ID and the number of logins he has made.
This is the on the login page:
Your Code Should Look Like:
_gaq.push(['_setCustomVar',
1,
'Member Login',
'NUMBER OF LOGINS', // SET THIS FROM YOUR SYSTEM
2 //VISIT LEVEL Custom Var
]);
Remember that this code should go before tracking the pageview.
After setting this up, you should use Advanced Segments to check those specific users, one case could be: (Using the example above)
Setup an Advanced Segment that "Excludes" the Custom Variable (Key 1) - Mathing RegExp : .*
This will give you all the never-loged user access.
Something else you could do is set up Adv Segments to check on a specific number of logins
Setup an Advanced Segment that "Excludes" the Custom Variable (Key 1) - Mathing RegExp : [^1]
This will give you all the users that loged-in more than once.
You can find more info on Custom Vars here.

Resources