Jump to content

Facebook Pixel Code


Recommended Posts

7 hours ago, pRieStaKos said:

you can add the code to footer.tpl.

if you were going to do that, you'd be better off using a clientarea output hook rather than editing the template.

the free addon module below should still work - though it's 3 years old, so the specific Facebook pixel code within might need to be changed if it has been updated by Facebook since then...

https://github.com/StrikeHawk-ecommerce/whmcs-facebook-pixel-tracking

you would need to change the folder name to "facebookpixel" within the addons folder for this to be visible to the addons page.

Link to comment
Share on other sites

Hi Guys! Thanks for help me. I resolved it doing;

1) Open the file "header.tpl" on  your Template folder

2) Before the tag "</head>" put this code below changing the ID "123456" to your pixel id:


{literal}
 <!-- 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','https://connect.facebook.net/en_US/fbevents.js');
 fbq('init', '123456'); // Insert your pixel ID here.
 fbq('track', 'PageView');
 </script>
 <noscript><img height="1" width="1" style="display:none"
 src="https://www.facebook.com/tr?id=123456&ev=PageView&noscript=1"
 /></noscript>
 <!-- DO NOT MODIFY -->
 <!-- End Facebook Pixel Code -->
{/literal}

 

Now it is working fine. I hope to help someone.

Link to comment
Share on other sites

On 08/02/2019 at 01:12, JuniorRodrigues said:

Now it is working fine. I hope to help someone.

I assume that you realise that this code is going to get overwritten during your next WHMCS update - you'd be better off putting that code into a headoutput hook as the free addon I linked to does.

the attached hook should do the same as your edited template - though obviously don't use both.

facebookpixel.php

Edited by brian!
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

This hook worked and was able to be verified immediately for my Facebook Pixel.

  1. Create a file. ( I named it FBPixel.php ) in: /includes/hooks/FBPixel.php
  2. Add the following code and replace 123456 for your Pixel Id.  or copy your pixel code in between the "return <<<HTML and HTML;" tags.
  3. Save and test your pixel. Mine was immediately verified. You can also view the source code of your page and you can  see the pixel code below there.

Hope this helps.

JC

<?php

/**
* Facebook Pixel Code
* @author JC
*/

add_hook('ClientAreaHeadOutput', 1, function($vars) {
    
	return <<<HTML
  <!-- 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',
    'https://connect.facebook.net/en_US/fbevents.js');
    fbq('init', '123456'); //Your pixel ID here.
    fbq('track', 'PageView');
  </script>
  <noscript><img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=123456&ev=PageView&noscript=1"
  /></noscript>
  <!-- End Facebook Pixel Code -->
HTML;

});

 

Link to comment
Share on other sites

  • 8 months later...
  • 10 months later...
On 1/7/2021 at 8:52 AM, Dave_Johns said:

Hi @brian!

sorry for bother! I need to start tracking sales, that means to paste a pixel in /cart.php?a=complete . This hook that you have shared could work?

Thanks in advance

D.

Sorry for bumping an old thread.

Any luck with that though? I am also looking for a hook to add a script after payment complete (on success). 

Link to comment
Share on other sites

  • 1 year later...
On 2/7/2019 at 8:12 PM, JuniorRodrigues said:

Hi Guys! Thanks for help me. I resolved it doing;

1) Open the file "header.tpl" on  your Template folder

2) Before the tag "</head>" put this code below changing the ID "123456" to your pixel id:


{literal}
 <!-- 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','https://connect.facebook.net/en_US/fbevents.js');
 fbq('init', '123456'); // Insert your pixel ID here.
 fbq('track', 'PageView');
 </script>
 <noscript><img height="1" width="1" style="display:none"
 src="https://www.facebook.com/tr?id=123456&ev=PageView&noscript=1"
 /></noscript>
 <!-- DO NOT MODIFY -->
 <!-- End Facebook Pixel Code -->
{/literal}

 

Now it is working fine. I hope to help someone.

I used this solution in a custom template. So far so good.

Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated