Google analytics steps to get number of views per page from an API












0















I AM TOTALLY NEW TO GOOGLE ANALYTICS.



I want to start somewhere.
This is my use case.




  1. I have a restAPI written in node.js express framework.

  2. I have a mobile application written in the react native.

  3. 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.




  1. Core reporting API

  2. Management API

  3. Embed API

  4. User deletion API

  5. Multi channel reporting API

  6. Real time API

  7. 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!










share|improve this question





























    0















    I AM TOTALLY NEW TO GOOGLE ANALYTICS.



    I want to start somewhere.
    This is my use case.




    1. I have a restAPI written in node.js express framework.

    2. I have a mobile application written in the react native.

    3. 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.




    1. Core reporting API

    2. Management API

    3. Embed API

    4. User deletion API

    5. Multi channel reporting API

    6. Real time API

    7. 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!










    share|improve this question



























      0












      0








      0








      I AM TOTALLY NEW TO GOOGLE ANALYTICS.



      I want to start somewhere.
      This is my use case.




      1. I have a restAPI written in node.js express framework.

      2. I have a mobile application written in the react native.

      3. 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.




      1. Core reporting API

      2. Management API

      3. Embed API

      4. User deletion API

      5. Multi channel reporting API

      6. Real time API

      7. 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!










      share|improve this question
















      I AM TOTALLY NEW TO GOOGLE ANALYTICS.



      I want to start somewhere.
      This is my use case.




      1. I have a restAPI written in node.js express framework.

      2. I have a mobile application written in the react native.

      3. 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.




      1. Core reporting API

      2. Management API

      3. Embed API

      4. User deletion API

      5. Multi channel reporting API

      6. Real time API

      7. 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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 10:23









      DaImTo

      46.4k1165246




      46.4k1165246










      asked Nov 21 '18 at 9:58









      Pathum SamararathnaPathum Samararathna

      939930




      939930
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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,
          };





          share|improve this answer
























          • 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











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


          }
          });














          draft saved

          draft discarded


















          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









          1














          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,
          };





          share|improve this answer
























          • 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
















          1














          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,
          };





          share|improve this answer
























          • 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














          1












          1








          1







          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,
          };





          share|improve this answer













          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,
          };






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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



















          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?