Jump to content
Sign in to follow this  
jeebee123

Facebook Pixel Tracking

Recommended Posts

Hi,

So, I've added the Facebook Pixel to WHMCS with succes, but I'm trying to figure out how to set-up e-commerce tracking in WHMCS.

As example:

<script>
  fbq('track', 'AddPaymentInfo', {
    value: x,
    currency: 'EUR',
  });
</script>

I need to place this with the order button. If someone clicks on the "Add to cart button", this script needs to be triggered. So far thats not a problem.

 

Currently I use:

        <div class="package-footer" style="margin-bottom:25px"> 
			  <a href="{$WEB_ROOT}/cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-lg btn-primary" id="product{$product@iteration}-order-button AddToCart"> {$LANG.ordernowbutton} </a> {if $product.qty || $product.qty == "0"}
                <div class="package-qty"> {$product.qty} {$LANG.orderavailable} </div>
                {/if} 
			
			{literal} 
			<script type="text/javascript">
				$('#$AddToCart').click(function() {
    			fbq('track', 'AddToCart', {currency: "EUR", value: {$product.pricing.minprice.price}{if $product.pricing.type !=="free" && $product.pricing.type !=="onetime"}{/if});
  				});
			 </script>
			{/literal}
		</div>

 

The problem is: after the value: x, it needs to show the product price.

 

What is the correct way of doing this in WHMCS?

Share this post


Link to post
Share on other sites
2 hours ago, jeebee123 said:

What is the correct way of doing this in WHMCS?

using an output hook - I suppose footeroutput in this case.

possibly you might find some help in the code in the thread below...

Share this post


Link to post
Share on other sites
On 9/29/2020 at 6:04 PM, brian! said:

using an output hook - I suppose footeroutput in this case.

possibly you might find some help in the code in the thread below...

Hmm okay.

I found this code and placed it into the viewinvoice.tpl template file.

{if $status eq "Paid" || $paymentSuccessAwaitingNotification || $paymentSuccess || $paymentInititated}
{assign var=total_amt value=$total|replace:'€':''|replace:'EUR':''|replace:' ':''}
<!-- Facebook Pixel Code -->
{literal}
<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', 'XXXXXXXXXX'); // Insert your pixel ID here.
fbq('track', 'Purchase', {
 currency: 'EUR',
 amount: '{/literal}{$total_amt}{literal}',
});
</script>	
{/literal}
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->
{/if}

I will test the code today.

Share this post


Link to post
Share on other sites

There's nothing to test. It's crystal clear from the code that it will not work as it should.

Every time an user views the invoice (it can be a customer or administrator) the purchase event triggers. Refreshing or visiting the page 100 times corresponds to 100 purchases. Your Facebook statistics will be a disaster as 99% of events are fake. It will report that you own a million-dollar business.

 

Share this post


Link to post
Share on other sites

Am using a callback file that redirects to the invoice page. What if I can use some kind of parameters in callback ? 

Could you help me know to get the values of $_GET into template ? so I can see if the purchase is valid from callback . @Kian

Share this post


Link to post
Share on other sites
1 hour ago, Waqas Saeed said:

Could you help me know to get the values of $_GET into template ?

in a template, you should be able to use $smarty.get.xxx where xxx is the name of the variable you're checking for...

{if $smarty.get.callbackvar eq "whatever"}

* do something *

{/if}

and that if condition could be combined with other existing if statement conditions if required.

Share this post


Link to post
Share on other sites

@brian! brilliant it resolved my issue overall. because we want to track those customers who are paying us with 3rd payment gateway. and it will not react to manual payment also. that is overall the best thing happened. I wish there could be some special hook in future that can able to return a html or javascript on successful payment attempt. 

Edited by Waqas Saeed

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

  • 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