Google 从 API 获取每页浏览量的分析步骤

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

我想从某个地方开始。 这是我的用例。

  1. 我休息API写在node.jsexpress framework.
  2. 我有一个用 react native 编写的移动应用程序。
  3. 我还有一个用于管理移动应用程序的 Web 应用程序,用 Vue.js
  4. 编写

移动应用是美食应用。在哪里可以搜索餐厅或餐厅的菜肴。

我想传递 餐厅 ID 并获取最近 7 天内该应用的餐厅浏览量。 非常直接的要求。但是很难实施。因为不知道从何说起。

我浏览了文档,发现有 7 个 APIs。

  1. 核心报告API
  2. 管理层API
  3. 嵌入API
  4. 用户删除API
  5. 多渠道报告API
  6. 实时API
  7. 元数据API

一天结束时,我很想用 API 做类似的事情。

showMeTheView(restaurant_id)

此外,如果我想传递额外的参数来表示仅获取上个月的观看次数。

showMeTheViews(restaurant_id, last_month)

我不知道实现我的要求的基本步骤是什么?

react-native app需要做什么? 在 vue.js 网络应用程序中需要做什么? 在这两者之间需要做什么?

首先你应该使用 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

如果你使用 Google apis node.js client libray 会让你的生活更轻松 从样本中提取的代码发现 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,
};