我想从Google Analytics API v4中获得兴趣相似性

时间:2018-07-11 09:26:29

标签: json node.js google-analytics-api google-analytics-v4

我在我的Web应用程序中放置了Google Analytics(分析)的跟踪代码,现在我想从Google Analytics(分析)API中获得用户的兴趣,我正在使用Nodejs,这是我的请求代码和得到的JSON响应。

const dimensions_rows = [{
  name: 'ga:interestAffinityCategory'
}, ];

const date_filters = [{
  startDate: '7daysAgo',
  endDate: 'today',
}];
const req = {
  reportRequests: [{
    viewId: viewId,
    dateRanges: date_filters,
    dimensions: dimensions_rows,
  }],
};

analytics.reports.batchGet({
    auth: oauth2Client,
    requestBody: req
  },
  function(err, response) {
    if (err) {
      console.log('Failed to get Report');
      console.log(err);
      return;
    }
    // response.data is where the good stuff is located
    console.log('Success - got something back from the Googlez');
    console.log("responseee: ", JSON.stringify(response.data));
  }
);

//JSON response

{
"reports": [{
    "columnHeader": {
        "dimensions": ["ga:interestAffinityCategory"],
        "metricHeader": {
            "metricHeaderEntries": [{
                "name": "ga:visits",
                "type": "INTEGER"
            }]
        }
    },
    "data": {
        "totals": [{
             "values": ["0"]
        }]
    }
}]
}

0 个答案:

没有答案