-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD]facebook_pixel_tracking: new module
- Loading branch information
Showing
15 changed files
with
395 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 @@ | ||
from . import models |
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,41 @@ | ||
############################################################################## | ||
# | ||
# 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': 'Facebook Pixel Tracking', | ||
'category': 'website', | ||
'version': "16.0.1.0.0", | ||
'author': 'ADHOC SA', | ||
'website': 'www.adhoc.com.ar', | ||
'license': 'AGPL-3', | ||
'depends': [ | ||
'website_sale_advanced_tracking', | ||
], | ||
'data': [ | ||
'views/res_config_settings_view.xml', | ||
'views/website_templates.xml', | ||
], | ||
'assets':{ | ||
'web.assets_frontend': [ | ||
'facebook_pixel_tracking/static/src/js/website_sale_tracking.js', | ||
'facebook_pixel_tracking/static/src/js/website_user_tracking.js' | ||
], | ||
}, | ||
'installable': True, | ||
} |
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,2 @@ | ||
from . import res_config_settings | ||
from . import website |
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,9 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
facebook_pixel_key = fields.Char( | ||
"Facebook pixel ID", related="website_id.facebook_pixel_key", readonly=False | ||
) |
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,7 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class Website(models.Model): | ||
_inherit = "website" | ||
|
||
facebook_pixel_key = fields.Char("Facebook pixel ID") |
84 changes: 84 additions & 0 deletions
84
facebook_pixel_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,84 @@ | ||
odoo.define("facebook_pixel_tracking.tracking", function (require) { | ||
"use strict"; | ||
|
||
var publicWidget = require("web.public.widget"); | ||
|
||
const PaymentCheckoutForm = publicWidget.registry.PaymentCheckoutForm; | ||
|
||
publicWidget.registry.FacebookPixelTracking = 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 (event, dict){ | ||
if(typeof(fbq) !== 'undefined'){ | ||
fbq('track', event, dict); | ||
console.log(dict); | ||
} | ||
}, | ||
_onClickAddToCartProduct: function (ev){ | ||
var dataTarget = ev.target.closest('a#add_to_cart'); | ||
var product_id = dataTarget.dataset.product_id; | ||
var product_name = dataTarget.dataset.product_name; | ||
var product_price = dataTarget.dataset.product_price; | ||
var product_amount = $("[name=add_qty]").val(); | ||
var amount = parseFloat(product_price * product_amount).toFixed(2); | ||
const dict = { | ||
'content_name': product_name, | ||
'content_ids': [product_id], | ||
'content_type': 'product', | ||
'value': product_price, | ||
'total': amount, | ||
} | ||
this._pushInfo('AddToCart', 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 = { | ||
'content_name': product_name, | ||
'content_ids': [product_sku || product_id], | ||
'content_type': 'product', | ||
'value': product_price, | ||
} | ||
this._pushInfo('AddToCart', dict); | ||
}, | ||
_onCheckoutStartJs: function () { | ||
var dataTarget = $("#cart_products")[0]; | ||
const info = dataTarget.dataset.cart_info; | ||
const dict = { | ||
'event':'begin_checkout', | ||
'ecommerce':{'items':info} | ||
} | ||
this._pushInfo('OnCheckoutStart', dict); | ||
}, | ||
}); | ||
|
||
PaymentCheckoutForm.include({ | ||
|
||
_pushInfo: function (event, dict){ | ||
if(typeof(fbq) !== 'undefined'){ | ||
fbq('track', event, dict); | ||
} | ||
}, | ||
|
||
// @override | ||
_onClickPay: async function (ev) { | ||
const info = $(".toggle_summary_div")[0].dataset.purchase_info; | ||
const dict = { | ||
'event':'purchase', | ||
'ecommerce':info | ||
} | ||
this._pushInfo('OnPurchaseConfirm', dict); | ||
this._super(...arguments); | ||
}, | ||
}) | ||
|
||
return publicWidget.registry.FacebookPixelTracking; | ||
}); |
27 changes: 27 additions & 0 deletions
27
facebook_pixel_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("facebook_pixel_tracking.user_tracking", function (require) { | ||
"use strict"; | ||
|
||
var publicWidget = require("web.public.widget"); | ||
|
||
publicWidget.registry.FacebookPixelTrackingUser = publicWidget.Widget.extend({ | ||
selector: '.oe_website_login_container', | ||
events: { | ||
"click button.on_user_signup": "_onUserSignup", | ||
}, | ||
|
||
_pushInfo: function (event, dict){ | ||
if(typeof(fbq) !== 'undefined'){ | ||
fbq('track', event, dict); | ||
console.log(dict); | ||
} | ||
}, | ||
_onUserSignup: function () { | ||
const user_email = $("#login").val(); | ||
const dict = { | ||
'user_email':user_email, | ||
} | ||
this._pushInfo('user_signup', dict); | ||
}, | ||
}); | ||
return publicWidget.registry.FacebookPixelTrackingUser; | ||
}); |
52 changes: 52 additions & 0 deletions
52
facebook_pixel_tracking/views/res_config_settings_view.xml
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,52 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="view_website_config_settings" model="ir.ui.view"> | ||
<field name="name">Facebook Pixel Tracking</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="website.res_config_settings_view_form" /> | ||
<field name="arch" type="xml"> | ||
<div id="plausbile_setting" position="after"> | ||
<div | ||
class="col-xs-12 col-lg-6 o_setting_box" | ||
id="facebook_pixel_tracking_setting" | ||
> | ||
<div class="o_setting_right_pane"> | ||
<label | ||
for="facebook_pixel_key" | ||
string="Facebook Pixel" | ||
/> | ||
<span | ||
class="fa fa-lg fa-globe" | ||
title="Values set here are website-specific." | ||
groups="website.group_multi_website" | ||
/> | ||
<div class="text-muted"> | ||
Manage Facebook Pixel without editing code. | ||
</div> | ||
<div class="content-group"> | ||
<div class="row mt16"> | ||
<label | ||
class="col-lg-4 o_light_label" | ||
for="facebook_pixel_key" | ||
/> | ||
<field | ||
name="facebook_pixel_key" | ||
placeholder="1234567890" | ||
/> | ||
</div> | ||
</div> | ||
<div> | ||
<a | ||
href="https://es-la.facebook.com/business/help/952192354843755?id=1205376682832142" | ||
class="oe_link fa fa-arrow-right" | ||
target="_blank" | ||
> | ||
Como obtengo mi codigo pixel | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</field> | ||
</record> | ||
</odoo> |
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,34 @@ | ||
<odoo> | ||
<template id="layout" inherit_id="website.layout"> | ||
|
||
</template> | ||
<template id="web_layout" inherit_id="website.layout"> | ||
<xpath expr="//meta[@name='generator']" position="before"> | ||
<t t-if="website and website.facebook_pixel_key"> | ||
<t t-set="pixel_key" t-value="website.facebook_pixel_key"/> | ||
<!-- Facebook Pixel Code --> | ||
<script | ||
type="text/javascript" | ||
> | ||
!function(f,b,e,v,n,t,s) | ||
{if(f.fbq)return;n=f.fbq=function(){n.callMethod? | ||
n.callMethod.apply(n,arguments):n.queue.push(arguments)}; | ||
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; | ||
n.queue=[];t=b.createElement(e);t.async=!0; | ||
t.src=v;s=b.getElementsByTagName(e)[0]; | ||
s.parentNode.insertBefore(t,s)}(window, document,'script', | ||
'https://connect.facebook.net/en_US/fbevents.js'); | ||
fbq('init', '<t | ||
t-esc="website.facebook_pixel_key" | ||
/>'); | ||
fbq('track', 'PageView'); | ||
</script> | ||
<noscript> | ||
<img height="1" width="1" style="display:none" | ||
t-att-src="'https://www.facebook.com/tr?id=%s&ev=PageView&noscript=1' % (website.facebook_pixel_key)"/> | ||
</noscript> | ||
<!-- End Facebook Pixel Code --> | ||
</t> | ||
</xpath> | ||
</template> | ||
</odoo> |
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 @@ | ||
from . import models |
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,34 @@ | ||
############################################################################## | ||
# | ||
# 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': 'Website Sale Advanced Tracking', | ||
'category': 'website', | ||
'version': "16.0.1.0.0", | ||
'author': 'ADHOC SA', | ||
'website': 'www.adhoc.com.ar', | ||
'license': 'AGPL-3', | ||
'depends': [ | ||
'website_sale', | ||
], | ||
'data': [ | ||
'views/templates.xml', | ||
], | ||
'installable': True, | ||
} |
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,2 @@ | ||
from . import sale_order | ||
from . import sale_order_line |
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,30 @@ | ||
from odoo import models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
def prepare_purchase_information(self): | ||
products = [] | ||
for line in self.order_line: | ||
products.append( | ||
{ | ||
"id": line.product_id.default_code or line.product_id.id, | ||
"name": line.product_id.name, | ||
"category": line.product_id.categ_id.name, | ||
"quantity": line.product_uom_qty, | ||
"price": line.price_subtotal, | ||
} | ||
) | ||
res = { | ||
'purchase': { | ||
'actionField': { | ||
'id': self.id, | ||
'affiliation': self.partner_id.name, | ||
'revenue': self.amount_total, | ||
'tax':self.amount_tax, | ||
}, | ||
'products': products | ||
} | ||
} | ||
return res |
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,18 @@ | ||
from odoo import models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = 'sale.order.line' | ||
|
||
def prepare_checkout_information(self): | ||
res = [] | ||
for line in self: | ||
res.append( | ||
{ | ||
'item_name': line.name, | ||
'item_id': line.product_id.default_code or line.product_id.id, | ||
'price': (line.price_reduce_taxinc / line.product_uom_qty), | ||
'quantity': line.product_uom_qty | ||
} | ||
) | ||
return res |
Oops, something went wrong.