X-Cart:How to Add Facebook Pixel Code to X-Cart Pages

From X-Cart 4 Classic
Revision as of 13:05, 27 February 2019 by Dohtur (talk | contribs)
Jump to: navigation, search

This article describes how to add Facebook Pixel code to the pages of X-Cart 4 Classic.

Please be aware that, starting with X-Cart 4.7.x, you can set up Facebook Pixel without custom programming - by using the module Facebook E-Commerce

Step-by-step guide

Locate the file skin/common_files/customer/service_head.tpl in your X-Cart folder and open it in X-Cart's Template Editor or a text editor of your choice.

Add the following code to the very end of the file:

<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.agent='plxcart';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', '{$config.Facebook_Ecommerce.facebook_ecomm_pixel_id|escape:"javascript"}'); // Insert your pixel ID here. fbq('track', 'PageView'); 

<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={$config.Facebook_Ecommerce.facebook_ecomm_pixel_id|escape:"html"}&ev=PageView&noscript=1"/></noscript>
<!-- End Facebook Pixel Code -->

Insert your pixel ID instead of pixel_id in the code above.

Save the changes and re-generate the X-Cart cache to make the changes active.

The command fbq('track', 'PageView'); used in the code above will create a standard event on the Facebook end.

It is also possible to add Facebook pixel ID by running the following SQL query in the Patch/Upgrade Center of the store Admin area:

INSERT INTO xcart_config SET name='facebook_ecomm_pixel_id', comment='Facebook Pixel ID', value='', category='Facebook_Ecommerce', orderby='20', type='trimmed_text', defvalue='', variants='', validation='' ON DUPLICATE KEY UPDATE orderby=orderby;

where value '' should be completed with your actual Facebook pixel ID value.

See Applying SQL Patches.