开发者

Question on Google Analytics

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开发者_如何学Go = 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);


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜