Google analytics steps to get number of views per page from an API
I AM TOTALLY NEW TO GOOGLE ANALYTICS.
I want to start somewhere.
This is my use case.
- I have a restAPI written in
node.js
express framework.
- I have a mobile application written in the
react native
. - Also I have a web application for the administration purpose of the mobile app, written in
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.
- Core reporting API
- Management API
- Embed API
- User deletion API
- Multi channel reporting API
- Real time API
- Meta data API
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?
any help!
Thanks in advanced!
node.js google-analytics google-api google-analytics-api
add a comment |
I AM TOTALLY NEW TO GOOGLE ANALYTICS.
I want to start somewhere.
This is my use case.
- I have a restAPI written in
node.js
express framework.
- I have a mobile application written in the
react native
. - Also I have a web application for the administration purpose of the mobile app, written in
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.
- Core reporting API
- Management API
- Embed API
- User deletion API
- Multi channel reporting API
- Real time API
- Meta data API
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?
any help!
Thanks in advanced!
node.js google-analytics google-api google-analytics-api
add a comment |
I AM TOTALLY NEW TO GOOGLE ANALYTICS.
I want to start somewhere.
This is my use case.
- I have a restAPI written in
node.js
express framework.
- I have a mobile application written in the
react native
. - Also I have a web application for the administration purpose of the mobile app, written in
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.
- Core reporting API
- Management API
- Embed API
- User deletion API
- Multi channel reporting API
- Real time API
- Meta data API
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?
any help!
Thanks in advanced!
node.js google-analytics google-api google-analytics-api
I AM TOTALLY NEW TO GOOGLE ANALYTICS.
I want to start somewhere.
This is my use case.
- I have a restAPI written in
node.js
express framework.
- I have a mobile application written in the
react native
. - Also I have a web application for the administration purpose of the mobile app, written in
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.
- Core reporting API
- Management API
- Embed API
- User deletion API
- Multi channel reporting API
- Real time API
- Meta data API
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?
any help!
Thanks in advanced!
node.js google-analytics google-api google-analytics-api
node.js google-analytics google-api google-analytics-api
edited Nov 21 '18 at 10:23
DaImTo
46.4k1165246
46.4k1165246
asked Nov 21 '18 at 9:58
Pathum SamararathnaPathum Samararathna
939930
939930
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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,
};
I got this point that I need to use core reporting api. and do I need to use node.js client library? I want to fetch data from GA and display on my vue.js front-end. I do not need to store them anywhere. So for that reason do I need that client lib? What is this view id?
– Pathum Samararathna
Nov 21 '18 at 10:49
Remember this is only going to fetch data for you will have to figure out how you want to format it yourself. Yes storing it is a good idea as there is no reason to make the same request twice old data wont change. View id is the id of the Google analytics view you wish to request the data from.
– DaImTo
Nov 21 '18 at 10:55
Thanks a lot. =)
– Pathum Samararathna
Nov 21 '18 at 11:28
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409462%2fgoogle-analytics-steps-to-get-number-of-views-per-page-from-an-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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,
};
I got this point that I need to use core reporting api. and do I need to use node.js client library? I want to fetch data from GA and display on my vue.js front-end. I do not need to store them anywhere. So for that reason do I need that client lib? What is this view id?
– Pathum Samararathna
Nov 21 '18 at 10:49
Remember this is only going to fetch data for you will have to figure out how you want to format it yourself. Yes storing it is a good idea as there is no reason to make the same request twice old data wont change. View id is the id of the Google analytics view you wish to request the data from.
– DaImTo
Nov 21 '18 at 10:55
Thanks a lot. =)
– Pathum Samararathna
Nov 21 '18 at 11:28
add a comment |
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,
};
I got this point that I need to use core reporting api. and do I need to use node.js client library? I want to fetch data from GA and display on my vue.js front-end. I do not need to store them anywhere. So for that reason do I need that client lib? What is this view id?
– Pathum Samararathna
Nov 21 '18 at 10:49
Remember this is only going to fetch data for you will have to figure out how you want to format it yourself. Yes storing it is a good idea as there is no reason to make the same request twice old data wont change. View id is the id of the Google analytics view you wish to request the data from.
– DaImTo
Nov 21 '18 at 10:55
Thanks a lot. =)
– Pathum Samararathna
Nov 21 '18 at 11:28
add a comment |
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,
};
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,
};
answered Nov 21 '18 at 10:23
DaImToDaImTo
46.4k1165246
46.4k1165246
I got this point that I need to use core reporting api. and do I need to use node.js client library? I want to fetch data from GA and display on my vue.js front-end. I do not need to store them anywhere. So for that reason do I need that client lib? What is this view id?
– Pathum Samararathna
Nov 21 '18 at 10:49
Remember this is only going to fetch data for you will have to figure out how you want to format it yourself. Yes storing it is a good idea as there is no reason to make the same request twice old data wont change. View id is the id of the Google analytics view you wish to request the data from.
– DaImTo
Nov 21 '18 at 10:55
Thanks a lot. =)
– Pathum Samararathna
Nov 21 '18 at 11:28
add a comment |
I got this point that I need to use core reporting api. and do I need to use node.js client library? I want to fetch data from GA and display on my vue.js front-end. I do not need to store them anywhere. So for that reason do I need that client lib? What is this view id?
– Pathum Samararathna
Nov 21 '18 at 10:49
Remember this is only going to fetch data for you will have to figure out how you want to format it yourself. Yes storing it is a good idea as there is no reason to make the same request twice old data wont change. View id is the id of the Google analytics view you wish to request the data from.
– DaImTo
Nov 21 '18 at 10:55
Thanks a lot. =)
– Pathum Samararathna
Nov 21 '18 at 11:28
I got this point that I need to use core reporting api. and do I need to use node.js client library? I want to fetch data from GA and display on my vue.js front-end. I do not need to store them anywhere. So for that reason do I need that client lib? What is this view id?
– Pathum Samararathna
Nov 21 '18 at 10:49
I got this point that I need to use core reporting api. and do I need to use node.js client library? I want to fetch data from GA and display on my vue.js front-end. I do not need to store them anywhere. So for that reason do I need that client lib? What is this view id?
– Pathum Samararathna
Nov 21 '18 at 10:49
Remember this is only going to fetch data for you will have to figure out how you want to format it yourself. Yes storing it is a good idea as there is no reason to make the same request twice old data wont change. View id is the id of the Google analytics view you wish to request the data from.
– DaImTo
Nov 21 '18 at 10:55
Remember this is only going to fetch data for you will have to figure out how you want to format it yourself. Yes storing it is a good idea as there is no reason to make the same request twice old data wont change. View id is the id of the Google analytics view you wish to request the data from.
– DaImTo
Nov 21 '18 at 10:55
Thanks a lot. =)
– Pathum Samararathna
Nov 21 '18 at 11:28
Thanks a lot. =)
– Pathum Samararathna
Nov 21 '18 at 11:28
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409462%2fgoogle-analytics-steps-to-get-number-of-views-per-page-from-an-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown