关于谷歌分析的问题
以下代码用于在 Google Analytics 上检索用户帐户。我的问题是 替换下面代码中的代码 ga:AccountName
和 ga:ProfileId
来查找登录网站的访问者。
/*
* Retrieve 50 accounts with profile names, profile IDs, table IDs
* for the authenticated user
*/
// Create the analytics service object
var analyticsService =
new google.gdata.analytics.AnalyticsService('iSample_acctSample_v1.0');
// The feed URI that is used for retrieving the analytics accounts
var feedUri =
'https://www.google.com/analytics/feeds/accounts/default?max-results=50';
// callback method to be invoked when getAccountFeed() returns data
var callback = function(result) {
// An array of analytics feed entries
var entries = result.feed.entry;
// create an HTML Table using an array of elements
var outputTable = ['<table>'];
outputTable.push('<tr>',
'<th>Account Name</th>',
'<th>Profile Name</th>',
'<th>Profile Id</th>',
'<th>Table Id</th></tr>');
// Iterate through the feed entries and add the data as table rows
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
// add a row in the HTML Table array for each value
var row = [
entry.getPropertyValue('ga:AccountName'),
entry.getTitle().getText(),
entry.getPropertyValue('ga:ProfileId'),
entry.getTableId().getValue()
].join('</td><td>');
outputTable.push('<tr><td>', row, '</td></tr>');
}
outputTable.push('</table>');
// print the generated table
PRINT(outputTable.join(''));
}
// Error handler
var handleError = function(error) {
PRINT(error);
}
// Submit the request using the analytics service object
analyticsService.getAccountFeed(feedUri, callback, handleError);
The below code is for Retrieve user Accounts on Google Analytics. My question is
what is to be replaced instead of the code ga:AccountName
and ga:ProfileId
in the below code To find the visitors logged in on the site.
/*
* Retrieve 50 accounts with profile names, profile IDs, table IDs
* for the authenticated user
*/
// Create the analytics service object
var analyticsService =
new google.gdata.analytics.AnalyticsService('iSample_acctSample_v1.0');
// The feed URI that is used for retrieving the analytics accounts
var feedUri =
'https://www.google.com/analytics/feeds/accounts/default?max-results=50';
// callback method to be invoked when getAccountFeed() returns data
var callback = function(result) {
// An array of analytics feed entries
var entries = result.feed.entry;
// create an HTML Table using an array of elements
var outputTable = ['<table>'];
outputTable.push('<tr>',
'<th>Account Name</th>',
'<th>Profile Name</th>',
'<th>Profile Id</th>',
'<th>Table Id</th></tr>');
// Iterate through the feed entries and add the data as table rows
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
// add a row in the HTML Table array for each value
var row = [
entry.getPropertyValue('ga:AccountName'),
entry.getTitle().getText(),
entry.getPropertyValue('ga:ProfileId'),
entry.getTableId().getValue()
].join('</td><td>');
outputTable.push('<tr><td>', row, '</td></tr>');
}
outputTable.push('</table>');
// print the generated table
PRINT(outputTable.join(''));
}
// Error handler
var handleError = function(error) {
PRINT(error);
}
// Submit the request using the analytics service object
analyticsService.getAccountFeed(feedUri, callback, handleError);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Google Analytics Data Feed Query Explorer 这里构建 API 请求链接。如果您使用与您的 Analytics(分析)数据关联的 Google 帐户进行身份验证,您将能够选择要查询的个人资料并查看关联的个人资料 ID。
帐户 ID 是 Analytics 跟踪代码中“UA-”之后、-1(或 -[任意数字])后缀之前的数字。根据记忆,我认为 AccountName 是与 Google 帐户关联的电子邮件地址(可能是 @gmail.com,但不一定是)。
You can build an API request using the Google Analytics Data Feed Query Explorer Here is the link. If you authenticate with a Google Account associated to your Analytics data, you'll be able to select a profile to query and see the associated Profile ID.
The Account ID is the number following the 'UA-' and preceding the -1 (or -[any number]) suffix in your Analytics tracking code. From memory, I think the AccountName is the email address associated to the Google Account (might be @gmail.com, but doesn't have to be).