Google 分析 API - 对 "ids" 代表什么感到困惑
Google Analytics API - Confused by what "ids" represents
我在我的网络应用程序中使用 GA API,其中一项分析如下所示:
gapi.analytics.ready(function () {
/*
* Authorize the user immediately if the user has already granted access.
* If no access has been created, render an authorize button inside the
* element with the ID "embed-api-auth-container".
*/
gapi.analytics.auth.authorize({
container: 'embed-api-auth-container',
clientid: 'xxxxxxxx.apps.googleusercontent.com'
});
/**
* Create a new ViewSelector instance to be rendered inside of an
* element with the id "view-selector-container".
*/
var viewSelector = new gapi.analytics.ViewSelector({
container: 'view-selector-container'
});
// Render the view selector to the page.
viewSelector.execute();
/*
* Create a new DataChart instance with the given query parameters
* and Google chart options. It will be rendered inside an element
* with the id "chart-container".
*/
var dataChart1 = new gapi.analytics.googleCharts.DataChart({
query: {
metrics: 'ga:newUsers, ga:users',
dimensions: 'ga:date',
'start-date': beginDate,
'end-date': endDate
},
chart: {
container: 'chart1-container',
type: 'COLUMN',
options: {
width: '100%',
isStacked: true
}
}
});
/*
* Render the dataChart on the page whenever a new view is selected.
*/
viewSelector.on('change', function(ids) {
dataChart1.set({ query: { ids: ids } }).execute();
});
});
问题是这样的。当我从我的笔记本电脑上执行此分析时,它的执行完全符合我的预期。但是,如果我尝试从另一台设备执行它,则不会从 GA 呈现任何图表,也不会生成任何错误。我猜,但真的不知道,问题出在底部的 viewSelector.on 语句,它期望 "ids" 值。但是,我不知道这些值是什么,也不知道 GA 期望什么。
可能是您在浏览器上使用此脚本,并在其中登录到 GA(笔记本电脑)- 并且运行良好。
但在另一台设备上它可能无法工作,因为您没有在 Google Analytics 中获得 ID 授权,您正在尝试可视化哪些数据。
理想情况下,如果您未获得授权,您应该会看到授权按钮,如代码注释中所述:
If no access has been created, render an authorize button inside the
* element with the ID "embed-api-auth-container"
确保您使用相同的 Google 帐户或有权访问您想要报告的 Google 分析视图的帐户登录。
'ids' 代表 Google 分析视图的 ID。它的格式应该是 'ga:123456789'.
参见[参考指南Query Parameters Summary。
登录后 Google 分析网站的默认登录页面是报告页面。导航到管理(顶部菜单),然后单击查看设置。您的视图 ID 将显示在那里。
我在我的网络应用程序中使用 GA API,其中一项分析如下所示:
gapi.analytics.ready(function () {
/*
* Authorize the user immediately if the user has already granted access.
* If no access has been created, render an authorize button inside the
* element with the ID "embed-api-auth-container".
*/
gapi.analytics.auth.authorize({
container: 'embed-api-auth-container',
clientid: 'xxxxxxxx.apps.googleusercontent.com'
});
/**
* Create a new ViewSelector instance to be rendered inside of an
* element with the id "view-selector-container".
*/
var viewSelector = new gapi.analytics.ViewSelector({
container: 'view-selector-container'
});
// Render the view selector to the page.
viewSelector.execute();
/*
* Create a new DataChart instance with the given query parameters
* and Google chart options. It will be rendered inside an element
* with the id "chart-container".
*/
var dataChart1 = new gapi.analytics.googleCharts.DataChart({
query: {
metrics: 'ga:newUsers, ga:users',
dimensions: 'ga:date',
'start-date': beginDate,
'end-date': endDate
},
chart: {
container: 'chart1-container',
type: 'COLUMN',
options: {
width: '100%',
isStacked: true
}
}
});
/*
* Render the dataChart on the page whenever a new view is selected.
*/
viewSelector.on('change', function(ids) {
dataChart1.set({ query: { ids: ids } }).execute();
});
});
问题是这样的。当我从我的笔记本电脑上执行此分析时,它的执行完全符合我的预期。但是,如果我尝试从另一台设备执行它,则不会从 GA 呈现任何图表,也不会生成任何错误。我猜,但真的不知道,问题出在底部的 viewSelector.on 语句,它期望 "ids" 值。但是,我不知道这些值是什么,也不知道 GA 期望什么。
可能是您在浏览器上使用此脚本,并在其中登录到 GA(笔记本电脑)- 并且运行良好。 但在另一台设备上它可能无法工作,因为您没有在 Google Analytics 中获得 ID 授权,您正在尝试可视化哪些数据。
理想情况下,如果您未获得授权,您应该会看到授权按钮,如代码注释中所述:
If no access has been created, render an authorize button inside the * element with the ID "embed-api-auth-container"
确保您使用相同的 Google 帐户或有权访问您想要报告的 Google 分析视图的帐户登录。
'ids' 代表 Google 分析视图的 ID。它的格式应该是 'ga:123456789'.
参见[参考指南Query Parameters Summary。
登录后 Google 分析网站的默认登录页面是报告页面。导航到管理(顶部菜单),然后单击查看设置。您的视图 ID 将显示在那里。