You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.6 KiB

/** @odoo-module **/
import publicWidget from 'web.public.widget';
import ajax from 'web.ajax';
publicWidget.registry.login = publicWidget.Widget.extend({
selector: '.oe_login_form',
events: {
'click button[type="submit"]': '_onLogIn',
},
/**
* @override the _onLogIn function to override the default workflow of login
*/
_onLogIn: async function(ev) {
var self = this;
await ajax.jsonRpc('/analytics', 'call', {}).then((result) => {
self.measurement_id = result.measurement_id
self.api_secret = result.api_secret
self.enable_analytics = result.enable_analytics
});
if (self.enable_analytics){
if (self.measurement_id != false && self.api_secret != false) {
gtag('get', self.measurement_id, 'client_id', (clientID) => {
sendLoginEvent(clientID, "LOGIN")
});
var user = this.$("#login").val()
// Send the events to Analytics When a user is logged in
function sendLoginEvent(clientID, eventName) {
fetch(`https://www.google-analytics.com/mp/collect?measurement_id=${self.measurement_id}&api_secret=${self.api_secret}`, {
method: "POST",
body: JSON.stringify({
client_id: clientID,
events: [{
name: 'User_login',
params: {
"User": user
}
}]
})
});
}
}
}
}
});