Looper Posted September 11, 2024 Share Posted September 11, 2024 I added Facebook Pixel code using a hook, and it's working just fine. However, I want to set up an event to capture sales, such as when someone makes a purchase. How can I track that in WHMCS? I used this hook to add the pixel: 0 Quote Link to comment Share on other sites More sharing options...
sahostking Posted November 11, 2024 Share Posted November 11, 2024 Well for starters you can do the following in your templates complete.tpl file Under: {if $ispaid} <!-- Enter any HTML code which should be displayed when a user has completed checkout here --> <!-- Common uses of this include conversion and affiliate tracking scripts --> Add something like below: {literal} <script> fbq('track', 'Purchase', {currency: "AED", value: 1.00}); </script> {/literal} I think the above could work. 0 Quote Link to comment Share on other sites More sharing options...
fridmanterry Posted November 11, 2024 Share Posted November 11, 2024 On 9/11/2024 at 4:30 PM, Looper said: I added Facebook Pixel code using a hook, and it's working just fine. However, I want to set up an event to capture sales, such as when someone makes a purchase. How can I track that in WHMCS? I used this hook to add the pixel: I am facing the same problem, have you found any working solution yet? 0 Quote Link to comment Share on other sites More sharing options...
Sweely Posted September 30 Share Posted September 30 That's a great question, and it's essential to track sales accurately for campaign optimization. The approach using `complete.tpl` is the standard client-side method, and the user sahostking is on the right track by suggesting the `fbq('track', 'Purchase', {currency: "AED", value: 1.00});` event. However, you need to make sure the currency and value are dynamically pulled from the completed order, not hardcoded as $1.00 AED, which requires integrating WHMCS's Smarty variables into the template. Also, a modern, more robust solution involves server-side tracking to combat browser limitations. The best solution today is to combine the WHMCS API with the Facebook Conversions API, orchestrated using Google Tag Manager and a server-side tagging solution like Stape or Google Cloud Platform. This setup provides superior data accuracy compared to client-side-only pixel tracking. The client-side Facebook Pixel, which you added via a hook, is vulnerable to ad blockers, browser privacy features like Intelligent Tracking Prevention (ITP) in Safari and Firefox, and poor network connectivity, which can all lead to underreported conversions. The Facebook Conversions API (CAPI) allows your server to send conversion data directly to Facebook. You can use a WHMCS hook or the WHMCS API to capture the sales event details, like when an invoice is marked as paid, and then send this data to your server-side Google Tag Manager container. This GTM server container, hosted on a service like Stape or Google Cloud Platform, acts as a centralized data router. When the WHMCS server sends a "Purchase" event with the order value, currency, and customer identifiers (like hashed email) to this endpoint, the GTM server can forward that information using the Facebook Conversions API tag. This method is better because it ensures more reliable and complete tracking, as it bypasses many client-side restrictions. Crucially, sending customer data like email and phone number from the server allows Facebook to hash this information securely and use it to better match the conversion event to the correct user on the platform, significantly improving the Event Match Quality score and, ultimately, campaign performance. Furthermore, by using both the client-side pixel and the server-side Conversions API, you can implement deduplication by sending a unique "event_id" for both events, ensuring Facebook doesn't count the same purchase twice but uses the more reliable server data. This creates a resilient, privacy-friendly, and highly accurate tracking mechanism for your Purchase events. 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.