-
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
12 changed files
with
338 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,42 @@ | ||
############################################################################## | ||
# | ||
# 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', | ||
], | ||
'data': [ | ||
'views/res_config_settings_view.xml', | ||
'views/website_templates.xml', | ||
'views/templates.xml', | ||
], | ||
'assets':{ | ||
'web.assets_frontend': [ | ||
'facebook_pixel_tracking/src/js/website_sale_tracking.js', | ||
'facebook_pixel_tracking/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,4 @@ | ||
from . import res_config_settings | ||
from . import website | ||
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,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,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 |
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") |
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,67 @@ | ||
odoo.define("facebook_pixel_tracking.tracking", function (require) { | ||
"use strict"; | ||
|
||
const publicWidget = require("web.public.widget"); | ||
|
||
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", | ||
"click button.on_purchase_confirm": "_onPurchaseConfirm", | ||
}, | ||
|
||
_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 = { | ||
'content_name': product_name, | ||
'content_ids': [product_id], | ||
'content_type': 'product', | ||
'value': product_price, | ||
} | ||
console.log(dict) | ||
fbq('track', '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, | ||
} | ||
console.log(dict) | ||
fbq('track', 'AddToCart', dict); | ||
}, | ||
_onCheckoutStartJs: function () { | ||
var dataTarget = $("#cart_products")[0]; | ||
const info = dataTarget.dataset.cart_info; | ||
const dict = { | ||
'event':'begin_checkout', | ||
'ecommerce':{'items':info} | ||
} | ||
console.log(dict); | ||
fbq('track', 'OnCheckoutStart', dict); | ||
}, | ||
_onPurchaseConfirm: function () { | ||
const info = $(".toggle_summary_div")[0].dataset.purchase_info; | ||
const dict = { | ||
'event':'purchase', | ||
'ecommerce':info | ||
} | ||
console.log(dict); | ||
fbq('track', 'OnPurchaseConfirm', dict); | ||
}, | ||
}); | ||
|
||
return publicWidget.registry.FacebookPixelTracking; | ||
}); |
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,21 @@ | ||
odoo.define("facebook_pixel_tracking.user_tracking", function (require) { | ||
"use strict"; | ||
|
||
const publicWidget = require("web.public.widget"); | ||
|
||
publicWidget.registry.FacebookPixelTracking = publicWidget.Widget.extend({ | ||
selector: '.oe_website_login_container', | ||
events: { | ||
"click button.on_user_signup": "_onUserSignup", | ||
}, | ||
_onUserSignup: function () { | ||
const user_email = $("#login").val() | ||
console.log(user_email); | ||
const dict = { | ||
'user_email':user_email, | ||
} | ||
fbq('track', 'user_signup', dict) | ||
}, | ||
}); | ||
return publicWidget.registry.FacebookPixelTracking; | ||
}); |
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,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="product" inherit_id="website_sale.product"> | ||
<xpath expr="//a[@id='add_to_cart']" position="attributes"> | ||
<attribute name="t-att-data-product_id">product.id</attribute> | ||
<attribute name="t-att-data-product_name">product.name</attribute> | ||
<attribute name="t-att-data-product_price">combination_info['base_unit_price']</attribute> | ||
</xpath> | ||
</template> | ||
<template id="products_item" inherit_id="website_sale.products_item"> | ||
<xpath expr="//div[hasclass('o_wsale_product_btn')]" position="attributes"> | ||
<attribute name="t-att-data-product_id">product.id</attribute> | ||
<attribute name="t-att-data-product_sku">product.default_code</attribute> | ||
<attribute name="t-att-data-product_name">product.name</attribute> | ||
<attribute name="t-att-data-product_price">template_price_vals['price_reduce']</attribute> | ||
</xpath> | ||
</template> | ||
<template id="products_add_to_cart" inherit_id="website_sale.products_add_to_cart"> | ||
<xpath expr="//a[hasclass('a-submit')]" position="attributes"> | ||
<attribute name="class" add="add_to_cart_products_item" separator=" " /> | ||
</xpath> | ||
</template> | ||
<template id="short_cart_summary" inherit_id="website_sale.short_cart_summary"> | ||
<xpath expr="//a[@t-if='website_sale_order and website_sale_order.website_order_line']" position="attributes"> | ||
<attribute name="class" add="on_checkout_start_js" separator=" " /> | ||
</xpath> | ||
</template> | ||
<template id="cart" inherit_id="website_sale.cart"> | ||
<xpath expr="//div[@t-if='website_sale_order and website_sale_order.website_order_line']/a" position="attributes"> | ||
<attribute name="class" add="on_checkout_start_js" separator=" " /> | ||
</xpath> | ||
</template> | ||
<template id="cart_lines" inherit_id="website_sale.cart_lines"> | ||
<xpath expr="//table" position="attributes"> | ||
<attribute name="t-att-data-cart_info">website_sale_order.website_order_line.prepare_checkout_information()</attribute> | ||
</xpath> | ||
</template> | ||
<template id="payment_footer" inherit_id="website_sale.payment_footer"> | ||
<xpath expr="//button" position="attributes"> | ||
<attribute name="class" add="on_purchase_confirm" separator=" " /> | ||
</xpath> | ||
</template> | ||
<template id="cart_summary" inherit_id="website_sale.cart_summary"> | ||
<xpath expr="//div[hasclass('toggle_summary_div')]" position="attributes"> | ||
<attribute name="t-att-data-purchase_info">website_sale_order.prepare_purchase_information()</attribute> | ||
</xpath> | ||
</template> | ||
<template id="signup" inherit_id="auth_signup.signup"> | ||
<xpath expr="//button" position="attributes"> | ||
<attribute name="class" add="on_user_signup" separator=" " /> | ||
</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,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" | ||
src="`https://www.facebook.com/tr?id={${pixel_key}}&ev=PageView&noscript=1`"/> | ||
</noscript> | ||
<!-- End Facebook Pixel Code --> | ||
</t> | ||
</xpath> | ||
</template> | ||
</odoo> |