}
public JSONObject getProfileMetrics(String profileId) throws IOException {
String formattedToday = DATE_TIME_FORMATTER.print(new DateTime());
Analytics analytics = initializeAnalytics();
GaData data = analytics.data().ga()
.get("ga:" + profileId, formattedToday, formattedToday, "ga:visitors,ga:newVisits")
.execute();
if (CollectionUtils.isEmpty(data.getRows())) {
return null;
}
JSONObjectBuilder builder = new JSONObjectBuilder();
builder.add("id", profileId);
int columnIndex = 0;
for (GaData.ColumnHeaders header : data.getColumnHeaders()) {
JSONObjectBuilder metric = new JSONObjectBuilder();
String metricName = normalizeMetricName(header.getName());
metric.add("metric", metricName);
metric.add("id", profileId);
Set<String> hashtags = new HashSet<>();
hashtags.add(metricName.toLowerCase());
for (List<String> row : data.getRows()) {
for (int rowIndex = 0; rowIndex < row.size(); rowIndex++) {
if (rowIndex == columnIndex) {
metric.add("data", new Float(row.get(rowIndex)));
}
}