Exemple #1
0
  private static String SITEProfileId(Analytics analytics) throws IOException {
    String profileId = null;

    // Query accounts collection.
    com.google.api.services.analytics.model.Accounts accounts =
        analytics.management().accounts().list().execute();

    if (accounts.getItems().isEmpty()) {
      logger.error("No Google Analytics accounts found");
    } else {
      String firstAccountId = accounts.getItems().get(0).getId();

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

      if (webproperties.getItems().isEmpty()) {
        logger.error("No Google Analytics Webproperties found");
      } else {
        String firstWebpropertyId = webproperties.getItems().get(0).getId();

        // Query views (profiles) collection.
        Profiles profiles =
            analytics.management().profiles().list(firstAccountId, firstWebpropertyId).execute();

        if (profiles.getItems().isEmpty()) {
          logger.error("No Google Analytics views (profiles) found");
        } else {
          // 1 for "SITE All Projects"
          profileId = profiles.getItems().get(1).getId();
        }
      }
    }
    return profileId;
  }
 private String findProfileId(Analytics analytics, String accountName) throws IOException {
   logger.info((new StringBuilder()).append("Account Name: ").append(accountName).toString());
   String profileId = null;
   Accounts accounts = (Accounts) analytics.management().accounts().list().execute();
   if (accounts.getItems().isEmpty()) {
     logger.debug("No accounts found");
   } else {
     logger.debug(
         (new StringBuilder())
             .append("Accounts found: ")
             .append(accounts.getItems().size())
             .toString());
     String accountId = null;
     Iterator i$ = accounts.getItems().iterator();
     do {
       if (!i$.hasNext()) break;
       Account account = (Account) i$.next();
       String googleAccountName = account.getName();
       logger.debug(
           (new StringBuilder())
               .append("googleAccountName: ")
               .append(googleAccountName)
               .toString());
       logger.debug((new StringBuilder()).append("accountName: ").append(accountName).toString());
       if (!googleAccountName.equalsIgnoreCase(accountName)) continue;
       accountId = account.getId();
       break;
     } while (true);
     logger.debug((new StringBuilder()).append("accountId: ").append(accountId).toString());
     Webproperties webproperties =
         (Webproperties) analytics.management().webproperties().list(accountId).execute();
     if (webproperties.getItems().isEmpty()) {
       logger.debug("No Webproperties found");
     } else {
       String firstWebpropertyId = ((Webproperty) webproperties.getItems().get(0)).getId();
       Profiles profiles =
           (Profiles)
               analytics.management().profiles().list(accountId, firstWebpropertyId).execute();
       if (profiles.getItems().isEmpty()) logger.debug("No profiles found");
       else profileId = ((Profile) profiles.getItems().get(0)).getId();
     }
   }
   return profileId;
 }