Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD]google_tag_manager_advanced_tracking: new module
- Loading branch information
Showing
3 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
############################################################################## | ||
# | ||
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar) | ||
# All Rights Reserved. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
{ | ||
'name': 'Google Tag Manager Advanced Tracking', | ||
'category': 'Website', | ||
'version': "16.0.1.0.0", | ||
'author': 'ADHOC SA', | ||
'website': 'www.adhoc.com.ar', | ||
'license': 'AGPL-3', | ||
'depends': [ | ||
'website_google_tag_manager', | ||
'website_sale_advanced_tracking', | ||
], | ||
'data': [], | ||
'assets':{ | ||
'web.assets_frontend': [ | ||
'google_tag_manager_advanced_tracking/static/src/js/website_sale_tracking.js', | ||
'google_tag_manager_advanced_tracking/static/src/js/website_user_tracking.js' | ||
], | ||
}, | ||
'installable': True, | ||
} |
88 changes: 88 additions & 0 deletions
88
google_tag_manager_advanced_tracking/static/src/js/website_sale_tracking.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
odoo.define("google_tag_manager_advanced_tracking.tracking", function (require) { | ||
"use strict"; | ||
|
||
const publicWidget = require("web.public.widget"); | ||
|
||
const PaymentCheckoutForm = publicWidget.registry.PaymentCheckoutForm; | ||
|
||
publicWidget.registry.GoogleTagManagerAdvancedTracking = publicWidget.Widget.extend({ | ||
selector: '.oe_website_sale', | ||
events: { | ||
'click #add_to_cart': '_onClickAddToCartProduct', | ||
'click a.add_to_cart_products_item': '_onClickAddToCartProductsItem', | ||
'click a.on_checkout_start_js': '_onCheckoutStartJs', | ||
}, | ||
|
||
_pushInfo: function (dict){ | ||
if(typeof(dataLayer) !== 'undefined'){ | ||
dataLayer.push(dict) | ||
console.log(dict) | ||
} | ||
}, | ||
_onClickAddToCartProduct: function (ev){ | ||
var product_id = ev.target.dataset.product_id; | ||
var product_name = ev.target.dataset.product_name; | ||
var product_price = ev.target.dataset.product_price; | ||
var product_amount = $("[name=add_qty]").val(); | ||
var amount = parseFloat(product_price * product_amount) | ||
const dict = { | ||
'event': 'add_to_cart', | ||
'value': amount, | ||
'items': [{ | ||
'item_name': product_name, | ||
'item_id': product_id, | ||
'price': product_price | ||
}] | ||
} | ||
this._pushInfo(dict); | ||
}, | ||
_onClickAddToCartProductsItem: function(ev) { | ||
var dataTarget = ev.target.closest('div.o_wsale_product_btn'); | ||
var product_id = dataTarget.dataset.product_id; | ||
var product_sku = dataTarget.dataset.product_sku; | ||
var product_name = dataTarget.dataset.product_name; | ||
var product_price = dataTarget.dataset.product_price; | ||
const dict = { | ||
'event': 'add_to_cart', | ||
'value': product_price, | ||
'items': { | ||
'item_name': product_name, | ||
'item_id': product_sku || product_id, | ||
'price': product_price | ||
} | ||
} | ||
this._pushInfo(dict); | ||
}, | ||
_onCheckoutStartJs: function () { | ||
var dataTarget = $("#cart_products")[0]; | ||
const info = dataTarget.dataset.cart_info; | ||
const dict = { | ||
'event':'begin_checkout', | ||
'ecommerce':{'items':info} | ||
} | ||
this._pushInfo(dict); | ||
}, | ||
}); | ||
|
||
//Heredamos payment checkout form porque el metodo _onClickPay tiene stopPropagation y preventDefault, impidiendonos hacerlo en el widget GoogleTagManagerAdvancedTracking | ||
PaymentCheckoutForm.include({ | ||
_pushInfo: function (dict){ | ||
if(typeof(dataLayer) !== 'undefined'){ | ||
dataLayer.push(dict) | ||
} | ||
}, | ||
// @override | ||
_onClickPay: async function (ev) { | ||
const info = $(".toggle_summary_div")[0].dataset.purchase_info; | ||
const dict = { | ||
'event':'purchase', | ||
'ecommerce':info | ||
} | ||
this._pushInfo(dict); | ||
|
||
this._super(...arguments) | ||
}, | ||
}) | ||
|
||
return publicWidget.registry.GoogleTagManagerAdvancedTracking; | ||
}); |
27 changes: 27 additions & 0 deletions
27
google_tag_manager_advanced_tracking/static/src/js/website_user_tracking.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
odoo.define("google_tag_manager_advanced_tracking.user_tracking", function (require) { | ||
"use strict"; | ||
|
||
const publicWidget = require("web.public.widget"); | ||
|
||
publicWidget.registry.GoogleTagManagerUserAdvancedTracking = publicWidget.Widget.extend({ | ||
selector: '.oe_website_login_container', | ||
events: { | ||
"click button.on_user_signup": "_onUserSignup", | ||
}, | ||
_pushInfo: function (dict){ | ||
if(typeof(dataLayer) !== 'undefined'){ | ||
dataLayer.push(dict) | ||
console.log(dict) | ||
} | ||
}, | ||
_onUserSignup: function () { | ||
const user_email = $("#login").val() | ||
const dict = { | ||
'event':'user_signup', | ||
'user_email':user_email, | ||
} | ||
this._pushInfo(dict) | ||
}, | ||
}); | ||
return publicWidget.registry.GoogleTagManagerUserAdvancedTracking; | ||
}); |