I am very new to this google analytics thing.
I have 3 things.
A RESTapi written using node.js express framework.
A mobile app written using react native
A admin panel UI written using vue.js
Mobile app is a food app. It has so many restaurants.
I want to pass a restaurant_id and need to get the dish views for that specific restaurant only.
for that I have to make a API call from my admin panel UI.
According to official docs I have to make my api call like this.
function makeApiCall() {
var apiQuery = gapi.client.analytics.data.ga.get({
'ids': TABLE_ID,
'start-date': '2010-01-01',
'end-date': '2010-01-15',
'metrics': 'ga:sessions',
'dimensions': 'ga:source,ga:keyword',
'sort': '-ga:sessions,ga:source',
'filters': 'ga:medium==organic',
'max-results': 25
});
// ...
}
To pass a such TABLE_ID, how do I create a table in my analytics?
As well as start-date and end-date are parameters I guess.
How do I create such params along with that TABLE?
If you look at the sentence in the documentation that precedes the code example you will see that TABLE_ID refers to the view id:
The easiest way to get the view id is to navigate in the admin section to the "view settings" (first item in the rightmost column). You will find the view id in the "Basic settings" section.
Related
A Brief Overview of the Problem
I am trying to store JSON data on my SendGrid contacts for usage in dynamic email templates designed in the SendGrid GUI.
To start, within the SendGrid email builder I can write the following code within a codeblock:
Here is the handlebar code in that code block...
<ol>
{{#each user.accounts}}
{{#if this.isPending}}
<li>
{{this.name}} is <strong>pending activation.</strong>
</li>
{{else}}
<li>
{{this.name}} is <strong>active.</strong>
</li>
{{/if}}
{{/each}}
</ol>
When I go to preview that code & add some test data I get the following:
Here is the JSON code in that code block formatted a bit nicer...
{
"user": {
"accounts": [
{
"name": "Checking",
"isPending": false
},
{
"name": "401k",
"isPending": true
},
{
"name": "Savings",
"isPending": true
}
]
}
}
The Question
Everything mentioned above is PERFECT so far - this is exactly what I want... To populate email data based on dynamic content present on each contact the email is going to. Here is where I hit the roadblock, where is that JSON Test Data coming from on the contact when the real email is sent out? And how do I populate a contact with JSON data using the API?
As far as I can tell, there is no option to add this custom JSON data to a new contact when creating one via the API (or via the GUI, for that matter) (see API docs here)
When I set up this email to send out to my SendGrid contacts via a SendGrid automation flow, does anyone know how to populate the JSON used by my code block for showing pending/activated accounts with data specific to each user?
Thank you, I greatly appreciate any help on this!
I think that JSON data is actually only useful when you are using the API to send an email with a template. You then provide the JSON data as dynamic_template_data and it is populated in the email template.
When dealing with Automations, you need to pull the data from the contact record itself. You can get the data you have on a Contact in the Tags section of the template designer.
There are a number of fields that already exist on contacts, like first_name, last_name, email, address_line_1, etc. You can also add Custom Fields which give you further fields you can use on your contacts. Custom Fields can be created by adding new columns on an CSV upload of your contacts, by creating them in the SendGrid admin or by creating them via API.
If you are using the API to create or update your contacts, you can pass an object of custom_fields as part of the contact record in the API request. For example:
const data = {
"contacts": [
{
"email": "ryan39#lee-young.com",
"custom_fields": {
"w1": "2002-10-02T15:00:00Z",
"w33": 9.5,
"e2": "Coffee is a beverage that puts one to sleep when not drank."
}
}
]
};
Note that to set custom fields on a contact when you create/update by the API like this, you need to use the custom field ID as the key in the custom_fields object (like the example above, the IDs "w1", "w33" , "e2" were used). If you need to know those IDs, you can use the API to get all field definitions.
Once you have added Custom Fields they will also be available as Tags in the design editor, then you can use them in the email design.
The only thing is, I notice you are using an array of accounts in your example. If you need an array of arbitrary data, then I don't believe you can achieve that with contact data and automations. You can set individual custom fields for, say, a checking account, 401k and savings. But you cannot have arbitrary data in a custom field. If you really need the data to be arbitrary, then Automations might not be right for you and you should send your emails out using the send mail API and providing dynamic template data.
When students in google classroom submit my google forms, they are automatically graded and students can see their results. Despite that when I want to import these quiz results into my google classroom, I need to do it manually with import grades button. Is there a way to automate this process? That means that when student submits the form, the results will be immediately visible in his google classroom.
Please do not tell me to change LMS, google classroom is a requirement for me.
There's no need to use Forms outside Classroom, you can integrate it
As a teacher go to your Class > Classwork and click on Create > Quiz assignment, fill the needed data like Title, Instructions, Students, Points, etc. Then click on the Form and edit it as required.
When you are done editing, save it and close the Form, then on the Classroom side click on Assign. Once you assigned the quiz to the students, this automatically will be reflected on the student classwork and this student can access your quiz trough the Classroom Platform.
If you want to export this data to another service then use Google Apps Script in order to automate your process
You can skip this if it's not necessary
As an approach to export this data using Apps Script, open the Form and open the Script Editor then copy this code:
function myFunction() {
var form = FormApp.getActiveForm();
form.setCollectEmail(true);
var responses = form.getResponses();
responses.forEach(response => {
let email = response.getRespondentEmail();
let score = 0;
response.getGradableItemResponses().forEach(item => {
score += Number.parseFloat(item.getScore());
});
// Handle your submit and export this data to an extra service
});
}
Then you can handle the submit event by creating a onSubmit trigger in your Apps Script project.
Reference
Class FormApp
FormApp.getActiveForm()
Class Form
Form.setCollectEmail(collect)
Form.getResponses()
Class FormResponse
FormResponse.getRespondentEmail()
FormResponse.getGradableItemResponses()
Class ItemResponse
ItemResponse.getScore()
What you want cannot be achieved for now.
The reason for this is essentially because before importing the grades, the teacher can modify/change the already existing grades if needed before sending them to the students.
What you can do in this situation is to file a Feature Request on Google Issue Tracker here and provide all the necessary details.
Trying to extract a userID from GoogleAnalytics. This is to view which user is the using the website most and least.
I would to retrieve the top 5 user IDs and bottom 5 user IDs that were passed using either:
gtag('config', 'GA_TRACKING_ID', {
'user_id': 'USER_ID'
});
OR
using a custom dimension... ( https://support.google.com/analytics/answer/2709828?hl=en )
I'm (vaguely) aware of policies and TOS to keep 'non identifying' information on Google BUT there are posts online indicating you can link back to CMS data.
Steps so far
Google Analytics with UserID and view setup - Working in Google dashboard and showing filtered userID and All website data using the idea.
Requirements:
Extract page view and session data for each userId between a date
range (or all by default)
UserID via standard GA method
UserID via Custom dimension method
Any help, pointers or examples how someone has completed something like this are appreciated.
NOTE: This is to PULL data out of GA and manipulate/display it on an external system/dashboard.
Seen this which states it's not possible: Google analytics userID tracking
and this which states it (kind of) is google analytics API implementation for tracking a specific user activities in php
The solution I used:
Tracking
Create Google Analytics account
Create a new view by activating the UserID tracking (labeled NewView1)
Use https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets
i.e. Define your custom dimension
Get Analytics tracking code + Add custom definition code
Create a Custom report using the 'metrics' you want to see and filtering by the 'custom dimension' I created earlier.
(note: data took ~ 12 hours to be visible so don't expect to work instantly)
Front end tracking additions
gtag('config', 'GA_TRACKING_ID', {
'custom_map': {'dimension<Index>': 'dimension_name'}
});
// Sends the custom dimension to Google Analytics.
gtag('event', 'any_event_name', {'dimension_name': dimension_value});
Extraction
Create New Google Developer Console Project (API)
Use a Service Account to connect the API with Analytics ( https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php ) -- API -> credentials -> Create Credentials (Service Account key)
(assign role [mine was set to Project => View])
Save the Text file to your filesystem and rename to json as per examples
Add permissions to your Analytics project by copy/pasting the 'Email' from the Service account details into Analytics User Management.
Get the view ID of the data you wish to extract (Analtyics created in step 2 in tracking)
Use the sample Code (HelloAnalytics.php) to connect and extract data
Use your custom dimension to filter results
The dimension filter I used was $dimensions (see below)
...
$dimensions = new \Google_Service_AnalyticsReporting_Dimension();
$dimensions->setName('ga:dimension1'); // as per docs
// Create the ReportRequest object.
$request = new \Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setMetrics(array($sessions, $pageviews));
$request->setDimensions($dimensions);
From there I was able to see the same data via API that I could see in the custom report on analytics web.
NOTE: be careful of which Google project and view you're in while setting up
permissions and dimensions.
NOTE: using gtag() code and not Universal (ga()) js code
The answer is a very brief/rough summary of how I achieved my specific goal. It is not a one-size-fits all solution but hopefully it will give someone a better idea of how to set and extract custom variable data within Google.
The final result was data from the API. From there it's up to you.
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.
THe below is a screenshot of a view on the Google analytics website (Geo > Location > Primary Dimension = city)
I would like to embed this exact view or replicate it as similarly as possible using google's Embed API and display it on my own site.
I have followed the tutorial here > https://developers.google.com/analytics/devguides/reporting/embed/v1/devguide and got the simple line graph working on my site but I cant seem to find any information showing how to add the map functionallity, the pie chart, or the table like we see in the below.
Are there any good examples or tutorials that could help me with this?
I tried the documentation but I just dont see a lot of explanation regarding what you can create with the API.
How about something like this?
http://jsbin.com/relufutenuto/2/edit
You can set chart options based on the options allowed by the various Google chart libraries. Here's the Google chart documentation for the chart type GEO:
https://developers.google.com/chart/interactive/docs/gallery/geochart#Configuration_Options
Note: you might have to disable pop-up blockers to get auth to work in jsbin, but this should give you the idea.
Here's the part of the code that sets the chart type of options:
var timeline = new gapi.analytics.googleCharts.DataChart({
query: {
'ids': 'ga:1234',
'dimensions': 'ga:country',
'metrics': 'ga:sessions',
'start-date': '30daysAgo',
'end-date': 'yesterday',
},
chart: {
type: 'GEO',
container: 'timeline',
options: {
region: '155', // Western Europe
displayMode: 'markers'
}
}
});