diff --git a/modules/gapi/gapi.php b/modules/gapi/gapi.php index 31e5276a6..75dfceab6 100644 --- a/modules/gapi/gapi.php +++ b/modules/gapi/gapi.php @@ -48,6 +48,12 @@ class Gapi extends Module return $this->api_3_0_getContent(); } + public function requestReportData($dimensions, $metrics, $date_from, $date_to, $sort = null, $filters = null, $start = 1, $limit = 30) + { + // You can switch to the 1.3 API by replacing the following function call by $this->api_1_3_requestReportData() + return $this->api_3_0_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort, $filters, $start, $limit); + } + public function api_3_0_authenticate() { // https://developers.google.com/accounts/docs/OAuth2WebServer @@ -103,7 +109,7 @@ class Gapi extends Module public function api_3_0_getContent() { $html = ''; - if (Tools::isSubmit('PS_GAPI30_CLIENT_ID')) + if (Tools::getValue('PS_GAPI30_CLIENT_ID')) { Configuration::updateValue('PS_GAPI30_REQUEST_URI_TMP', dirname($_SERVER['REQUEST_URI']).'/'.AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); Configuration::updateValue('PS_GAPI30_CLIENT_ID_TMP', trim(Tools::getValue('PS_GAPI30_CLIENT_ID'))); @@ -124,13 +130,72 @@ class Gapi extends Module $html .= $this->displayError('Google API Authorization granted but access token cannot be retrieved'); } + $display_slider = true; if (Configuration::get('PS_GAPI30_CLIENT_ID') && Configuration::get('PS_GAPI30_CLIENT_SECRET') && Configuration::get('PS_GAPI30_PROFILE')) { $result_test = $this->api_3_0_requestReportData('', 'ga:visits,ga:uniquePageviews', date('Y-m-d', strtotime('-1 day')), date('Y-m-d', strtotime('-1 day')), null, null, 1, 1); if (!$result_test) $html .= $this->displayError('Cannot retrieve test results'); else + { + $display_slider = false; $html .= $this->displayConfirmation(sprintf($this->l('Yesterday, your store received the visit of %d people for a total of %d unique page views.'), $result_test[0]['metrics']['visits'], $result_test[0]['metrics']['uniquePageviews'])); + } + } + + if ($display_slider) + { + $slides = array( + 'Google API - 01 - Start.png' => $this->l('Go to https://code.google.com/apis/console and click the "Create project..." button'), + 'Google API - 02 - Services.png' => $this->l('In the "Services" tab, switch on the Analytics API'), + 'Google API - 03 - Terms.png' => $this->l('You will be asked to agree to the Terms of Service of Google APIs'), + 'Google API - 04 - Terms.png' => $this->l('And the Terms of Service of Analytics API'), + 'Google API - 05 - Services OK.png' => $this->l('You should now have something like that'), + 'Google API - 06 - API Access.png' => $this->l('In the "API Access" tab, click the big, blue, "Create an OAuth 2.0 client ID..." button'), + 'Google API - 07 - Create Client ID.png' => $this->l('Fill in the form with the name of your store, the URL of your logo and the URL of your store then click "Next"'), + 'Google API - 08 - Create Client ID.png' => sprintf($this->l('Keep "Web application" select and fill in the "Authorized Redirect URIs" area with the following URL: %s (you may have to click the "more options" link). Then validate by clicking the "Create client ID" button'), Tools::getShopDomain(true, false).__PS_BASE_URI__.'modules/'.$this->name.'/oauth2callback.php'), + 'Google API - 09 - API Access created.png' => $this->l('You should now have the following screen. Copy/Paste the "Client ID" and "Client secret" into the form below'), + 'Google API - 10 - Profile ID.png' => $this->l('Now you need the ID of the Analytics Profile you want to connect. In order to find you Profile ID, connect to the Analytics dashboard look at the URL in the address bar. Your Profile ID is the number following a "p", as shown underlined in red on the screenshot') + ); + $first_slide = key($slides); + + $html .= ' + +
+ +
+
 
+ '; } $helper = new HelperOptions($this); @@ -141,27 +206,24 @@ class Gapi extends Module $fields_options = array( 'general' => array( - 'title' => $this->l('Google Analytics API'), + 'title' => $this->l('Google Analytics API v3.0'), 'icon' => $this->_path.'logo.png', 'fields' => $fields = array( 'PS_GAPI30_CLIENT_ID' => array( 'title' => $this->l('Client ID'), - 'validation' => 'isEmail', 'type' => 'text' ), 'PS_GAPI30_CLIENT_SECRET' => array( 'title' => $this->l('Client Secret'), - 'validation' => 'isNothing', 'type' => 'text' ), 'PS_GAPI30_PROFILE' => array( 'title' => $this->l('Profile'), - 'validation' => 'isUnsignedInt', 'type' => 'text', 'desc' => sprintf($this->l('You can find your profile ID in the address bar of your browser while accessing Analytics report: %s.'), ''.$this->l('see screenshot').'') ) ), - 'submit' => array('title' => $this->l('Authenticate')), + 'submit' => array('title' => $this->l('Save and Authenticate')), ) ); @@ -202,7 +264,7 @@ class Gapi extends Module // https://developers.google.com/analytics/devguides/reporting/core/dimsmets // requestReportData('ga:country', 'ga:visits', '2013-08-25', '2013-08-25', null, null, 1, 1000); - protected function api_3_0_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort = null, $filters = null, $start = 1, $limit = 30) + protected function api_3_0_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort, $filters, $start, $limit) { if (Configuration::get('PS_GAPI30_TOKEN_EXPIRATION') < time() + 30 && !$this->api_3_0_refreshtoken()) return false; @@ -282,7 +344,7 @@ class Gapi extends Module $fields_options = array( 'general' => array( - 'title' => $this->l('Google Analytics API'), + 'title' => $this->l('Google Analytics API v1.3'), 'icon' => $this->_path.'logo.png', 'fields' => $fields = array( 'PS_GAPI13_EMAIL' => array( @@ -332,7 +394,7 @@ class Gapi extends Module } // requestReportData('ga:country', 'ga:visits', '2013-08-25', '2013-08-25', null, null, 1, 1000); - protected function api_1_3_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort = null, $filters = null, $start = 1, $limit = 30) + protected function api_1_3_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort, $filters, $start, $limit) { if (!$this->api_1_3_authenticate(Configuration::get('PS_GAPI13_EMAIL'), Configuration::get('PS_GAPI13_PASSWORD'))) return false; diff --git a/modules/gapi/screenshots/3.0/Google API - 01 - Start.png b/modules/gapi/screenshots/3.0/Google API - 01 - Start.png new file mode 100644 index 000000000..ab6ff0399 Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 01 - Start.png differ diff --git a/modules/gapi/screenshots/3.0/Google API - 02 - Services.png b/modules/gapi/screenshots/3.0/Google API - 02 - Services.png new file mode 100644 index 000000000..fbcf8e4bf Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 02 - Services.png differ diff --git a/modules/gapi/screenshots/3.0/Google API - 03 - Terms.png b/modules/gapi/screenshots/3.0/Google API - 03 - Terms.png new file mode 100644 index 000000000..88bd4d493 Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 03 - Terms.png differ diff --git a/modules/gapi/screenshots/3.0/Google API - 04 - Terms.png b/modules/gapi/screenshots/3.0/Google API - 04 - Terms.png new file mode 100644 index 000000000..2843c152e Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 04 - Terms.png differ diff --git a/modules/gapi/screenshots/3.0/Google API - 05 - Services OK.png b/modules/gapi/screenshots/3.0/Google API - 05 - Services OK.png new file mode 100644 index 000000000..e39b6dd96 Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 05 - Services OK.png differ diff --git a/modules/gapi/screenshots/3.0/Google API - 06 - API Access.png b/modules/gapi/screenshots/3.0/Google API - 06 - API Access.png new file mode 100644 index 000000000..209a88fcd Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 06 - API Access.png differ diff --git a/modules/gapi/screenshots/3.0/Google API - 07 - Create Client ID.png b/modules/gapi/screenshots/3.0/Google API - 07 - Create Client ID.png new file mode 100644 index 000000000..81ace0411 Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 07 - Create Client ID.png differ diff --git a/modules/gapi/screenshots/3.0/Google API - 08 - Create Client ID.png b/modules/gapi/screenshots/3.0/Google API - 08 - Create Client ID.png new file mode 100644 index 000000000..c3f40fdfe Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 08 - Create Client ID.png differ diff --git a/modules/gapi/screenshots/3.0/Google API - 09 - API Access created.png b/modules/gapi/screenshots/3.0/Google API - 09 - API Access created.png new file mode 100644 index 000000000..bd6a06765 Binary files /dev/null and b/modules/gapi/screenshots/3.0/Google API - 09 - API Access created.png differ diff --git a/modules/gapi/screenshots/Google API - 10 - Profile ID.png b/modules/gapi/screenshots/3.0/Google API - 10 - Profile ID.png similarity index 100% rename from modules/gapi/screenshots/Google API - 10 - Profile ID.png rename to modules/gapi/screenshots/3.0/Google API - 10 - Profile ID.png diff --git a/modules/gapi/screenshots/Google API - 01 - Start.png b/modules/gapi/screenshots/Google API - 01 - Start.png deleted file mode 100644 index 012d078c7..000000000 Binary files a/modules/gapi/screenshots/Google API - 01 - Start.png and /dev/null differ diff --git a/modules/gapi/screenshots/Google API - 02 - Services.png b/modules/gapi/screenshots/Google API - 02 - Services.png deleted file mode 100644 index 5b45d4494..000000000 Binary files a/modules/gapi/screenshots/Google API - 02 - Services.png and /dev/null differ diff --git a/modules/gapi/screenshots/Google API - 03 - Terms.png b/modules/gapi/screenshots/Google API - 03 - Terms.png deleted file mode 100644 index a6c889e4f..000000000 Binary files a/modules/gapi/screenshots/Google API - 03 - Terms.png and /dev/null differ diff --git a/modules/gapi/screenshots/Google API - 04 - Terms.png b/modules/gapi/screenshots/Google API - 04 - Terms.png deleted file mode 100644 index c2a9c4582..000000000 Binary files a/modules/gapi/screenshots/Google API - 04 - Terms.png and /dev/null differ diff --git a/modules/gapi/screenshots/Google API - 05 - Services OK.png b/modules/gapi/screenshots/Google API - 05 - Services OK.png deleted file mode 100644 index 158634aba..000000000 Binary files a/modules/gapi/screenshots/Google API - 05 - Services OK.png and /dev/null differ diff --git a/modules/gapi/screenshots/Google API - 06 - API Access.png b/modules/gapi/screenshots/Google API - 06 - API Access.png deleted file mode 100644 index f7a8235ea..000000000 Binary files a/modules/gapi/screenshots/Google API - 06 - API Access.png and /dev/null differ diff --git a/modules/gapi/screenshots/Google API - 07 - Create Client ID.png b/modules/gapi/screenshots/Google API - 07 - Create Client ID.png deleted file mode 100644 index 1936f57cc..000000000 Binary files a/modules/gapi/screenshots/Google API - 07 - Create Client ID.png and /dev/null differ diff --git a/modules/gapi/screenshots/Google API - 08 - Create Client ID.png b/modules/gapi/screenshots/Google API - 08 - Create Client ID.png deleted file mode 100644 index d263b30ba..000000000 Binary files a/modules/gapi/screenshots/Google API - 08 - Create Client ID.png and /dev/null differ diff --git a/modules/gapi/screenshots/Google API - 09 - API Access created.png b/modules/gapi/screenshots/Google API - 09 - API Access created.png deleted file mode 100644 index 570f7cacb..000000000 Binary files a/modules/gapi/screenshots/Google API - 09 - API Access created.png and /dev/null differ