Package com.google.gdata.client.analytics

Examples of com.google.gdata.client.analytics.AnalyticsService


  public static void main(String[] args) {

    //------------------------------------------------------
    // Configure GA API
    //------------------------------------------------------
    AnalyticsService as = new AnalyticsService("gaExportAPI_acctSample_v1.0");
    String baseUrl = "https://www.google.com/analytics/feeds/data";
    DataQuery query;

    //------------------------------------------------------
    // Client Login Authentication
    //------------------------------------------------------
    try {
      as.setUserCredentials(CLIENT_USERNAME, CLIENT_PASS);
    } catch (AuthenticationException e) {
      System.err.println("Error : " + e.getMessage());
      return;
    }

    //------------------------------------------------------
    // GA Data Feed
    //------------------------------------------------------
    // first build the query
    try {
      query = new DataQuery(new URL(baseUrl));
    } catch (MalformedURLException e) {
      System.err.println("Malformed URL: " + baseUrl);
      return;
    }
    query.setIds("ga:" + PROFILE_ID);
    query.setDimensions("ga:source,ga:medium");
    query.setMetrics("ga:visits,ga:bounces");
    query.setSort("-ga:visits");
    query.setFilters("ga:medium==referral");
    query.setMaxResults(100);
    query.setStartDate("2008-10-01");
    query.setEndDate("2008-10-31");
    URL url = query.getUrl();
    System.out.println("URL: " + url.toString());

    // Send our request to the Analytics API and wait for the results to come back
    DataFeed feed;
    try {
      feed = as.getFeed(url, DataFeed.class);
    } catch (IOException e) {
      System.err.println("Network error trying to retrieve feed: " + e.getMessage());
      return;
    } catch (ServiceException e) {
      System.err.println("Analytics API responded with an error message: " + e.getMessage());
View Full Code Here


  public static void main(String args[]) {

    //------------------------------------------------------
    // Configure GA API
    //------------------------------------------------------
    AnalyticsService as = new AnalyticsService("gaExportAPI_acctSample_v1.0");
    String baseUrl = "https://www.google.com/analytics/feeds/accounts/default";

    //------------------------------------------------------
    // Client Login Authentication
    //------------------------------------------------------
    try {
      as.setUserCredentials(CLIENT_USERNAME, CLIENT_PASS);
    } catch (AuthenticationException e) {
      System.err.println("Authentication failed : " + e.getMessage());
      return;
    }

    //------------------------------------------------------
    // GA Account Feed
    //------------------------------------------------------
    URL queryUrl;
    try {
      queryUrl = new URL(baseUrl);
    } catch (MalformedURLException e) {
      System.err.println("Malformed URL: " + baseUrl);
      return;
    }

    // Send our request to the Analytics API and wait for the results to come back
    AccountFeed accountFeed;
    try {
      accountFeed = as.getFeed(queryUrl, AccountFeed.class);
    } catch (IOException e) {
      System.err.println("Network error trying to retrieve feed: " + e.getMessage());
      return;
    } catch (ServiceException e) {
      System.err.println("Analytics API responded with an error message: " + e.getMessage());
View Full Code Here

    return new GoogleDataManager(
        UserServiceFactory.getUserService(),
        new TokenDaoJdoImpl(
            PMF.getInstance()),
        new AnalyticsServiceWrapper(
            new AnalyticsService(applicationName),
            new AuthorizationServiceAuthSubImpl(
                GoogleDataManager.GOOGLE_DATA_SCOPE),
            tableId, startDate, endDate, segment, segmentName));
  }
View Full Code Here

    return new GoogleDataManager(
        UserServiceFactory.getUserService(),
        new TokenDaoJdoImpl(
            PMF.getInstance()),
        new AnalyticsServiceWrapper(
            new AnalyticsService(applicationName),
            new AuthorizationServiceOauthImpl(
                GoogleDataManager.GOOGLE_DATA_SCOPE,
                new GoogleOAuthParameters()),
            tableId, startDate, endDate));
  }
View Full Code Here

    if (help || (userName == null)) {
      usage();
      System.exit(1);
    }

    AnalyticsService myService = new AnalyticsService("exampleCo-exampleApp-1");

    try {
      run(myService, userName, userPassword);
    } catch (ServiceException se) {
      se.printStackTrace();
View Full Code Here

   * Creates a new service object.  This is the object that will be used to
   * communicate with the API.
   */
  public static void initializeAnalyticsService() {
    try {
      analyticsService = new AnalyticsService(CLIENT_NAME);
      analyticsService.setUserCredentials(CLIENT_USERNAME, CLIENT_PASSWORD);
    } catch (AuthenticationException e) {
      System.err.println("Authentication failed : " + e.getMessage());
    }
  }
View Full Code Here

    spreadsheetService.setUserCredentials(username, password);
    // Workaround for Google Data APIs Java client issue #103
    // (http://code.google.com/p/gdata-java-client/issues/detail?id=103)
    spreadsheetService.setProtocolVersion(SpreadsheetService.Versions.V1);

    AnalyticsService analyticsService = new AnalyticsService(APP_NAME);
    analyticsService.setUserCredentials(username, password);

    SpreadsheetExporter exporter = new SpreadsheetExporter(spreadsheetService, analyticsService);
    exporter.exportToSpreadsheet(spreadsheetKey, tableId, startDate, endDate);
  }
View Full Code Here

   * Client Login.
   * @return AnalyticsService to be used
   */
  private static AnalyticsService getAnalyticsService(String clientName) {
    try {
      AnalyticsService analyticsService = new AnalyticsService(clientName);
      analyticsService.setUserCredentials(CLIENT_USERNAME, CLIENT_PASS);
      return analyticsService;
    } catch (AuthenticationException e) {
      System.err.println("Authentication failed : " + e.getMessage());
      System.exit(-1);
    }
View Full Code Here

   *         with an error.
   */
  public DataFeed getAnalyticsData() throws  IOException,
      com.google.gdata.util.ServiceException {

    AnalyticsService analyticsService = new AnalyticsService(CLIENT_NAME);
    analyticsService.setUserCredentials(USERNAME, PASSWORD);

    DataQuery dataQuery = new DataQuery(new URL("https://www.google.com/analytics/feeds/data"));
    dataQuery.setIds(PROFILE_ID);
    dataQuery.setStartDate(GA_START_DATE);
    dataQuery.setEndDate(GA_END_DATE);

    // Dimensions:  Boundaries for the data being requested.
    dataQuery.setDimensions("ga:year,ga:month,ga:adwordsCampaignID," +
        "ga:adwordsAdGroupID,ga:adwordsCriteriaID");

    // Metrics:  The data being requested
    dataQuery.setMetrics("ga:visits,ga:entrances,ga:bounces,ga:transactions," +
        "ga:transactionRevenue,ga:goalCompletionsAll,ga:goalValueAll");

    // A descending sort (highest values first) can be requested by placing a negative symbol in
    // front of the metric to sort by.
    dataQuery.setSort("-ga:transactionRevenue,-ga:entrances");

    // This example is specifically comparing Analytics data to keywords set up in AdWords.
    // AdWords returns clicks achieved via Content Targetting (think adsense on other websites)
    // as having a Criteria ID of 3000000.  While important, these aren't relevant to this example.
    // Thus, filter them out.
    dataQuery.setFilters("ga:adwordsCriteriaID!=3000000");
    dataQuery.setMaxResults(MAX_RESULTS);
    return analyticsService.getFeed(dataQuery.getUrl(), DataFeed.class);
  }
View Full Code Here

   * @throws ServiceException if an error occurs with the Google Analytics API.
   */
  public AccountFeedExample() throws AuthenticationException, IOException, ServiceException {

    // Configure GA API.
    AnalyticsService as = new AnalyticsService("gaExportAPI_acctSample_v2.0");

    // Client Login Authorization.
    as.setUserCredentials(CLIENT_USERNAME, CLIENT_PASS);

    // GA Account Feed query uri.
    String baseUrl = "https://www.google.com/analytics/feeds/accounts/default";
    URL queryUrl = new URL(baseUrl);

    // Send our request to the Analytics API and wait for the results to
    // come back.
    accountFeed = as.getFeed(queryUrl, AccountFeed.class);
  }
View Full Code Here

TOP

Related Classes of com.google.gdata.client.analytics.AnalyticsService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.