Package com.google.api.services.analytics

Examples of com.google.api.services.analytics.Analytics


            throw new InvalidCredentialsException("You must have one or more profiles defined in Google Analytics in order to continue.");
        }
    }

    public List<JSONObject> getProfiles() throws IOException {
        Analytics analytics = initializeAnalytics();
        Accounts accounts = analytics.management().accounts().list().execute();

        List<JSONObject> jsonProfiles = Lists.newArrayList();

        if (accounts.getItems().isEmpty()) {
            System.err.println("No accounts found");
        }
        else {
            for (Account account : accounts.getItems()) {
                String accountId = account.getId();

                // Query webproperties collection.
                Webproperties webproperties = analytics.management().webproperties().list(accountId).execute();

                if (webproperties.getItems().isEmpty()) {
                    System.err.println("No Webproperties found");
                }
                else {
                    for (Webproperty webproperty : webproperties.getItems()) {
                        String webpropertyId = webproperty.getId();

                        // Query profiles collection.
                        Profiles profiles = analytics.management().profiles().list(accountId, webpropertyId).execute();
                        if (profiles.getItems().isEmpty()) {
                            System.err.println("No profiles found");
                        }
                        else {
                            for (Profile profile : profiles.getItems()) {
View Full Code Here


        return jsonProfiles;
    }

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

  public static void main(String[] args) {
    try {
      HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
      DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
      Analytics analytics = initializeAnalytics();
      GaData gaData = executeDataQuery(analytics, TABLE_ID);

      printDataTable(gaData);

    } catch (GoogleJsonResponseException e) {
View Full Code Here

TOP

Related Classes of com.google.api.services.analytics.Analytics

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.