VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: microtribe on June 17, 2014, 03:23:47 AM

Title: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: microtribe on June 17, 2014, 03:23:47 AM
Hi. I need to insert Facebook's Conversion Tracking code into the <head> tag of the order_done.php page. I know how to add Google's tracking code to the body, but do not know how to add Facebook's code to the Head tag. Can anyone help? I have  a third party extension installed, but it just offers the ability to add the code to a published article page, and the checkout thank you page is not a published article.

Thank you,
Tony
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: GJC Web Design on June 17, 2014, 10:18:22 AM
something like


$script = 'YOUR SCRIPT HERE';
$doc = JFactory::getDocument();
$doc->addScriptDeclaration( $script );

Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: microtribe on June 19, 2014, 06:47:03 AM
Nope, that doesn't work. Something about the syntax of the script messes it up when I drop it into YOUR SCRIPT HERE. Below is the script. I've overwritten my personal numeric code with NUMBER for security.

<script>(function() {
  var _fbq = window._fbq || (window._fbq = []);
  if (!_fbq.loaded) {
    var fbds = document.createElement('script');
    fbds.async = true;
    fbds.src = '//connect.facebook.net/en_US/fbds.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(fbds, s);
    _fbq.loaded = true;
  }
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'NUMBER', {'value':'0.00','currency':'USD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=NUMBER&amp;cd[value]=0.00&amp;cd[currency]=USD&amp;noscript=1" /></noscript>
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: GJC Web Design on June 19, 2014, 09:22:28 AM
of course - you will have to escape etc your script - you asked how to insert JS in the head on a Joomla install - that is how

to get your script in a condition to do that is html 101 - Google
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: powerguy2011 on July 20, 2014, 00:11:14 AM
yes I was wondering why there is no thread about this.

the new facebook conversion tool it very useful but somehow its not working when I do the steps as facebook guide,

they asked to copy the entire pixel code and add it into all php files of the website in <head> tags and then when making the campaign choose the pages u need to track,

1- there are a lot of files in joomla and virtuemart is it really necessary to do that

2- I inserted the code in some files and fixed the campaign to track it, however its not working I don't know why

I am a beginner and don't know about coding but in facebook tutorial it mentioned not to edit the code,

can anyone help?
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: powerguy2011 on July 20, 2014, 05:45:04 AM
hey guyz !

I want to give this a second try, can anyone tell me what is the file name for the thankyou page after checkout knowing that I use VM version 1.2.0 b stable
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: jenkinhill on July 20, 2014, 10:56:59 AM
VirtueMart 1.2b is not supported on this forum. It was a privately produced version of VM1.1.9 modified to work with Joomla2.5 for those who for one reason or another could not migrate their site to use VM2 at that time. See http://forum.virtuemart.net/index.php?topic=99339.0   
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: powerguy2011 on July 25, 2014, 03:11:16 AM
just wanted to knw the checkout page php file name..
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: microtribe on December 12, 2014, 20:59:38 PM
Hey folks. The solution I came up with was to create a custom Thank You page that the cart redirects to at checkout. I was then able to install the FB conversion pixel and it works. The only downside is that this is a static html page, so it has to be updated if the main menu changes.
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: sebmolo on January 29, 2015, 15:00:42 PM
I'm really interested in that matter, as i need to implement the facebook conversion pixel in the checkout page.
Can anybody help me to insert the code the right way?
Thanks in advance!
Title: Re: Insert Facebook Conversion Code into Head tag of Checkout Thank you page
Post by: microtribe on November 30, 2015, 22:39:21 PM
UPDATE: With the new Facebook pixel, you no longer need to add the code to your thank you page or order_done.php page. You just add the main pixel to your template index.php file in the head area. Then in Facebook, create a Custom Conversion item and use the URL for your checkout: http://www.yourwebsite.com/store/cart