Reputation: 7145
I want to start somewhere. This is my use case.
node.js
express framework.
react native
.Vue.js
Mobile app is food app. Where you can search restaurants or dishes of a restaurant.
I want to pass the restaurant id and get the restaurant views of the app with in the last 7 days. Pretty straight forward requirement. But hard to implement. Since I don't know where to start from.
I went through the docs and have found there are 7 APIs.
End of the day, I would love to do something similar to this with the API.
showMeTheView(restaurant_id)
Also If I want to pass additional parameter to say get only last month views count.
showMeTheViews(restaurant_id, last_month)
I can't figure out what are the essential steps to achieve my requirement?
What need to be done in the react-native app? What need to be done in the vue.js web app? What need to be done in between these two?
Upvotes: 2
Views: 1532
Reputation: 116868
First off you should be using the Core reporting api this is the api that can be used to extract data from Google analytics. The Json object used to extract data form Google analytics is quite extensive batch get
It will make your life a lot easier if you use the Google apis node.js client libray code ripped from sample found here
'use strict';
const {google} = require('googleapis');
const sampleClient = require('../sampleclient');
const analyticsreporting = google.analyticsreporting({
version: 'v4',
auth: sampleClient.oAuth2Client,
});
async function runSample() {
const res = await analyticsreporting.reports.batchGet({
requestBody: {
reportRequests: [
{
viewId: '65704806',
dateRanges: [
{
startDate: '2018-03-17',
endDate: '2018-03-24',
},
{
startDate: '14daysAgo',
endDate: '7daysAgo',
},
],
metrics: [
{
expression: 'ga:users',
},
],
},
],
},
});
console.log(res.data);
return res.data;
}
// if invoked directly (not tests), authenticate and run the samples
if (module === require.main) {
const scopes = ['https://www.googleapis.com/auth/analytics'];
sampleClient
.authenticate(scopes)
.then(runSample)
.catch(console.error);
}
// export functions for testing purposes
module.exports = {
runSample,
client: sampleClient.oAuth2Client,
};
Upvotes: 3