[IMP] website: Restructure the 'Google Analytics' wizard.

* Set the blocking warning if the user enters a 'Client ID' without
   any 'Tracking ID'.
 * 'Google Analytics in Dashboard' field is visible only if
   'Google Analytics' is checked in website settings.
 * Get/Set the value of 'google_analytics_key' and
   'google_management_client_id' from 'website' model instead of
   'ir.config_parameter' on 'Google Analytics' wizard.
 * If ID is set on 'Google Analytics' wizard then activated the related
 features and populate fields in website settings.
This commit is contained in:
Hiral Bhavsar
2017-06-19 17:37:38 +02:00
committed by Yannick Tivisse
parent e331c0bd19
commit 100ab909e6
5 changed files with 61 additions and 25 deletions
+16 -12
View File
@@ -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
+13
View File
@@ -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()
@@ -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) {
@@ -92,8 +92,15 @@
</div>
<div t-name="website.ga_dialog_content">
Your Google Analytic Client ID: <input type="text" name="ga_client_id" t-att-value="ga_key" style="width: 100%"></input>
<br/>Go to our <a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics.html" target="_blank">User Documentation</a> to get more information.
Your Tracking ID: <input type="text" name="ga_analytics_key" placeholder="UA-XXXXXXXX-Y" t-att-value="ga_analytics_key" style="width: 100%"></input>
<a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics_dashboard.html" class="oe_link fa fa-arrow-right" target="_blank">
How to get my Tracking ID
</a>
<br/><br/>
Your Client ID: <input type="text" name="ga_client_id" t-att-value="ga_key" style="width: 100%"></input>
<a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics_dashboard.html" class="oe_link fa fa-arrow-right" target="_blank">
How to get my Client ID
</a>
</div>
<t t-name="website.DateRangeButtons">
+13 -6
View File
@@ -71,18 +71,25 @@
</div>
<div class="content-group" attrs="{'invisible': [('has_google_analytics', '=', False)]}">
<div class="row mt16">
<label class="col-md-3 o_light_label" string="Analytics Key" for="google_analytics_key"/>
<field name="google_analytics_key" placeholder="UA-XXXXXXXX-Y"/>
<label class="col-md-3 o_light_label" string="Tracking ID" for="google_analytics_key"/>
<field name="google_analytics_key" placeholder="UA-XXXXXXXX-Y"
attrs="{'required': [('google_management_client_id', '!=', False)]}"/>
</div>
</div>
<div attrs="{'invisible': [('has_google_analytics', '=', False)]}">
<a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics_dashboard.html"
class="oe_link fa fa-arrow-right" target="_blank">
How to get my Tracking ID
</a>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 o_setting_box" id="google_analytics_dashboard_setting">
<div class="o_setting_left_pane">
<div class="o_setting_left_pane" attrs="{'invisible': [('has_google_analytics', '=', False)]}">
<field name="has_google_analytics_dashboard"/>
</div>
<div class="o_setting_right_pane">
<div class="o_setting_right_pane" attrs="{'invisible': [('has_google_analytics', '=', False)]}">
<label for="has_google_analytics_dashboard"/>
<div class="text-muted">
See Google Analytics data on your Website Dashboard
@@ -98,9 +105,9 @@
</div>
</div>
<div attrs="{'invisible': [('has_google_analytics_dashboard', '=', False)]}">
<a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics.html"
<a href="https://www.odoo.com/documentation/user/online/website/optimize/google_analytics_dashboard.html"
class="oe_link fa fa-arrow-right" target="_blank">
Tutorial
How to get my Client ID
</a>
</div>
</div>