jeebee123 Posted September 29, 2020 Share Posted September 29, 2020 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? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 29, 2020 Share Posted September 29, 2020 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... 0 Quote Link to comment Share on other sites More sharing options...
jeebee123 Posted November 18, 2020 Author Share Posted November 18, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted November 18, 2020 Share Posted November 18, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Manchester Web Hosting Posted November 18, 2020 Share Posted November 18, 2020 9 hours ago, Kian said: It will report that you own a million-dollar business. Some may like the vanity metrics, no? 1 Quote Link to comment Share on other sites More sharing options...
Waqas Saeed Posted November 27, 2020 Share Posted November 27, 2020 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 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 27, 2020 Share Posted November 27, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Waqas Saeed Posted November 27, 2020 Share Posted November 27, 2020 (edited) @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 November 27, 2020 by Waqas Saeed 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.