Plugin Directory

Changeset 3404142


Ignore:
Timestamp:
11/27/2025 01:33:02 PM (4 months ago)
Author:
fastwpde
Message:

Update: Added view cart and product view tracking. Extended WooCommerce integration for Trackboxx v2 compatibility. Updated public and loader classes.

Location:
trackboxx-analytics/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trackboxx-analytics/trunk/includes/class-trackboxx.php

    r3358630 r3404142  
    184184        $this->loader->add_action( 'wp_print_scripts', $plugin_public, 'enqueue_scripts_old' );
    185185        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
     186       
     187        // WooCommerce tracking hooks
    186188        $this->loader->add_action( 'woocommerce_before_thankyou', $plugin_public, 'wc_purchase_tracking_script' );
    187189        $this->loader->add_action( 'woocommerce_add_to_cart', $plugin_public, 'wc_add_to_cart', 10, 2 );
     190       
     191        // New View Cart tracking hooks (added in version 1.3.34)
     192        $this->loader->add_action( 'wp_footer', $plugin_public, 'wc_view_cart_tracking' );
     193        $this->loader->add_action( 'wp_footer', $plugin_public, 'wc_view_product_tracking' );
    188194    }
    189195
  • trackboxx-analytics/trunk/public/class-trackboxx-public.php

    r3358630 r3404142  
    183183    }
    184184
     185    /**
     186     * Track WooCommerce View Cart action.
     187     *
     188     * @since 1.3.34
     189     * @return void
     190     */
     191    public function wc_view_cart_tracking() {
     192        if ( !function_exists( 'is_cart' ) || !is_cart() ) {
     193            return;
     194        }
     195
     196        $cart = WC()->cart;
     197        if ( ! $cart || $cart->is_empty() ) {
     198            return;
     199        }
     200
     201        $options      = get_option( 'trackboxx_tracking_id' );
     202        $trackboxx_id = isset( $options['input'] ) ? sanitize_text_field( $options['input'] ) : '';
     203
     204        if ( empty( $trackboxx_id ) ) {
     205            return;
     206        }
     207
     208        // Build tracking data
     209        $tracking_data = array(
     210                array( 'type' => 'ViewCart' ),
     211                array(
     212                        'type' => 'cart',
     213                        'amount' => floatval( $cart->get_cart_contents_total() )
     214                ),
     215        );
     216
     217        // Add all products in cart
     218        foreach ( $cart->get_cart() as $cart_item ) {
     219            $product = $cart_item['data'];
     220            if ( $product ) {
     221                $tracking_data[] = array(
     222                        'type'  => 'product',
     223                        'name'  => wp_strip_all_tags( $product->get_name() ),
     224                        'price' => floatval( $product->get_price() ) * intval( $cart_item['quantity'] ),
     225                );
     226            }
     227        }
     228
     229        $params_json = wp_json_encode( $tracking_data );
     230        $inline_js = "trackboxx('Purchase', " . $params_json . ");";
     231        $this->enqueue_public_scripts( $inline_js );
     232    }
     233
     234    /**
     235     * Track WooCommerce View Product action.
     236     *
     237     * @since 1.3.34
     238     * @return void
     239     */
     240    public function wc_view_product_tracking() {
     241        if ( !function_exists( 'is_product' ) || !is_product() ) {
     242            return;
     243        }
     244
     245        $options      = get_option( 'trackboxx_tracking_id' );
     246        $trackboxx_id = isset( $options['input'] ) ? sanitize_text_field( $options['input'] ) : '';
     247
     248        if ( empty( $trackboxx_id ) ) {
     249            return;
     250        }
     251
     252        global $product;
     253
     254        if ( $product instanceof WC_Product ) {
     255            $tracking_data = array(
     256                    array( 'type' => 'ViewProduct' ),
     257                    array(
     258                            'type' => 'product',
     259                            'name' => $product->get_name(),
     260                            'price' => $product->get_price()
     261                    )
     262            );
     263
     264            $params_json = wp_json_encode( $tracking_data );
     265            $inline_js = "trackboxx('Purchase', " . $params_json . ");";
     266            $this->enqueue_public_scripts( $inline_js );
     267        }
     268    }
     269
    185270    /**
    186271     * Track WooCommerce Purchase action.
     
    290375        ?>
    291376        <!-- Trackboxx Analytics -->
    292         <script>
     377<script>
    293378          (function(d, s, id, w, f){
    294               w[f] = w[f] || function() { (w[f].q = w[f].q || []).push(arguments) };
     379              w[f] = w[f] || function() { (w[f].q = w[f].q || []).push(arguments)
     380        };
    295381              var js, fjs = d.getElementsByTagName(s)[0];
    296382              if (d.getElementById(id)) { return; }
     
    302388          }(document, 'script', 'trackboxx-script', window, 'trackboxx'));
    303389          trackboxx('set', 'siteId', <?php echo wp_json_encode( $id ); ?>);
    304           trackboxx('trackPageview');
    305         </script>
     390            trackboxx('trackPageview');
     391</script>
     392
    306393        <?php
    307394    }
  • trackboxx-analytics/trunk/readme.txt

    r3361053 r3404142  
    115115== Changelog ==
    116116
     117
     118= 1.3.34 =
     119* Added view cart tracking functionality for improved event accuracy.
     120* Added product view tracking to support enhanced behavioral analytics.
     121* Extended WooCommerce integration to enable precise cart view detection.
     122* Enables Trackboxx to calculate cart abandonment rates more reliably.
     123* Updated public classes and loader to include new tracking hooks.
     124
    117125= 1.3.33 =
    118126* Added new signup information block to the onboarding wizard.
  • trackboxx-analytics/trunk/trackboxx.php

    r3361053 r3404142  
    55 * Author:            Trackboxx
    66 * Author URI:        https://trackboxx.com/
    7  * Version:           1.3.33
     7 * Version:           1.3.34
    88 * Requires PHP:      8.0
    99 * Text Domain:       trackboxx-analytics
     
    2323 * Currently plugin version.
    2424 */
    25 define( 'TRACKBOXX_VERSION', '1.3.33' );
     25define( 'TRACKBOXX_VERSION', '1.3.34' );
    2626
    2727
Note: See TracChangeset for help on using the changeset viewer.