diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py index 8a59d730714..3af688a6346 100644 --- a/addons/website/controllers/backend.py +++ b/addons/website/controllers/backend.py @@ -30,14 +30,16 @@ class WebsiteBackend(http.Controller): } } if has_group_designer: - ga_dashboard = request.env['ir.config_parameter'].sudo().get_param('website.has_google_analytics_dashboard') - if ga_dashboard: - ga_client_id = request.env['ir.config_parameter'].sudo().get_param('google_management_client_id', default='') - dashboard_data['dashboards']['visits']['ga_client_id'] = ga_client_id + config = request.env['website.config.settings'].sudo().create({}) + if config.has_google_analytics_dashboard: + dashboard_data['dashboards']['visits'] = dict( + ga_client_id=config.google_management_client_id or '', # void string instead of stringified False + ga_analytics_key=config.google_analytics_key or '', # void string instead of stringified False + ) return dashboard_data - @http.route('/website/dashboard/set_ga_client_id', type='json', auth='user') - def website_set_ga_client_id(self, ga_client_id): + @http.route('/website/dashboard/set_ga_data', type='json', auth='user') + def website_set_ga_data(self, ga_client_id, ga_analytics_key): if not request.env.user.has_group('base.group_system'): return { 'error': { @@ -45,15 +47,17 @@ class WebsiteBackend(http.Controller): 'message': 'You do not have sufficient rights to perform that action.', } } - if not ga_client_id.endswith('.apps.googleusercontent.com') or ga_client_id.startswith(" "): + if not ga_analytics_key or not ga_client_id.endswith('.apps.googleusercontent.com'): return { 'error': { - 'title': 'Incorrect Client ID', - 'message': 'The Google Analytics Client ID you have entered seems incorrect.', + 'title': 'Incorrect Client ID / Key', + 'message': 'The Google Analytics Client ID or Key you entered seems incorrect.', } } - request.env['website.config.setting'].create({ - 'use_google_analytics_dashboard': True, + request.env['website.config.settings'].create({ + 'has_google_analytics': True, + 'has_google_analytics_dashboard': True, 'google_management_client_id': ga_client_id, - }) + 'google_analytics_key': ga_analytics_key, + }).execute() return True diff --git a/addons/website/models/res_config.py b/addons/website/models/res_config.py index 094a94e2e96..b1a8f26608d 100644 --- a/addons/website/models/res_config.py +++ b/addons/website/models/res_config.py @@ -54,6 +54,19 @@ class WebsiteConfigSettings(models.TransientModel): has_google_analytics_dashboard = fields.Boolean("Google Analytics in Dashboard") has_google_maps = fields.Boolean("Google Maps") + @api.onchange('has_google_analytics') + def onchange_has_google_analytics(self): + if not self.has_google_analytics: + self.has_google_analytics_dashboard = False + if not self.has_google_analytics: + self.google_analytics_key = False + + @api.onchange('has_google_analytics_dashboard') + def onchange_has_google_analytics_dashboard(self): + if not self.has_google_analytics_dashboard: + self.google_management_client_id = False + self.google_management_client_secret = False + def get_default_google_maps_api_key(self, fields): if not self.user_has_groups('website.group_website_designer'): raise AccessDenied() diff --git a/addons/website/static/src/js/website.backendDashboard.js b/addons/website/static/src/js/website.backendDashboard.js index f5c9c6b7b2f..f1dcdf6a6ec 100644 --- a/addons/website/static/src/js/website.backendDashboard.js +++ b/addons/website/static/src/js/website.backendDashboard.js @@ -76,7 +76,10 @@ var Dashboard = Widget.extend(ControlPanelMixin, { var dialog = new Dialog(this, { size: 'medium', title: _t('Google Analytics'), - $content: QWeb.render('website.ga_dialog_content', {ga_key: this.dashboards_data.visits.ga_client_id}), + $content: QWeb.render('website.ga_dialog_content', { + ga_key: this.dashboards_data.visits.ga_client_id, + ga_analytics_key: this.dashboards_data.visits.ga_analytics_key, + }), buttons: [ { text: _t("Save"), @@ -84,7 +87,8 @@ var Dashboard = Widget.extend(ControlPanelMixin, { close: true, click: function() { var ga_client_id = dialog.$el.find('input[name="ga_client_id"]').val(); - self.on_save_ga_client_id(ga_client_id); + var ga_analytics_key = dialog.$el.find('input[name="ga_analytics_key"]').val(); + self.on_save_ga_client_id(ga_client_id, ga_analytics_key); }, }, { @@ -95,12 +99,13 @@ var Dashboard = Widget.extend(ControlPanelMixin, { }).open(); }, - on_save_ga_client_id: function(ga_client_id) { + on_save_ga_client_id: function(ga_client_id, ga_analytics_key) { var self = this; return this._rpc({ - route: '/website/dashboard/set_ga_client_id', + route: '/website/dashboard/set_ga_data', params: { - 'ga_client_id': ga_client_id + 'ga_client_id': ga_client_id, + 'ga_analytics_key': ga_analytics_key, }, }).then(function (result) { if (result.error) { diff --git a/addons/website/static/src/xml/website.backend.xml b/addons/website/static/src/xml/website.backend.xml index a30267af9a8..9abb82e0e49 100644 --- a/addons/website/static/src/xml/website.backend.xml +++ b/addons/website/static/src/xml/website.backend.xml @@ -92,8 +92,15 @@
- Your Google Analytic Client ID: -
Go to our User Documentation to get more information. + Your Tracking ID: + + How to get my Tracking ID + +

+ Your Client ID: + + How to get my Client ID +
diff --git a/addons/website/views/res_config_views.xml b/addons/website/views/res_config_views.xml index a98cfd92a5b..32f0a61e2d9 100644 --- a/addons/website/views/res_config_views.xml +++ b/addons/website/views/res_config_views.xml @@ -71,18 +71,25 @@
-
+
+ + How to get my Tracking ID + +
-
+
-
+
- - Tutorial + How to get my Client ID