Apptrian_Facebook_Pixel - Version 1.1.0

Version Notes

+ Facebook Dynamic Ads code
+ Compliance with Magento's Extension Quality Program (EQP)

Download this release

Release Info

Developer Apptrian
Extension Apptrian_Facebook_Pixel
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.0.0 to 1.1.0

app/code/community/Apptrian/FacebookPixel/Block/Adminhtml/About.php CHANGED
@@ -10,7 +10,6 @@ class Apptrian_FacebookPixel_Block_Adminhtml_About
10
  extends Mage_Adminhtml_Block_Abstract
11
  implements Varien_Data_Form_Element_Renderer_Interface
12
  {
13
-
14
  /**
15
  * Render fieldset html
16
  *
@@ -29,7 +28,7 @@ border:1px solid #ccc; min-height:100px; margin:5px 0;
29
  padding:15px 15px 15px 140px;">
30
  <p>
31
  <strong>Apptrian Facebook Pixel Extension v$version</strong><br />
32
- Adds Facebook Pixel with standard events on appropriate pages. Passes W3C
33
  validation. Easy to install and use.
34
  </p>
35
  <p>
10
  extends Mage_Adminhtml_Block_Abstract
11
  implements Varien_Data_Form_Element_Renderer_Interface
12
  {
 
13
  /**
14
  * Render fieldset html
15
  *
28
  padding:15px 15px 15px 140px;">
29
  <p>
30
  <strong>Apptrian Facebook Pixel Extension v$version</strong><br />
31
+ Adds Facebook Pixel with Dynamic Ads code on appropriate pages. Passes W3C
32
  validation. Easy to install and use.
33
  </p>
34
  <p>
app/code/community/Apptrian/FacebookPixel/Block/Adminhtml/Info.php CHANGED
@@ -10,7 +10,6 @@ class Apptrian_FacebookPixel_Block_Adminhtml_Info
10
  extends Mage_Adminhtml_Block_Abstract
11
  implements Varien_Data_Form_Element_Renderer_Interface
12
  {
13
-
14
  /**
15
  * Render fieldset html
16
  *
@@ -22,71 +21,76 @@ class Apptrian_FacebookPixel_Block_Adminhtml_Info
22
  $element = null;
23
  $logopath = 'http://www.apptrian.com/media/apptrian.gif';
24
  $html = <<<HTML
25
- <div style="background:url('$logopath') no-repeat scroll 15px 15px #e7efef;
26
- border:1px solid #ccc; min-height:100px; margin:5px 0;
27
  padding:15px 15px 15px 140px;">
28
  <p>
29
  <strong>Magento Online Stores &amp; Extensions</strong><br />
30
- <a href="http://www.apptrian.com" target="_blank">Apptrian</a> offers a wide
31
  choice of products and services for your online business.
32
  </p>
33
  <p>
34
  Website: <a href="http://www.apptrian.com" target="_blank">www.apptrian.com</a>
35
  <br />
36
- Like, share and follow us on
37
- <a href="https://www.facebook.com/apptrian" target="_blank">Facebook</a>,
38
- <a href="https://plus.google.com/+ApptrianCom" target="_blank">Google+</a>,
39
- <a href="http://www.pinterest.com/apptrian" target="_blank">Pinterest</a>, and
40
  <a href="http://twitter.com/apptrian" target="_blank">Twitter</a>.<br />
41
- If you have any questions send email at
42
  <a href="mailto:service@apptrian.com">service@apptrian.com</a>.
43
  </p>
44
  </div>
45
  <div>
46
  <p><strong>Products and services you might be interested in:</strong></p>
47
- <a href="http://www.apptrian.com/image-optimizer-for-magento"
48
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
49
- <img src="http://www.apptrian.com/media/image-optimizer.jpg"
 
 
 
 
 
50
  alt="Image Optimizer" style="border:1px solid #ccc;" />
51
  </a>
52
- <a href="http://www.apptrian.com/minify-html-css-js-for-magento"
53
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
54
- <img src="http://www.apptrian.com/media/minify-html-css-js.jpg"
55
  alt="Minify HTML CSS JS" style="border:1px solid #ccc;" />
56
  </a>
57
- <a href="http://www.apptrian.com/professional-magento-installation"
58
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
59
- <img src="http://www.apptrian.com/media/professional-magento-installation.jpg"
60
  alt="Professional Magento Installation" style="border:1px solid #ccc;" />
61
  </a>
62
- <a href="http://www.apptrian.com/quick-search-for-magento"
63
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
64
- <img src="http://www.apptrian.com/media/quick-search.jpg"
65
  alt="Quick Search" style="border:1px solid #ccc;" />
66
  </a>
67
- <a href="http://www.apptrian.com/responsive-product-slider-for-magento"
68
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
69
- <img src="http://www.apptrian.com/media/responsive-product-slider.jpg"
70
  alt="Responsive Product Slider" style="border:1px solid #ccc;" />
71
  </a>
72
- <a href="http://www.apptrian.com/schema-org-microdata-for-magento"
73
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
74
- <img src="http://www.apptrian.com/media/schema-org-microdata-for-magento.jpg"
75
  alt="Schema.org Microdata for Magento" style="border:1px solid #ccc;" />
76
  </a>
77
- <a href="http://www.apptrian.com/snippets-generator-for-magento"
78
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
79
- <img src="http://www.apptrian.com/media/snippets-generator.jpg"
80
  alt="Snippets Generator" style="border:1px solid #ccc;" />
81
  </a>
82
- <a href="http://www.apptrian.com/social-integrator-for-magento"
83
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
84
- <img src="http://www.apptrian.com/media/social-integrator.jpg"
85
  alt="Social Integrator" style="border:1px solid #ccc;" />
86
  </a>
87
- <a href="http://www.apptrian.com/subcategories-grid-list-for-magento"
88
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
89
- <img src="http://www.apptrian.com/media/subcategories-grid-list.jpg"
90
  alt="Subcategories Grid/List" style="border:1px solid #ccc;" />
91
  </a>
92
  </div>
10
  extends Mage_Adminhtml_Block_Abstract
11
  implements Varien_Data_Form_Element_Renderer_Interface
12
  {
 
13
  /**
14
  * Render fieldset html
15
  *
21
  $element = null;
22
  $logopath = 'http://www.apptrian.com/media/apptrian.gif';
23
  $html = <<<HTML
24
+ <div style="background:url('$logopath') no-repeat scroll 15px 15px #e7efef;
25
+ border:1px solid #ccc; min-height:100px; margin:5px 0;
26
  padding:15px 15px 15px 140px;">
27
  <p>
28
  <strong>Magento Online Stores &amp; Extensions</strong><br />
29
+ <a href="http://www.apptrian.com" target="_blank">Apptrian</a> offers a wide
30
  choice of products and services for your online business.
31
  </p>
32
  <p>
33
  Website: <a href="http://www.apptrian.com" target="_blank">www.apptrian.com</a>
34
  <br />
35
+ Like, share and follow us on
36
+ <a href="https://www.facebook.com/apptrian" target="_blank">Facebook</a>,
37
+ <a href="https://plus.google.com/+ApptrianCom" target="_blank">Google+</a>,
38
+ <a href="http://www.pinterest.com/apptrian" target="_blank">Pinterest</a>, and
39
  <a href="http://twitter.com/apptrian" target="_blank">Twitter</a>.<br />
40
+ If you have any questions send email at
41
  <a href="mailto:service@apptrian.com">service@apptrian.com</a>.
42
  </p>
43
  </div>
44
  <div>
45
  <p><strong>Products and services you might be interested in:</strong></p>
46
+ <a href="http://www.apptrian.com/facebook-pixel-for-magento"
47
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
48
+ <img src="http://www.apptrian.com/media/facebook-pixel.jpg"
49
+ alt="Facebook Pixel" style="border:1px solid #ccc;" />
50
+ </a>
51
+ <a href="http://www.apptrian.com/image-optimizer-for-magento"
52
+ target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
53
+ <img src="http://www.apptrian.com/media/image-optimizer.jpg"
54
  alt="Image Optimizer" style="border:1px solid #ccc;" />
55
  </a>
56
+ <a href="http://www.apptrian.com/minify-html-css-js-for-magento"
57
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
58
+ <img src="http://www.apptrian.com/media/minify-html-css-js.jpg"
59
  alt="Minify HTML CSS JS" style="border:1px solid #ccc;" />
60
  </a>
61
+ <a href="http://www.apptrian.com/professional-magento-installation"
62
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
63
+ <img src="http://www.apptrian.com/media/professional-magento-installation.jpg"
64
  alt="Professional Magento Installation" style="border:1px solid #ccc;" />
65
  </a>
66
+ <a href="http://www.apptrian.com/quick-search-for-magento"
67
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
68
+ <img src="http://www.apptrian.com/media/quick-search.jpg"
69
  alt="Quick Search" style="border:1px solid #ccc;" />
70
  </a>
71
+ <a href="http://www.apptrian.com/responsive-product-slider-for-magento"
72
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
73
+ <img src="http://www.apptrian.com/media/responsive-product-slider.jpg"
74
  alt="Responsive Product Slider" style="border:1px solid #ccc;" />
75
  </a>
76
+ <a href="http://www.apptrian.com/schema-org-microdata-for-magento"
77
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
78
+ <img src="http://www.apptrian.com/media/schema-org-microdata-for-magento.jpg"
79
  alt="Schema.org Microdata for Magento" style="border:1px solid #ccc;" />
80
  </a>
81
+ <a href="http://www.apptrian.com/snippets-generator-for-magento"
82
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
83
+ <img src="http://www.apptrian.com/media/snippets-generator.jpg"
84
  alt="Snippets Generator" style="border:1px solid #ccc;" />
85
  </a>
86
+ <a href="http://www.apptrian.com/social-integrator-for-magento"
87
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
88
+ <img src="http://www.apptrian.com/media/social-integrator.jpg"
89
  alt="Social Integrator" style="border:1px solid #ccc;" />
90
  </a>
91
+ <a href="http://www.apptrian.com/subcategories-grid-list-for-magento"
92
  target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
93
+ <img src="http://www.apptrian.com/media/subcategories-grid-list.jpg"
94
  alt="Subcategories Grid/List" style="border:1px solid #ccc;" />
95
  </a>
96
  </div>
app/code/community/Apptrian/FacebookPixel/Block/Code.php CHANGED
@@ -28,4 +28,153 @@ class Apptrian_FacebookPixel_Block_Code extends Mage_Core_Block_Template
28
  return $data;
29
  }
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
28
  return $data;
29
  }
30
 
31
+ /**
32
+ * Returns product data needed for dynamic ads tracking.
33
+ *
34
+ * @return array
35
+ */
36
+ public function getProductData()
37
+ {
38
+ $p = Mage::registry('current_product');
39
+
40
+ $data = array();
41
+
42
+ $data['content_name'] = $this->escapeSingleQuotes($p->getName());
43
+ $data['content_ids'] = $this->escapeSingleQuotes($p->getSku());
44
+ $data['content_type'] = 'product';
45
+ $data['value'] = number_format(
46
+ $this->getCalculatedPrice(), 2, '.', ''
47
+ );
48
+ $data['currency'] = $this->getCurrencyCode();
49
+
50
+ return $data;
51
+
52
+ }
53
+
54
+ /**
55
+ * Returns data needed for purchase tracking.
56
+ *
57
+ * @return array|null
58
+ */
59
+ public function getOrderData()
60
+ {
61
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
62
+
63
+ if ($orderId) {
64
+ $order = Mage::getModel('sales/order')->load($orderId);
65
+
66
+ $items = array();
67
+
68
+ foreach ($order->getAllVisibleItems() as $item) {
69
+ $items[] = array(
70
+ 'name' => $item->getName(), 'sku' => $item->getSku()
71
+ );
72
+ }
73
+
74
+ $data = array();
75
+
76
+ if (count($items) === 1) {
77
+ $data['content_name'] = $this->escapeSingleQuotes(
78
+ $items[0]['name']
79
+ );
80
+ }
81
+
82
+ $ids = '';
83
+ foreach ($items as $i) {
84
+ $ids .= "'" . $this->escapeSingleQuotes($i['sku']) . "', ";
85
+ }
86
+
87
+ $data['content_ids'] = trim($ids, ", ");
88
+ $data['content_type'] = 'product';
89
+ $data['value'] = number_format(
90
+ $order->getGrandTotal(), 2, '.', ''
91
+ );
92
+ $data['currency'] = $order->getOrderCurrencyCode();
93
+
94
+ return $data;
95
+ } else {
96
+ return null;
97
+ }
98
+
99
+ }
100
+
101
+ /**
102
+ * Returns product calculated price depending option selected in
103
+ * Stores > Cofiguration > Sales > Tax > Price Display Settings
104
+ * If "Excluding Tax" is selected price will not include tax.
105
+ * If "Including Tax" or "Including and Excluding Tax" is selected price
106
+ * will include tax.
107
+ *
108
+ * @return int|float|string
109
+ */
110
+ public function getCalculatedPrice()
111
+ {
112
+ $p = Mage::registry('current_product');
113
+
114
+ $productType = $p->getTypeId();
115
+
116
+ $calculatedPrice = 0;
117
+
118
+ // Tax Display
119
+ // 1 - excluding tax
120
+ // 2 - including tax
121
+ // 3 - including and excluding tax
122
+ $tax = (int) Mage::getStoreConfig('tax/display/type');
123
+
124
+ if ($productType == 'configurable') {
125
+ if ($tax === 1) {
126
+ $calculatedPrice = $p->getFinalPrice();
127
+ } else {
128
+ $calculatedPrice = Mage::helper('tax')
129
+ ->getPrice($p, $p->getFinalPrice());
130
+ }
131
+ } elseif ($productType == 'grouped') {
132
+ $associatedProducts = $p->getTypeInstance(true)
133
+ ->getAssociatedProducts($p);
134
+
135
+ $prices = array();
136
+
137
+ foreach ($associatedProducts as $associatedProduct) {
138
+ $prices[] = $associatedProduct->getPrice();
139
+ }
140
+
141
+ if (!empty($prices)) {
142
+ $calculatedPrice = min($prices);
143
+ }
144
+
145
+ // downloadable, simple, virtual
146
+ } else {
147
+ if ($tax === 1) {
148
+ $calculatedPrice = $p->getFinalPrice();
149
+ } else {
150
+ $calculatedPrice = Mage::helper('tax')
151
+ ->getPrice($p, $p->getFinalPrice());
152
+ }
153
+ }
154
+
155
+ return $calculatedPrice;
156
+
157
+ }
158
+
159
+ /**
160
+ * Returns 3 letter currency code like USD, GBP, EUR, etc.
161
+ *
162
+ * @return string
163
+ */
164
+ public function getCurrencyCode()
165
+ {
166
+ return strtoupper(Mage::app()->getStore()->getCurrentCurrencyCode());
167
+ }
168
+
169
+ /**
170
+ * Add slashes to string and prepares string for javascript.
171
+ *
172
+ * @param string $str
173
+ * @return string
174
+ */
175
+ public function escapeSingleQuotes($str)
176
+ {
177
+ return str_replace("'", "\'", $str);
178
+ }
179
+
180
  }
app/code/community/Apptrian/FacebookPixel/Model/Config/Pixelid.php CHANGED
@@ -16,9 +16,7 @@ class Apptrian_FacebookPixel_Model_Config_Pixelid
16
  $result = $this->validate();
17
 
18
  if ($result !== true) {
19
-
20
  Mage::throwException(implode("\n", $result));
21
-
22
  }
23
 
24
  return parent::_beforeSave();
16
  $result = $this->validate();
17
 
18
  if ($result !== true) {
 
19
  Mage::throwException(implode("\n", $result));
 
20
  }
21
 
22
  return parent::_beforeSave();
app/code/community/Apptrian/FacebookPixel/etc/config.xml CHANGED
@@ -11,7 +11,7 @@
11
  <config>
12
  <modules>
13
  <Apptrian_FacebookPixel>
14
- <version>1.0.0</version>
15
  </Apptrian_FacebookPixel>
16
  </modules>
17
  <global>
11
  <config>
12
  <modules>
13
  <Apptrian_FacebookPixel>
14
+ <version>1.1.0</version>
15
  </Apptrian_FacebookPixel>
16
  </modules>
17
  <global>
app/code/community/Apptrian/FacebookPixel/etc/system.xml CHANGED
@@ -43,22 +43,12 @@
43
  <show_in_website>1</show_in_website>
44
  <show_in_store>1</show_in_store>
45
  <groups>
46
- <about translate="label">
47
- <label>About</label>
48
- <frontend_type>text</frontend_type>
49
  <sort_order>1</sort_order>
50
  <show_in_default>1</show_in_default>
51
  <show_in_website>1</show_in_website>
52
  <show_in_store>1</show_in_store>
53
- <fields>
54
- <info translate="label">
55
- <frontend_model>apptrian_facebookpixel/adminhtml_about</frontend_model>
56
- <sort_order>1</sort_order>
57
- <show_in_default>1</show_in_default>
58
- <show_in_website>1</show_in_website>
59
- <show_in_store>1</show_in_store>
60
- </info>
61
- </fields>
62
  </about>
63
  <general translate="label">
64
  <label>General</label>
43
  <show_in_website>1</show_in_website>
44
  <show_in_store>1</show_in_store>
45
  <groups>
46
+ <about>
47
+ <frontend_model>apptrian_facebookpixel/adminhtml_about</frontend_model>
 
48
  <sort_order>1</sort_order>
49
  <show_in_default>1</show_in_default>
50
  <show_in_website>1</show_in_website>
51
  <show_in_store>1</show_in_store>
 
 
 
 
 
 
 
 
 
52
  </about>
53
  <general translate="label">
54
  <label>General</label>
app/design/frontend/base/default/layout/apptrian_facebookpixel.xml CHANGED
@@ -81,15 +81,6 @@
81
  </block>
82
  </reference>
83
  </customer_account_create>
84
- <checkout_cart_index>
85
- <reference name="before_body_end">
86
- <block type="apptrian_facebookpixel/code" name="apptrian.facebookpixel.cart" after="-">
87
- <action method="setTemplate" ifconfig="apptrian_facebookpixel/general/enabled">
88
- <template>apptrian/facebookpixel/code.phtml</template>
89
- </action>
90
- </block>
91
- </reference>
92
- </checkout_cart_index>
93
  <checkout_onepage_index>
94
  <reference name="before_body_end">
95
  <block type="apptrian_facebookpixel/code" name="apptrian.facebookpixel.checkout" after="-">
81
  </block>
82
  </reference>
83
  </customer_account_create>
 
 
 
 
 
 
 
 
 
84
  <checkout_onepage_index>
85
  <reference name="before_body_end">
86
  <block type="apptrian_facebookpixel/code" name="apptrian.facebookpixel.checkout" after="-">
app/design/frontend/base/default/template/apptrian/facebookpixel/code.phtml CHANGED
@@ -6,9 +6,6 @@
6
  * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
  */
9
-
10
- // @codingStandardsIgnoreFile
11
-
12
  ?>
13
  <?php
14
  /**
@@ -30,7 +27,7 @@ n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
30
  t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
31
  document,'script','https://connect.facebook.net/en_US/fbevents.js');
32
 
33
- fbq('init', '<?php echo $id ?>');
34
  fbq('track', 'PageView');
35
 
36
  <?php if ($action == 'cms_index_index'): ?>
@@ -42,29 +39,60 @@ fbq('track', 'ViewContent');
42
  || $action == 'catalog_category_layered'): ?>
43
  fbq('track', 'ViewContent');
44
  <?php elseif ($action == 'catalog_product_view'): ?>
45
- fbq('track', 'ViewContent');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  <?php elseif ($action == 'catalogsearch_result_index'
47
  || $action == 'catalogsearch_advanced_result'): ?>
48
  fbq('track', 'Search');
49
  <?php elseif ($action == 'customer_account_create'): ?>
50
  fbq('track', 'CompleteRegistration');
51
- <?php elseif ($action == 'checkout_cart_index'): ?>
52
- fbq('track', 'AddToCart');
53
  <?php elseif ($action == 'checkout_onepage_index'
54
  || $action == 'onestepcheckout_index_index'
55
  || $action == 'opc_index_index'): ?>
56
  fbq('track', 'InitiateCheckout');
57
  <?php elseif ($action == 'checkout_onepage_success'): ?>
58
- <?php
59
- $sOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
60
- if ($sOrderId != ''): ?>
61
  <?php
62
- $oOrder = Mage::getModel('sales/order')->load($sOrderId);
63
- $total = round($oOrder->getGrandTotal(), 2);
64
- $currency = $oOrder->getOrderCurrencyCode();
65
- ?>
66
- fbq('track', 'Purchase', {value: '<?php echo $total ?>', currency: '<?php echo $currency ?>'});
67
  <?php endif; ?>
 
 
 
 
 
 
 
68
  <?php elseif ($action == 'wishlist_index_index'): ?>
69
  fbq('track', 'AddToWishlist');
70
  <?php else: ?>
@@ -73,6 +101,6 @@ fbq('track', 'ViewContent');
73
 
74
  </script>
75
  <noscript><img height="1" width="1" style="display:none" alt="Facebook Pixel"
76
- src="https://www.facebook.com/tr?id=<?php echo $id ?>&ev=PageView&noscript=1"
77
- /></noscript>
78
  <!-- End Facebook Pixel Code -->
6
  * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
  */
 
 
 
9
  ?>
10
  <?php
11
  /**
27
  t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
28
  document,'script','https://connect.facebook.net/en_US/fbevents.js');
29
 
30
+ fbq('init', '<?php echo $this->escapeHtml($id) ?>');
31
  fbq('track', 'PageView');
32
 
33
  <?php if ($action == 'cms_index_index'): ?>
39
  || $action == 'catalog_category_layered'): ?>
40
  fbq('track', 'ViewContent');
41
  <?php elseif ($action == 'catalog_product_view'): ?>
42
+
43
+ <?php
44
+ $productData = $this->getProductData();
45
+ if ($productData !== null): ?>
46
+ fbq('track', 'ViewContent', {
47
+ content_name: '<?php echo $this
48
+ ->escapeHtml($productData['content_name']) ?>',
49
+ content_ids: ['<?php echo $this
50
+ ->escapeHtml($productData['content_ids']) ?>'],
51
+ content_type: 'product',
52
+ value: <?php echo $this->escapeHtml($productData['value']) ?>,
53
+ currency: '<?php echo $this->escapeHtml($productData['currency']) ?>'
54
+ });
55
+ //Add Pixel Events to the button's click handler
56
+ if (typeof jQuery != 'undefined') {
57
+ jQuery('.add-to-cart .btn-cart').click(function() {
58
+ fbq('track', 'AddToCart', {
59
+ content_name: '<?php echo $this
60
+ ->escapeHtml($productData['content_name']) ?>',
61
+ content_ids: ['<?php echo $this
62
+ ->escapeHtml($productData['content_ids']) ?>'],
63
+ content_type: 'product',
64
+ value: <?php echo $this->escapeHtml($productData['value']) ?>,
65
+ currency: '<?php echo $this->escapeHtml($productData['currency'])?>'
66
+ });
67
+ });
68
+ }
69
+ <?php endif; ?>
70
+
71
  <?php elseif ($action == 'catalogsearch_result_index'
72
  || $action == 'catalogsearch_advanced_result'): ?>
73
  fbq('track', 'Search');
74
  <?php elseif ($action == 'customer_account_create'): ?>
75
  fbq('track', 'CompleteRegistration');
 
 
76
  <?php elseif ($action == 'checkout_onepage_index'
77
  || $action == 'onestepcheckout_index_index'
78
  || $action == 'opc_index_index'): ?>
79
  fbq('track', 'InitiateCheckout');
80
  <?php elseif ($action == 'checkout_onepage_success'): ?>
81
+
 
 
82
  <?php
83
+ $orderData = $this->getOrderData();
84
+ if ($orderData !== null):?>
85
+ fbq('track', 'Purchase', {
86
+ <?php if (array_key_exists('content_name', $orderData)): ?>
87
+ content_name: '<?php echo $this->escapeHtml($orderData['content_name']) ?>',
88
  <?php endif; ?>
89
+ content_ids: [<?php echo $this->escapeHtml($orderData['content_ids']) ?>],
90
+ content_type: 'product',
91
+ value: <?php echo $this->escapeHtml($orderData['value']) ?>,
92
+ currency: '<?php echo $this->escapeHtml($orderData['currency']) ?>'
93
+ });
94
+ <?php endif; ?>
95
+
96
  <?php elseif ($action == 'wishlist_index_index'): ?>
97
  fbq('track', 'AddToWishlist');
98
  <?php else: ?>
101
 
102
  </script>
103
  <noscript><img height="1" width="1" style="display:none" alt="Facebook Pixel"
104
+ src="https://www.facebook.com/tr?id=<?php echo $this
105
+ ->escapeHtml($id) ?>&ev=PageView&noscript=1"/></noscript>
106
  <!-- End Facebook Pixel Code -->
package.xml CHANGED
@@ -1,18 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Apptrian_Facebook_Pixel</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Adds Facebook Pixel with standard events on appropriate pages. Passes W3C validation. Easy to install and use.</summary>
10
- <description>Apptrian Facebook Pixel Extension for Magento adds Facebook Pixel on CMS pages (including home page), category pages, product pages, catalog search pages, catalog advanced search pages, customer registration page, cart page, checkout page (default Magento one but also IWD One Page Checkout and IDEV OneStepCheckout - others can be easily supported), checkout success page, and wishlist page. Optionally Facebook Pixel block can be added to any other Magento page or any other extension page (blogs, form pages, etc.) via xml layout updates.</description>
11
- <notes>Initial release.</notes>
 
12
  <authors><author><name>Apptrian</name><user>apptrian</user><email>apptrian@yahoo.com</email></author></authors>
13
- <date>2016-05-03</date>
14
- <time>21:29:14</time>
15
- <contents><target name="magecommunity"><dir name="Apptrian"><dir name="FacebookPixel"><dir name="Block"><dir name="Adminhtml"><file name="About.php" hash="50252d7279e670db6b55becb51bf4972"/><file name="Info.php" hash="6d198b2b2adcb85fd5d0b5f24bf30f34"/></dir><file name="Code.php" hash="e3499a4b7ffe0bac0df1ad2a60bd562d"/></dir><dir name="Helper"><file name="Data.php" hash="ce582ef825fb7071ad52da24ddd703f6"/></dir><dir name="Model"><dir name="Config"><file name="Pixelid.php" hash="628b51cbabd8539a92c9b04d621a731c"/></dir></dir><dir name="etc"><file name="config.xml" hash="ed0b1cba402da2dc0445fd40b29aa280"/><file name="system.xml" hash="864da78b1a9174f70e7ecf0873017cdb"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="apptrian_facebookpixel.xml" hash="dae666fe98a79ae417786d1a5eaec929"/></dir><dir name="template"><dir name="apptrian"><dir name="facebookpixel"><file name="code.phtml" hash="4bfcaae5b88ac9820a2633af629ba329"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Apptrian_FacebookPixel.xml" hash="70949175d38bd066823f7b31b2a0a53e"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Apptrian_FacebookPixel.csv" hash="1918e6bffdadf5063923338d2fb30fcd"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>8.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Apptrian_Facebook_Pixel</name>
4
+ <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Adds Facebook Pixel with Dynamic Ads code. Passes W3C validation. Easy to install and use.</summary>
10
+ <description>Apptrian Facebook Pixel Extension for Magento adds Facebook Pixel with Dynamic Ads code on CMS pages (including home page), category pages, product pages, catalog search pages, catalog advanced search pages, customer registration page, checkout page (default Magento one but also IWD One Page Checkout and IDEV OneStepCheckout - others can be easily supported), checkout success page, and wishlist page. Optionally Facebook Pixel block can be added to any other Magento page or any other extension page (blogs, form pages, etc.) via xml layout updates.</description>
11
+ <notes>+ Facebook Dynamic Ads code&#xD;
12
+ + Compliance with Magento's Extension Quality Program (EQP)</notes>
13
  <authors><author><name>Apptrian</name><user>apptrian</user><email>apptrian@yahoo.com</email></author></authors>
14
+ <date>2016-11-23</date>
15
+ <time>21:35:57</time>
16
+ <contents><target name="magecommunity"><dir name="Apptrian"><dir name="FacebookPixel"><dir name="Block"><dir name="Adminhtml"><file name="About.php" hash="a4a2606d0c6c275eb61520cd019d3f57"/><file name="Info.php" hash="2657afb23a33a8f0ba69f95aaf609587"/></dir><file name="Code.php" hash="4c4b559998d234f80dbdb9f39f4cec18"/></dir><dir name="Helper"><file name="Data.php" hash="ce582ef825fb7071ad52da24ddd703f6"/></dir><dir name="Model"><dir name="Config"><file name="Pixelid.php" hash="3a7be57f685ecca7f832127d008277b4"/></dir></dir><dir name="etc"><file name="config.xml" hash="bd22a7c78974f38fff2df8048cd88e43"/><file name="system.xml" hash="23422fba35bb9730ee604228d99a1e1a"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="apptrian_facebookpixel.xml" hash="476c3c581a20d4da36f2623154ec1615"/></dir><dir name="template"><dir name="apptrian"><dir name="facebookpixel"><file name="code.phtml" hash="bf0077f3e69c19d2af37313eb8edfe63"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Apptrian_FacebookPixel.xml" hash="70949175d38bd066823f7b31b2a0a53e"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Apptrian_FacebookPixel.csv" hash="1918e6bffdadf5063923338d2fb30fcd"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>8.0.0</max></php></required></dependencies>
19
  </package>