/** * Returns the profile ID from the set Google UID * * TODO: move the use of this method to the UID setting. So we can have the setting value in an easy to get the Profile ID format * TODO: Preferred format: UID:ProfileID * * @since 1.0 * @return array * @throws Exception */ function get_single_ga_profile() { $webproperty_id = get_option('woocommerce_woocommerce_grow_settings'); $ga_uid = $webproperty_id['ga_api_uid']; if (empty($ga_uid)) { // TODO: TEST throw new Exception(sprintf(__('The Google Account User ID is not set. Please visit %ssettings page%s to set the Google UID.', 'woocommerce-grow'), '<a href="' . WooCommerce_Grow_Helpers::get_plugin_settings_page() . '" target="_blank">', '</a>')); } list($pre, $account_id, $post) = explode('-', $ga_uid); try { $profiles = $this->analytics->management_profiles->listManagementProfiles($account_id, $ga_uid); } catch (Exception $e) { throw new Exception(sprintf(__('Analytics API error occurred. Error Code: %s. Error Message: %s ', 'woocommerce-grow'), $e->getCode(), $e->getMessage())); } $profile_id = $profiles->items[0]->id; // If the profile is empty or it does not match the UID we chose to use. if (empty($profile_id) || $ga_uid != $profiles->items[0]->webPropertyId) { throw new Exception(sprintf(__('There is no Google Profile ID found from your Google UID. Please visit %ssettings page%s to set the Google UID.', 'woocommerce-grow'), '<a href="' . WooCommerce_Grow_Helpers::get_plugin_settings_page() . '" target="_blank">', '</a>')); } return $profile_id; }