关于谷歌分析的问题

发布于 2024-08-17 02:45:06 字数 1830 浏览 3 评论 0原文

以下代码用于在 Google Analytics 上检索用户帐户。我的问题是 替换下面代码中的代码 ga:AccountNamega: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为守护你 2024-08-24 02:45:06

您可以使用 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文