2010-01-11 110 views
0

以下代码用于在Google Analytics上检索用户帐户。我的问题是 在下面的代码中需要替换什么而不是代码ga:AccountNamega:ProfileId要查找登录网站的访问者。有关Google Analytics(分析)的问题

/* 
* 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); 
+0

什么都在这.. ..? – Hulk 2010-01-11 09:30:54

回答

1

您可以使用Google Analytics数据Feed查询浏览器Here is the link来构建API请求。如果您使用与Google Analytics数据关联的Google帐户进行身份验证,则可以选择一个配置文件来查询并查看关联的配置文件ID。

帐户ID是“UA-”后面的数字,位于您的Google Analytics跟踪代码中-1(或 - [任意数字])后缀的前面。从内存中,我认为AccountName是与Google帐户关联的电子邮件地址(可能是@ gmail.com,但不一定是)。

相关问题