Google Analytics APIs now available in the Objective-C library

105 views
Skip to first unread message

Greg Robbins

unread,
May 22, 2009, 4:29:50 PM5/22/09
to gdata-objec...@googlegroups.com
I've checked in classes to support the Google Analytics Data API to the top-of-trunk in the Objective-C library's svn repository.

There is currently no sample app for the new classes, though the following snippets show how to fetch the account and data feeds.

Note that the Analytics API feeds do not yet include "kind" category elements indicating the class for each type of feed and entry.  So rather than use the normal fetch calls in the GDataServiceGoogleAnalytics class, currently the superclass's "fetchAuthenticated..." calls must be used instead, as those take the class of the created object as an argument.  The snippets below demonstrate this.


// fetch the feed of account entries for the authenticated user
NSURL *feedURL = [NSURL URLWithString:kGDataGoogleAnalyticsDefaultAccountFeed];
GDataServiceGoogleAnalytics *service = [self analyticsService];

GDataServiceTicket *ticket;
ticket = [service fetchAuthenticatedFeedWithURL:feedURL
  feedClass:[GDataFeedAnalyticsAccount class]
  delegate:self
  didFinishSelector:@selector(accountsTicket:finishedWithFeed:)
  didFailSelector:@selector(accountsTicket:failedWithError:)];


Once the accounts feed is fetched, the data feed for an account can be requested with a query:

NSString *tableID = [accountEntry tableID];

GDataQueryAnalytics *dataQuery;
dataQuery = [GDataQueryAnalytics analyticsDataQueryWithTableID:tableID
  startDateString:@"2009-05-18"
  endDateString:@"2009-05-22"];
[dataQuery setDimensions:@"ga:country"];
[dataQuery setMetrics:@"ga:pageviews"];
   
ticket = [service fetchAuthenticatedFeedWithQuery:dataQuery
  feedClass:[GDataFeedAnalyticsData class]
  delegate:self
  didFinishSelector:@selector(dataTicket:finishedWithFeed:)
  didFailSelector:@selector(dataTicket:failedWithError:)];

Reply all
Reply to author
Forward
0 new messages