Package com.google.gdata.client.analytics

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


    //------------------------------------------------------
    // 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 {
View Full Code Here


      endDate = gaDate.format(lastMonth.getTime());
    }
     

    // Make a query.
    DataQuery query = new DataQuery(new URL(BASE_DATA_FEED_URL));
    query.setIds(tableId);
    query.setDimensions("ga:year,ga:month");
    query.setMetrics("ga:visits,ga:transactions,ga:itemQuantity,ga:uniquePageviews,ga:bounces,ga:entrances");
    query.setSort("ga:year,ga:month");
    query.setMaxResults(500);
    query.setStartDate(startDate);
    query.setEndDate(endDate);
    if (segment !=null) {
      query.setSegment(segment);
    }
   
    log.info(query.getUrl().toString());
    String theURL = query.getUrl().toString();
    return query.getUrl();
  }
View Full Code Here

   * @throws MalformedURLException If the URL used to request data is malformed
   */
  public static DataQuery getBasicQuery(String tableId) throws MalformedURLException {
    // Set up the request (we could alternately construct a URL manually with all query parameters
    // set)
    DataQuery query = new DataQuery(new URL(DATA_URL));
    query.setIds(tableId);
    query.setStartDate("2009-01-01");
    query.setEndDate("2009-01-31");
    query.setDimensions("ga:browser");
    query.setMetrics("ga:visits,ga:bounces");

    return query;
  }
View Full Code Here

    // Each entry in the account feed represents an individual profile
    AccountEntry profile = accountFeed.getEntries().get(0);
    String tableId = profile.getTableId().getValue();

    // Print the results of a basic request
    DataQuery basicQuery = getBasicQuery(tableId);
    DataFeed basicData = myService.getFeed(basicQuery, DataFeed.class);
    printData("BASIC RESULTS", basicData);

    // Ask Analytics to return the data sorted in descending order of visits
    DataQuery sortedQuery = getBasicQuery(tableId);
    sortedQuery.setSort("-ga:visits");
    DataFeed sortedData = myService.getFeed(sortedQuery, DataFeed.class);
    printData("SORTED RESULTS", sortedData);

    // Ask Analytics to filter out browsers that contain the word "Explorer"
    DataQuery filteredQuery = getBasicQuery(tableId);
    filteredQuery.setFilters("ga:browser!@Explorer");
    DataFeed filteredData = myService.getFeed(filteredQuery, DataFeed.class);
    printData("FILTERED RESULTS", filteredData);
  }
View Full Code Here

      String tableId,
      ColumnTypeMap columnTypeMap,
      String startDate,
      String endDate) throws IOException, ServiceException {

    DataQuery query = new DataQuery(new URL("https://www.google.com/analytics/feeds/data"));
    query.setIds(tableId);
    query.setDimensions(columnTypeMap.getColumnString(ColumnType.DIMENSION));
    query.setMetrics(columnTypeMap.getColumnString(ColumnType.METRIC));
    query.setStartDate(startDate);
    query.setEndDate(endDate);
    DataFeed feed = analyticsService.getFeed(query, DataFeed.class);
    return feed.getEntries();
  }
View Full Code Here

   * Returns a new DataQuery object. Catches all exceptions.
   * @return
   */
  public static DataQuery getNewDataQuery() {
    try {
      return new DataQuery(new URL(DATA_FEED_BASE_URL));
    } catch (MalformedURLException e) { TestCase.fail(); }
    return null;
  }
View Full Code Here

  /**
   * Returns a new DataQuery object that has a set of filled parameters.
   * @return A filled DataQuery object.
   */
  public static DataQuery getFilledDataQuery() {
    DataQuery dataQuery = getNewDataQuery();
    dataQuery.setStartDate("2010-01-01");
    dataQuery.setEndDate("2010-01-15");
    dataQuery.setDimensions("ga:landingPagePath");
    dataQuery.setMetrics("ga:entrances");
    return dataQuery;
  }
View Full Code Here

  /**
   * Tests getting filtered queries.
   */
  public void testGetFilteredQueries() {
    DataQuery dataQueryTest = TestUtil.getFilledDataQuery();
    String dimensionName = "ga:landingPagePath";
    dataQueryTest.setDimensions(dimensionName);

    List<String> dimensionValues = new ArrayList<String>();
    String dimensionValue = "/foo";
    dimensionValues.add(dimensionValue);

    // Ensure list of filters is being set.
    queries = queryManager.getFilteredQueries(dataQueryTest, dimensionValues);
    assertNotNull(queries);
    assertNotNull(queries.getFilterList());
    assertNotNull(queries.getQuery());
    assertEquals(dimensionValues.size(), queries.getFilterList().size());

    String expectedFilter = Filter.getEqualityFilter(dimensionName, dimensionValue);
    assertEquals(expectedFilter, queries.getFilterList().get(0));

    // Ensure query is updated.
    DataQuery resultQuery = queries.getFilteredQuery(0);

    // The following lines help setup the test. Because getFilteredQueries
    // calls updateQuery, the expectedQuery is also passed through
    // updateQuery.
    DataQuery expectedQuery = TestUtil.getFilledDataQuery();
    expectedQuery.setDimensions(dimensionName);
    queryManager.updateQuery(expectedQuery);

    assertEquals(expectedQuery.getMaxResults(), resultQuery.getMaxResults());
    assertEquals(expectedQuery.getSort(), resultQuery.getSort());
    assertEquals(expectedQuery.getDimensions(), resultQuery.getDimensions());
  }
View Full Code Here

  /**
   * Tests the iterator implementation of getFileredQueries.
   */
  public void testGetFilteredQueries_iteratorImplementation() {
    DataQuery dataQueryTest = TestUtil.getFilledDataQuery();
    String dimensionName = "ga:landingPagePath";
    dataQueryTest.setDimensions(dimensionName);

    List<String> dimensionValues = TestUtil.toList(new String[]{"/foo", "/bar", "bat"});

    queries = queryManager.getFilteredQueries(dataQueryTest, dimensionValues);

    // The following lines help setup the test. Because getFilteredQueries
    // calls updateQuery, the expectedQuery is also passed through
    // updateQuery.
    DataQuery expectedQuery = TestUtil.getFilledDataQuery();
    expectedQuery.setDimensions(dimensionName);
    queryManager.updateQuery(expectedQuery);

    for (String dimensionValue : dimensionValues) {
      String expectedFilter = Filter.getEqualityFilter(dimensionName, dimensionValue);
      expectedQuery.setFilters(expectedFilter);

      DataQuery testQuery = queries.next();
      assertEquals(expectedQuery.getUrl(), testQuery.getUrl());
    }
  }
View Full Code Here

  /**
   * Tests updating the query.
   */
  public void testGetUpdatedQuery() {
    DataQuery query = TestUtil.getFilledDataQuery();
    queryManager.updateQuery(query);

    int maxResults = DataQueryUtil.getNumberOfDays(query);
    assertEquals(maxResults, query.getMaxResults());
    assertTrue("ga:date".equals(query.getSort()));
    assertTrue("ga:date".equals(query.getDimensions()));
    assertEquals(-1, query.getStartIndex());
  }
View Full Code Here

TOP

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

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.