FunnelKit
FunnelKit Documentation
Get unstuck with our helpful reference material

Funnel Builder

Track Custom Purchase Event Tracking

This document explains how to track custom purchase events in FunnelKit using your own tracking scripts. It includes step-by-step instructions, examples, and references to popular tracking platforms.

1. Overview

FunnelKit allows you to trigger custom purchase events on both upsell pages and the Thank You page. You can place your custom scripts inside a wrapper function, which ensures that your script runs whenever a purchase occurs. This guarantees accurate purchase tracking, even if a user does not reach the final Thank You page after an upsell.

Key points:

  • The wrapper ensures scripts are executed on the purchase event.
  • Order variables (like Total, Product ID, Quantity) can be passed dynamically.
  • Supports tracking on upsell offers and main order pages.

2. Using the Wrapper for Custom Scripts

  1. FunnelKit provides a wrapper where you can place any custom purchase tracking script along with all relevant variables.
  2. Use the following snippet as your base wrapper:
/**
 * Rendering Custom tracking script for thank you and upsell pages. 
 *
 * @param $general_data
 */
function render_custom_script_tracking( $general_data ) {
   ?>
   <script type="text/javascript">
      if (undefined !== wfocu_tracking_data && '' !== wfocu_tracking_data) {
         let order_id = '';
         if ("undefined" !== typeof wfocu_tracking_data.ga_transaction_id && '' !== wfocu_tracking_data.ga_transaction_id) {
            order_id = wfocu_tracking_data.ga_transaction_id;
         }else if ("undefined" !== typeof wfocu_tracking_data.transaction_id){
            order_id = wfocu_tracking_data.transaction_id;
         }

         
         //PASTE YOUR SCRIPT HERE
         
         //USE THESE DYNAMIC VARIABLES IN YOUR SCRIPT
         //wfocu_tracking_data.total                //For order total
         //wfocu_tracking_data.currency             //For order currency
         //wfocu_tracking_data.ga_transaction_id    //For order ID
         //wfocu_tracking_data.email                //For order Email
         //wfocu_tracking_data.first_name           //For order user First name
         //wfocu_tracking_data.last_name            //For order user Last name
         //wfocu_tracking_data.revenue              //For order total or revenue
         //wfocu_tracking_data.shipping             //For order Shipping cost
         //wfocu_tracking_data.tax                  //For order Tax

         // You can now use wc_order_data.billing_address_1, wc_order_data.billing_city, etc. in your custom script
      }
   </script>
   <?php
}
add_action( 'wfocu_custom_purchase_tracking', 'render_custom_script_tracking' );
  1. You can make your tracking snippet dynamic by using the commented variables provided in this reference:
Dynamic Variables Guide

Insert Image Here: Example of dynamic variable placeholders in the wrapper

3. Passing Order Variables

You can access and pass various order details in your tracking script.

Example: Getting Total Order Value

  • Variable: wfocu_tracking_data.total
  • Usage: Pass this variable in your custom script to track the total purchase value.
Screenshot showing the wfocu_tracking_data.total variable usage

Other available variables:

  • Order ID
  • Product IDs
  • Quantity
  • Upsell acceptance status

All available variables are commented in the wrapper script. You can include any of these in your custom tracking script.

4. Tracking Checkout Order and Upsell Purchases

  1. Purchase events are fired on the main order during the upsell page.
  2. If a user accepts an upsell, a separate net purchase event is triggered on the next step.
  3. Even if the user leaves the offer page without reaching the Thank You page, the wrapper ensures the purchase is still tracked.

Verification:

5. Sample Tracking Scripts for Popular Platforms

FunnelKit provides ready-to-use tracking snippets for several platforms:

6. Important Notes

  • FunnelKit guarantees that your custom script is triggered on purchase events (both on offer and Thank You pages).
  • Limitations: We do not control how events appear in your analytics, Ad Manager, or social platform accounts.
  • The wfocu_custom_purchase_tracking function ensures that scripts run at the correct time but does not influence reporting or visibility in analytics platforms.
  • Support is limited to triggering the script; we do not provide setup or troubleshooting for your analytics dashboards.

7. Recommended Implementation Steps

  1. Copy the wrapper snippet to your child theme's functions.php file, or you can use the Code Snippet plugin to add the PHP snippet using this guide.
  2. Insert your tracking script inside the wrapper.
  3. Use the commented variables to dynamically pass order data.
  4. Test the implementation on both upsell pages and Thank You pages.
  5. Verify variables and script execution using the Loom guide.
  6. Deploy to production after successful verification.
Ready to Transform Your Store?
Join 38,315+ successful store owners who trust FunnelKit to power their businesses.
Conversion Optimized Checkout Pages
Increase Revenue with Smart Upsells
Capture Emails & Recover Abandoned Carts
Automate Winbacks & Repeat Sales
918+ 5 star reviews on WordPress.org
Transform your store to power your business with FunnelKit
🚀 Maximize Your Profit with FunnelKit – Highest Rated with 918+ 5-Star Reviews
Get Started