♥Gyakutsuki Posted October 13, 2015 Share Posted October 13, 2015 Today A news on facebook could be interesting. there the information : news : https://www.facebook.com/business/news/product-ads the process to use : https://www.facebook.com/business/a/online-sales/dynamic-product-ads Just we need a csv to push the product on the facebook catalog, I also suppose it can be dynamic. the feed: https://developers.facebook.com/docs/marketing-api/reference/product-feed Regards ----------------------------------------- Loïc Contact me by skype for business Contact me @gyakutsuki for an answer on the forum Link to comment Share on other sites More sharing options...
greasemonkey Posted October 14, 2015 Share Posted October 14, 2015 I'm in... I could so use this. Link to comment Share on other sites More sharing options...
burt Posted October 14, 2015 Share Posted October 14, 2015 Going by https://www.facebook.com/business/a/online-sales/dynamic-product-adsit looks like Shopowners need 3 things; 1. a mechanism to create a suitably formatted list of products. 2. custom audience pixel module 3. facebook converson pixel module Is there more to it, I have not read the pages in-depth. Link to comment Share on other sites More sharing options...
greasemonkey Posted October 14, 2015 Share Posted October 14, 2015 a mechanism to create a suitably formatted list of products. @@burt that is all I'm missing.... i was going to try a simple .csv export from mysql. unless you have simple script to maybe include with your FB pixel module? Link to comment Share on other sites More sharing options...
burt Posted October 14, 2015 Share Posted October 14, 2015 Creation of a script that would make a suitable XML feed would not be straightforward, but equally not super difficult. There might already be a script in the addons area that could handle it. It would be good to have a shopowner who could put the pieces of the jigsaw together and get it working on FB. Link to comment Share on other sites More sharing options...
♥bruyndoncx Posted October 15, 2015 Share Posted October 15, 2015 the details on the product feed are at this url https://developers.facebook.com/docs/marketing-api/dynamic-product-ads/product-catalog#productfeed not sure if the feedmachine contribution is something to look into for this. I'm currently using a commercial system (lengow) that takes my product feed and then aggregates and enhances the feed for product ads to google, but have not looked into facebook ads as yet. KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt Link to comment Share on other sites More sharing options...
burt Posted October 16, 2015 Share Posted October 16, 2015 Coded and being Tested. Stay tuned. Link to comment Share on other sites More sharing options...
♥Gyakutsuki Posted October 16, 2015 Author Share Posted October 16, 2015 I tried to use this code below but I don't know if it's correct. On google : I see the document on the screen On firefox ; I don't see the document on the screen but when I edit the code With facebook on this url : https://business.facebook.com/ads/product_catalog/debug/ there is no result with my url : http://localhost/boutique/export_price_comparison.php?format=facebook.php&p=Gh87456yDE&language=fr&libre= note: localhost is not my true URL, it's example. idea $products_description = $products['products_description']; $products_description = html_entity_decode($products_description); $products_description = str_replace('<BR>','<br />', $products_description); $products_description =preg_replace('/\s \s/i', ' ', $products_description); $head ='<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">'.chr(10); $head .='<channel>'.chr(10); $head .='<title>' . STORE_NAME . '</title>'.chr(10); $head .='<link>' . HTTP::TypeUrlDomain() . '</link>'.chr(10); $head .='<description>An example item from the feed</description>'.chr(10); $head .='<item>'.chr(10); $output .= '<g:id>' . $products['products_model'] . '></g:id>'.chr(10); $output .= '<g:title>' . utf8_decode($products['products_name']) . '></g:title>'.chr(10); $output .= '<g:description>' . $products_description . '></g:description>'.chr(10); $output .= '<g:link>' . OSCOM::link('product_info.php', 'products_id=' . $products['products_id'], 'SSL') . $libre . '></g:link>>'.chr(10); $output .= '<g:image_link>' . HTTP::TypeUrlDomain() . DIR_WS_HTTP_CATALOG . DIR_WS_IMAGES . $products['products_image'] . '></g:image_link>'.chr(10); $output .= '<g:brand>' . utf8_decode($products['manufacturers_name']).'</g:brand>'.chr(10); $output .= '<g:price>' . $regular_price .'</g:price>'.chr(10); $foot .= '<item></channel></rss>'; The result is : <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"> <channel> <title>Boutique</title> <link>http://localhost</link> <description>An example item from the feed</description> <item> <g:id>REF-2104056098></g:id> <g:title>Tequilla Beefeaterin></g:title> <g:description>Haec igitur lex in amicitia sanciatur, ut neque rogemus res turpes nec faciamus rogati. Turpis enim excusatio est et minime accipienda cum in ceteris peccatis, tum si quis contra rem publicam se amici causa fecisse fateatur. Etenim eo loco, Fanni et Scaevola, locati sumus ut nos longe prospicere oporteat futuros casus rei publicae. Deflexit iam aliquantum de spatio curriculoque consuetudo maiorum.Alii nullo quaerente vultus severitate adsimulata patrimonia sua in inmensum extollunt, cultorum ut puta feracium multiplicantes annuos fructus, quae a primo ad ultimum solem se abunde iactitant possidere, ignorantes profecto maiores suos, per quos ita magnitudo Romana porrigitur, non divitiis eluxisse sed per bella saevissima, nec opibus nec victu nec indumentorum vilitate gregariis militibus discrepantes opposita cuncta superasse virtute. Advenit post multos Scudilo Scutariorum tribunus velamento subagrestis ingenii persuasionis opifex callidus. qui eum adulabili sermone seriis admixto solus omnium proficisci pellexit vultu adsimulato saepius replicando quod flagrantibus votis eum videre frater cuperet patruelis, siquid per inprudentiam gestum est remissurus ut mitis et clemens, participemque eum suae maiestatis adscisceret, futurum laborum quoque socium, quos Arctoae provinciae diu fessae poscebant.></g:description> <g:link>http://localhost/boutique/product_info.php?products_id=1></g:link> <g:image_link>http://localhost/boutique/sources/image/products/alcool/130_640_beefeaterin.jpg></g:image_link> <g:brand></g:brand> <g:price>100.0000</g:price> <g:id>REF-1204150938</g:id> <g:title>Tequilla Bells Christmas Decanter></g:title> <g:description>Haec igitur lex in amicitia sanciatur, ut neque rogemus res turpes nec faciamus rogati. Turpis enim excusatio est et minime accipienda cum in ceteris peccatis, tum si quis contra rem publicam se amici causa fecisse fateatur. Etenim eo loco, Fanni et Scaevola, locati sumus ut nos longe prospicere oporteat futuros casus rei publicae. Deflexit iam aliquantum de spatio curriculoque consuetudo maiorum.<br /> <br /> Alii nullo quaerente vultus severitate adsimulata patrimonia sua in inmensum extollunt, cultorum ut puta feracium multiplicantes annuos fructus, quae a primo ad ultimum solem se abunde iactitant possidere, ignorantes profecto maiores suos, per quos ita magnitudo Romana porrigitur, non divitiis eluxisse sed per bella saevissima, nec opibus nec victu nec indumentorum vilitate gregariis militibus discrepantes opposita cuncta superasse virtute.<br /> <br /> Advenit post multos Scudilo Scutariorum tribunus velamento subagrestis ingenii persuasionis opifex callidus. qui eum adulabili sermone seriis admixto solus omnium proficisci pellexit vultu adsimulato saepius replicando quod flagrantibus votis eum videre frater cuperet patruelis, siquid per inprudentiam gestum est remissurus ut mitis et clemens, participemque eum suae maiestatis adscisceret, futurum laborum quoque socium, quos Arctoae provinciae diu fessae poscebant.></g:description> <g:link>http://localhost/boutique/product_info.php?products_id=2</g:link> <g:image_link>http://localhost/boutique/sources/image/products/alcool/130_640_bells_christmas_Decanter.jpg</g:image_link> <g:brand>tutu</g:brand> <g:price>695.0000</g:price> </item> </channel> </rss> Regards ----------------------------------------- Loïc Contact me by skype for business Contact me @gyakutsuki for an answer on the forum Link to comment Share on other sites More sharing options...
burt Posted November 11, 2015 Share Posted November 11, 2015 Anyone else using Facebook Ads ? Or want to start using it ? Link to comment Share on other sites More sharing options...
♥bruyndoncx Posted November 11, 2015 Share Posted November 11, 2015 yes, I think so, but I'm not upto speed with the details of it all KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt Link to comment Share on other sites More sharing options...
frankl Posted February 29, 2016 Share Posted February 29, 2016 Anyone else using Facebook Ads ? Or want to start using it ? I'm starting on this now. You need a business page - https://www.facebook.com/business/learn/set-up-facebook-page Then you need to create a Facebook pixel. Once you have your Facebook pixel you need to add a header tag to your site. I have created a very basic header tag module (which only tracks visits and conversions - you can also track other events such as Add to Cart or View Content). ht_facebook_pixel module code: <?php /* $Id: ht_facebook_pixel module.php v1.0 20101128 frankl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2010 osCommerce Released under the GNU General Public License */ class ht_facebook_pixel { var $code = 'ht_facebook_pixel'; var $group = 'header_tags'; var $title; var $description; var $sort_order; var $enabled = false; var $languages_array = array(); function ht_facebook_pixel() { $this->title = MODULE_HEADER_TAGS_FACEBOOK_PIXEL_TITLE; $this->description = MODULE_HEADER_TAGS_FACEBOOK_PIXEL_DESCRIPTION; if ( defined('MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS') ) { $this->sort_order = MODULE_HEADER_TAGS_FACEBOOK_PIXEL_SORT_ORDER; $this->enabled = (MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS == 'True'); } } function execute() { global $oscTemplate, $order, $order_id; if( basename( $PHP_SELF ) == FILENAME_CHECKOUT_SUCCESS) { ob_start(); $trusted_order_query = tep_db_query("select customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'"); $trusted_order = tep_db_fetch_array($trusted_order_query); //total order amount query $total_cost_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_total'"); $total_cost = tep_db_fetch_array($total_cost_query); //discounts query $discount_total_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_coupon'"); $discount_total = tep_db_fetch_array($discount_total_query); //shipping cost $shipping_cost_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_shipping'"); $shipping_cost = tep_db_fetch_array($shipping_cost_query); //tax $tax_amount_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_tax'"); $tax_amount = tep_db_fetch_array($tax_amount_query); //shipping/delivery $shipping_date = date('Y-m-d', strtotime($order['date_purchased'] . ' +1 Weekday')); } $meta_tag = <<<EOD <!-- Facebook Pixel Code --> <script> !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','//connect.facebook.net/en_US/fbevents.js'); fbq('init', 'YOUR PIXEL CODE HERE'); fbq('track', "PageView"); EOD; if( basename( $PHP_SELF ) == FILENAME_CHECKOUT_SUCCESS) { $meta_tag .= <<<EOD fbq('track', 'Purchase', {value: ' EOD; $meta_tag .= number_format($total_cost['value'], 2, '.', ''); $meta_tag .= <<<EOD ', currency:'AUD'}); EOD; } $meta_tag .= <<<EOD </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=YOUR PIXEL CODE HERE&ev=PageView&noscript=1" /></noscript> <!-- End Facebook Pixel Code --> EOD; if( basename( $PHP_SELF ) == FILENAME_CHECKOUT_SUCCESS) { $template = ob_get_clean(); } $oscTemplate->addBlock( $meta_tag, $this->group ); } function isEnabled() { return $this->enabled; } function check() { return defined( 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS' ); } function install() { tep_db_query( "insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Facebook pixel Meta Tag', 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS', 'True', 'Do you want to add a Facebook pixel tag to all pages?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())" ); tep_db_query( "insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_SORT_ORDER', '40', 'Sort order of display. Lowest is displayed first.', '6', '2', now())" ); } function remove() { tep_db_query( "delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { $keys_array = array(); $keys_array[] = 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS'; $keys_array[] = 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_SORT_ORDER'; return $keys_array; } } ?> It would probably be easier to have a field when enabling/disabling the module where the Facebook pixel id can be added. Language file for ht_facebook_pixel module <?php /* $Id: ht_facebook_pixel.php v1.0 20101128 frankl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2010 osCommerce Released under the GNU General Public License */ define( 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_TITLE', 'Facebook Pixel Tag' ); define( 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_DESCRIPTION', 'Add the Facebook pixel tag to all pages.' ); ?> With pixels you can do exciting things such as targeting audiences, remarketing etc etc https://www.facebook.com/business/a/online-sales/custom-audiences-website I've made a couple of custom audiences - people who like our page, females aged 25-60, people who have visited our site in the last 30 days etc etc. I am using my googlefeeder.php to (successfully) upload products. Next step is to see how easy it is to do the ads. I'll keep you posted. osCommerce user since 2003! Link to comment Share on other sites More sharing options...
frankl Posted February 29, 2016 Share Posted February 29, 2016 OK. Need to add this to the ht_facebook_pixel.php code (after the conditional checkout success) if( isset( $_GET['products_id'] ) ) { $meta_tag .= <<<EOD fbq(['track', 'ViewContent', { content_type: 'product', content_ids: [' EOD; $meta_tag .= $_GET['products_id']; $meta_tag .= <<<EOD '], }]); EOD; } This will register the product id (or ids) for the customer so that Facebook will show the product, or related products, on their news feed or in the right hand column when they are browsing Facebook. osCommerce user since 2003! Link to comment Share on other sites More sharing options...
frankl Posted February 29, 2016 Share Posted February 29, 2016 Next, how to actually set up a dynamic ad https://developers.facebook.com/docs/marketing-api/dynamic-product-ads/v2.5 osCommerce user since 2003! Link to comment Share on other sites More sharing options...
frankl Posted February 29, 2016 Share Posted February 29, 2016 I have struck a snag and am now stymied. According to Facebook we NEED these standard events in the pixel to enable dynamic product ads: View Content (installed and working OK); Add To Cart; and Purchase (may need more work). For add to cart we can add an onclick event. I have the code below that I added to product_info.php: <?php if ($facebook_special_price = tep_get_products_special_price($product_info['products_id'])) { $facebook_price = $facebook_special_price+tep_calculate_tax($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])); } else { $facebook_price = $product_info['products_price']+tep_calculate_tax($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); } ?> <script type="text/javascript"> $( '#addToCartButton' ).click(function() { fbq('track', 'AddToCart', { content_name: '<?php echo $product_info['products_name']; ?>', content_category: '', content_ids: ['<?php echo $_GET['products_id']; ?>'], content_type: 'product', value: <?php echo $facebook_price; ?>, currency: '<?php echo tep_output_string($currency); ?>' }); }); </script> which outputs as an example (and would be easy to add as a product_info page module!): <script type="text/javascript"> $( '#addToCartButton' ).click(function() { fbq('track', 'AddToCart', { content_name: 'Canon MG5760 Advanced All-in-One Black Printer', content_category: '', content_ids: ['7665'], content_type: 'product', value: 94.99996, currency: 'AUD' }); }); </script> (the value could do with rounding and we need to add the category but those are minor issues) compared to Facebook's example: <button id="addToCartButton">Add To Cart</button> <!-- Add event to the button's click handler --> <script type="text/javascript"> $( '#addToCartButton' ).click(function() { fbq('track', 'AddToCart', { content_name: 'Really Fast Running Shoes', content_category: 'Apparel & Accessories > Shoes', content_ids: ['1234'], content_type: 'product', value: 2.99, currency: 'USD' }); }); </script> As far as I can tell the pixel for AddToCart isn't firing. I'm using the Facebook Pixel Helper to diagnose https://developers.facebook.com/docs/facebook-pixel/pixel-helper Do I need to add id="addToCartButton" to the add to cart button to make that onclick event work? How to do that? Or do we need a new tep_draw_button function to add it? I'm not very good at javascript! osCommerce user since 2003! Link to comment Share on other sites More sharing options...
frankl Posted February 29, 2016 Share Posted February 29, 2016 Another important step is to associate your Facebook Pixel with a catalogue. Follow these steps to pair a catalog with a pixel using the Business Manager: Go to business.facebook.com Settings page Choose "Product Catalogs" on the left pane Press "Associate Pixels" button Associate pixels with your product catalog. osCommerce user since 2003! Link to comment Share on other sites More sharing options...
burt Posted February 29, 2016 Share Posted February 29, 2016 @@frankl good work. Will be good to see where you get with it. This was another scheduled for inclusion in 29DoC. Fully Coded and being tested by a user, but the user dropped out of testing it and become a bit unresponsive to emails :( So it was another project I shelved :( Link to comment Share on other sites More sharing options...
frankl Posted March 1, 2016 Share Posted March 1, 2016 I have advanced and I have this working (although the code may be sloppy) The steps you need to take according to this page https://www.facebook.com/business/a/online-sales/dynamic-product-ads are: Upload your product catalogue Set up your pixel Create a dynamic pixel Run dynamic adverts Not as simple as it looks though. Before you do anything, set up a business page on Facebook https://www.facebook.com/business/learn/set-up-facebook-page This will enable you to access the Adverts Manager pages necessary to set this up. Next you need to set up a feed for the product catalogue. If you are using a feed for Google Merchant, this is perfect. If you haven't set up any kind of feed yet, I believe this contribution would do what you want http://addons.oscommerce.com/info/4513 You can do your own csv file and upload it manually, but far better to have a feed that Facebook can fetch daily or weekly with no input from you. Once your products have uploaded you need to make a product set. Just add all the products to the product set, you can fine tune and tweak product sets later. Now you need to set up your pixel. You can do this through the business settings. Facebook will give you Javascript code but ignore that for the moment. All you need is the long number (the one I received was 15 digits). We need to set up the Facebook pixel to check product views, products added to cart and purchases. Facebook will keep track of product ids for targeting your ads. You can use these product ids to NOT show products to people who already bought them, or show them the same product after 6 months, or show them related products (using Product Sets) etc etc. Targeting is only limited to your imagination. This is the basic pixel code, which is a header tag module. You would need to replace the XXXXXXXXXXX's with the long number you received earlier. This code will take care of product views (and page views too, actually). Copy this to ht_facebook_pixel.php and save it in includes/modules/header_tags <?php /* $Id: ht_facebook_pixel.php v1.0 20101128 frankl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2010 osCommerce Released under the GNU General Public License */ class ht_facebook_pixel { var $code = 'ht_facebook_pixel'; var $group = 'header_tags'; var $title; var $description; var $sort_order; var $enabled = false; var $languages_array = array(); function ht_facebook_pixel() { $this->title = MODULE_HEADER_TAGS_FACEBOOK_PIXEL_TITLE; $this->description = MODULE_HEADER_TAGS_FACEBOOK_PIXEL_DESCRIPTION; if ( defined('MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS') ) { $this->sort_order = MODULE_HEADER_TAGS_FACEBOOK_PIXEL_SORT_ORDER; $this->enabled = (MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS == 'True'); } } function execute() { global $oscTemplate, $order, $order_id; $meta_tag .= <<<EOD <!-- Facebook Pixel Code --> <script> !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','//connect.facebook.net/en_US/fbevents.js'); fbq('init', 'XXXXXXXXXXXXXXX'); fbq('track', "PageView"); EOD; if( isset( $_GET['products_id'] ) ) { $meta_tag .= <<<EOD fbq(['track', 'ViewContent', { content_type: 'product', content_ids: [' EOD; $meta_tag .= $_GET['products_id']; $meta_tag .= <<<EOD '], }]); EOD; } $meta_tag .= <<<EOD </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=XXXXXXXXXXXXXXX&ev=PageView&noscript=1" /></noscript> <!-- End Facebook Pixel Code --> EOD; $oscTemplate->addBlock( $meta_tag, $this->group ); } function isEnabled() { return $this->enabled; } function check() { return defined( 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS' ); } function install() { tep_db_query( "insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Facebook pixel Meta Tag', 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS', 'True', 'Do you want to add a Facebook pixel tag to all pages?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())" ); tep_db_query( "insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_SORT_ORDER', '40', 'Sort order of display. Lowest is displayed first.', '6', '2', now())" ); } function remove() { tep_db_query( "delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { $keys_array = array(); $keys_array[] = 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_STATUS'; $keys_array[] = 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_SORT_ORDER'; return $keys_array; } } Language file: Copy this to ht_facebook_pixel.php and save it in includes/languages/english/modules/header_tags <?php /* $Id: ht_facebook_pixel.php v1.0 20101128 frankl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2010 osCommerce Released under the GNU General Public License */ define( 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_TITLE', 'Facebook Pixel Tag' ); define( 'MODULE_HEADER_TAGS_FACEBOOK_PIXEL_DESCRIPTION', 'Add the Facebook pixel tag to all pages.' ); To track products added to cart, change this line echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'glyphicon glyphicon-shopping-cart', null, 'primary', '', 'btn btn-success'); to echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'glyphicon glyphicon-shopping-cart', null, 'primary', array('params' => 'id="addToCartButton"'), 'btn btn-success'); then add this code below <?php if ($facebook_special_price = tep_get_products_special_price($product_info['products_id'])) { $facebook_price = $facebook_special_price+tep_calculate_tax($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])); } else { $facebook_price = $product_info['products_price']+tep_calculate_tax($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); } ?> <script type="text/javascript"> $( '#addToCartButton' ).click(function() { fbq('track', 'AddToCart', { content_name: '<?php echo $product_info['products_name']; ?>', content_category: '', content_ids: ['<?php echo $_GET['products_id']; ?>'], content_type: 'product', value: <?php echo $facebook_price; ?>, currency: '<?php echo tep_output_string($currency); ?>' }); }); </script> Next we need to track purchases This is the code for a checkout success module. Copy this to ht_facebook_purchase.php and save it in includes/modules/content/checkout_success <?php /* $Id$ ht_facebook_purchase.php v1.0 20160301 frankl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2014 osCommerce Released under the GNU General Public License */ class cm_cs_facebook_purchase { var $code; var $group; var $title; var $description; var $sort_order; var $enabled = false; function cm_cs_facebook_purchase() { $this->code = get_class($this); $this->group = basename(dirname(__FILE__)); $this->title = MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_TITLE; $this->description = MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_DESCRIPTION; if ( defined('MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_STATUS') ) { $this->sort_order = MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_SORT_ORDER; $this->enabled = (MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_STATUS == 'True'); } } function execute() { global $oscTemplate, $customer_id, $order_id; //total order amount query $total_cost_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_total'"); $total_cost = tep_db_fetch_array($total_cost_query); $order_query = tep_db_query("select currency from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'"); $order = tep_db_fetch_array($order_query); ob_start(); $meta_tag = <<<EOD <script type="text/javascript"> fbq('track', 'Purchase', { content_type: 'product', value: ' EOD; $meta_tag .= number_format($total_cost['value'], 2, '.', ''); $meta_tag .= <<<EOD ', currency: ' EOD; $meta_tag .= $order['currency']; $meta_tag .= <<<EOD ', order_id: ' EOD; $meta_tag .= (int)$order_id; $meta_tag .= <<<EOD ', content_ids : EOD; $product_ids = ''; $order_products_query = tep_db_query("select op.products_id, pd.products_name, op.final_price, op.products_quantity from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_LANGUAGES . " l where op.orders_id = '" . (int)$order_id . "' and op.products_id = pd.products_id and l.code = '" . tep_db_input(DEFAULT_LANGUAGE) . "' and l.languages_id = pd.language_id"); while ($order_products = tep_db_fetch_array($order_products_query)) { $product_ids .= '\'' . (int)$order_products['products_id'] . '\','; // SKU/code - required } $meta_tag .= '[' . rtrim($product_ids, ",") . ']});'; $meta_tag .= <<<EOD </script> EOD; $template = ob_get_clean(); $oscTemplate->addContent($meta_tag, $this->group); } function isEnabled() { return $this->enabled; } function check() { return defined('MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_STATUS'); } function install() { tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Facebook Purchase Module', 'MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_STATUS', 'True', 'Should the facebook purchase block go on the checkout success page?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())"); } function remove() { tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { return array('MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_STATUS', 'MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_SORT_ORDER'); } } Language file: Copy this to ht_facebook_purchase.php and save it in includes/languages/english/modules/content/checkout_success <?php /* $Id$ ht_facebook_purchase.php v1.0 20160301 frankl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2014 osCommerce Released under the GNU General Public License */ define('MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_TITLE', 'Facebook Purchase'); define('MODULE_CONTENT_CHECKOUT_SUCCESS_FACEBOOK_PURCHASE_DESCRIPTION', 'Show Facebook purchase block on the checkout success page.'); Use the Facebook Pixel Helper addon for Chrome to check the pixel is firing. Now you've uploaded your product catalog and installed the pixels, go to the Facebook Adverts Manager, then Tools, then Pixels and check URLs, Domains, Devices and Events to be doubly ensure the pixel is working correctly. Note: Before you can set up an ad you need to set up a payment method with Facebook, and allow a minimum spend of $100 for a dynamic display ad campaign. You can always deactivate the campaign at any time, even if only $1 has been spent. To set up an ad, go to Facebook Adverts Manager, then Power Editor, then select Create Campaign from the Create Advert Set button. Give your campaign a name, choose Auction from Buying Type dropdown (I know, I know!) then select Product Catalogue Sales from the Objective dropdown. Tick both the Choose an advert set and Create new advert selectors, Create New on both, then name them. "Test' is fine for the whole series, you can delete them later. Click Create. There are 3 tabs on the left representing the different levels - Campaign, Advert Sets, and Adverts. Only the campaign has been created. Click on the middle tab to create an advert set. Choose the options you want. You can play around, all this is editable later or you can delete and start afresh. After that create an ad, the carousel with 5 items look the best. Play around with it, I'm no expert and have just started playing myself. osCommerce user since 2003! Link to comment Share on other sites More sharing options...
frankl Posted March 17, 2016 Share Posted March 17, 2016 Update on this contribution. It's working fine! When a visitor visits a product on our site without buying, then goes back to Facebook, that product shows up in ads on Facebook for 10 days (or until they buy). This month we've had 29 sales from this form of advertising at a cost of around $2 each (total cost of Facebook ads divided by number of sales). The Facebook pixel counts product views resulting from the ad too - that came to 400. Anyone else want to test? osCommerce user since 2003! Link to comment Share on other sites More sharing options...
PetrBertran Posted March 18, 2016 Share Posted March 18, 2016 Can not verify that I made the purchase that way. It works). Link to comment Share on other sites More sharing options...
frankl Posted March 21, 2016 Share Posted March 21, 2016 @PetrBertran Sorry I don't understand what you mean, but you need to activate the "Total Conversion Value" and "Purchases" columns in Adverts Manager to see conversions. osCommerce user since 2003! Link to comment Share on other sites More sharing options...
frankl Posted June 22, 2016 Share Posted June 22, 2016 OK. Need to add this to the ht_facebook_pixel.php code (after the conditional checkout success) if( isset( $_GET['products_id'] ) ) { $meta_tag .= <<<EOD fbq(['track', 'ViewContent', { content_type: 'product', content_ids: [' EOD; $meta_tag .= $_GET['products_id']; $meta_tag .= <<<EOD '], }]); EOD; } This will register the product id (or ids) for the customer so that Facebook will show the product, or related products, on their news feed or in the right hand column when they are browsing Facebook. Change this to if( isset( $_GET['products_id'] ) ) { $meta_tag .= <<<EOD fbq(['track', 'ViewContent', { content_type: 'product', content_ids: [' EOD; $meta_tag .= (int)$_GET['products_id']; $meta_tag .= <<<EOD '], }]); EOD; } (changed $meta_tag .= $_GET['products_id']; to $meta_tag .= (int)$_GET['products_id']; ) to avoid the possibility of XSS attacks. osCommerce user since 2003! Link to comment Share on other sites More sharing options...
Mort-lemur Posted September 1, 2016 Share Posted September 1, 2016 @@frankl Hi, Frank, Installing this and plowing through the facebook documentation - all very confusing stuff. To get the checkout success modules to load and install I had to name them cm_cs_facebook_purchase.php rather than ht_facebook_purchase.php Will keep you posted on how it works for me. Thanks Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members. Link to comment Share on other sites More sharing options...
frankl Posted September 1, 2016 Share Posted September 1, 2016 @@Mort-lemur The Facebook documentation is highly confusing, it took me a while to get through it (and I've promptly forgotten it, not much spare space in this old cranium anymore :))cm_cs_facebook_purchase.php is the correct filename, sorry about that. The header tag is ht_facebook_pixel.php. osCommerce user since 2003! Link to comment Share on other sites More sharing options...
Mort-lemur Posted September 2, 2016 Share Posted September 2, 2016 @@frankl Hi Again, Looking at your instructions for altering code for tracking items added to cart, your instructions are: To track products added to cart, change this line echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'glyphicon glyphicon-shopping-cart', null, 'primary', '', 'btn btn-success'); to echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'glyphicon glyphicon-shopping-cart', null, 'primary', array('params' => 'id="addToCartButton"'), 'btn btn-success'); Is this code in an existing file? (looks like it is from a 2.3.4BS Version?) Many Thanks Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members. Link to comment Share on other sites More sharing options...
frankl Posted September 4, 2016 Share Posted September 4, 2016 @@Mort-lemur That is the Add To Cart button on the product_info.php page. You should be able to alter that code according to which version of osCommerce you are using. osCommerce user since 2003! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.