Plugin Directory

Changeset 3402749


Ignore:
Timestamp:
11/25/2025 06:08:10 PM (3 months ago)
Author:
routedev
Message:

Add Amplitude tracking for Route widget interactions

Location:
routeapp/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • routeapp/trunk/public/class-routeapp-public.php

    r3391431 r3402749  
    3636    const ALLOWED_QUOTE_TYPE = 'paid_by_customer';
    3737
     38    const AMPLITUDE_API_KEY = [
     39        'production' => '6d4f9158886e0c6d78e3bd97663ba920',
     40        'stage' => '99a869d62986f6415610c6741057bc92',
     41        'dev' => '527af176070cf4b775c6a718f0737f0a'
     42    ];
     43
    3844    /**
    3945     * The ID of this plugin.
     
    4450     */
    4551    private $plugin_name;
     52
     53    private $route_insurance_data = null;
    4654
    4755    /**
     
    390398        $cartItems = $this->get_cart_shippable_items($cart);
    391399        $route_insurance_quote = $this->routeapp_get_quote_from_api($cartRef, $cartTotal, $currency, $cartItems);
     400        $this->route_insurance_data = $route_insurance_quote;
    392401
    393402        $route_insurance_amount = false;
     
    482491        wp_enqueue_script($this->plugin_name . '-widget', 'https://protection-widget.route.com/route-protection-widget.js', array(), $this->version, false);
    483492
    484         wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/routeapp-public-pbc.js', array('jquery'), $this->version, false);
     493        $amplitude_key = self::AMPLITUDE_API_KEY[$custom_env];
     494
     495        // Load Amplitude SDK (standard version, not snippet)
     496        wp_enqueue_script('amplitude-js', "https://cdn.amplitude.com/script/$amplitude_key.js", array(), null, false);
     497
     498        // Enqueue Amplitude Analytics module (depends on jQuery and Amplitude SDK)
     499        wp_enqueue_script($this->plugin_name . '-amplitude-analytics', plugin_dir_url(__FILE__) . 'js/amplitude-analytics.js', array('jquery', 'amplitude-js'), $this->version, false);
     500
     501        // Main script depends on amplitude-analytics when available
     502        wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/routeapp-public-pbc.js', array('jquery', $this->plugin_name . '-amplitude-analytics'), $this->version, false);
     503
     504        /**
     505         * Calculate total Route fee
     506         * Uses the premium amount from route insurance data if available,
     507         * otherwise defaults to 0.98 as a fallback fee amount
     508         */
     509        $totalRouteFee = (is_object($this->route_insurance_data) && isset($this->route_insurance_data->premium->amount))
     510            ? (float) $this->route_insurance_data->premium->amount
     511            : 0.98;
     512
     513        // Pass cart data to JavaScript - send to amplitude-analytics.js
     514        wp_localize_script($this->plugin_name . '-amplitude-analytics', 'cartData', array(
     515            'cartId' => WC()->cart->get_cart_hash(),
     516            'amplitudeKey' => $amplitude_key,
     517            'widgetId' => uniqid('widget-', true),
     518            'subtotal' => round($this->get_cart_subtotal_with_only_shippable_items(WC()->cart), 2),
     519            'totalRouteFee' => $totalRouteFee,
     520            'environment' => $custom_env,
     521            'currency' => get_woocommerce_currency(),
     522            'merchantId' => $this->routeapp_api_client->get_merchant_id(),
     523        ));
    485524
    486525        wp_enqueue_style($this->plugin_name . '-widget', plugin_dir_url(__FILE__) . 'css/routeapp-widget.css', array(), $this->version, false);
  • routeapp/trunk/public/js/routeapp-public-pbc.js

    r2979691 r3402749  
    2323            is_cart_page: window.location.pathname === "/cart/",
    2424            invalid_shipping_method: '.routeapp-invalid-shipping-method',
    25             checkbox: $(PROTECTION_COOKIE).length ? parseCheckboxValue() : Route.Coverage.ActiveByDefault,
     25            checkbox: $(PROTECTION_COOKIE).length ? parseCheckboxValue() : Route.Coverage.ActiveByDefault
    2626        };
    2727
     
    6363                success: function () {
    6464                    RouteConfig.is_cart_page ? triggerCartUpdate() : triggerCheckoutUpdate();
     65
     66                    // Track protection change using RouteAmplitudeAnalytics
     67                    if (window.RouteAmplitudeAnalytics) {
     68                        RouteAmplitudeAnalytics.trackProtectChange(checkbox);
     69                    }
    6570                }
    6671            });
     
    108113                        $(ROUTE_WIDGET_ID).show();
    109114                        renderWidget(result['routeapp-subtotal']);
     115                        // Track widget render using RouteAmplitudeAnalytics
     116                        if (window.RouteAmplitudeAnalytics) {
     117                            RouteAmplitudeAnalytics.trackWidgetRender();
     118                        }
    110119                    } else {
    111120                        $(ROUTE_WIDGET_ID).hide();
     
    119128        $(document.body).on( UPDATED_CHECKOUT_EVENT, checkWidgetShow);
    120129
     130        // Initialize Amplitude analytics using RouteAmplitudeAnalytics
     131        if (window.RouteAmplitudeAnalytics) {
     132            RouteAmplitudeAnalytics.initialize();
     133        }
     134
     135        // Set up event listeners for info modal tracking
     136        // Listen for clicks on Route widget info buttons
     137        $(document).on('click', '#RouteWidget .pw-info-icon', function() {
     138            if (window.RouteAmplitudeAnalytics) {
     139                RouteAmplitudeAnalytics.trackInfoChange('opened');
     140            }
     141        });
     142       
     143        // Listen for modal close events
     144        $(document).on('click', '#RouteWidget .route-modal__close', function() {
     145            if (window.RouteAmplitudeAnalytics) {
     146                RouteAmplitudeAnalytics.trackInfoChange('closed');
     147            }
     148        });
     149
    121150        if (!$(RouteConfig.invalid_shipping_method).length) {
    122151            renderWidget($(RouteConfig.subtotal).val());
  • routeapp/trunk/readme.txt

    r3391431 r3402749  
    66Requires at least: 4.0
    77Tested up to: 6.7.1
    8 Stable tag: 2.2.29
     8Stable tag: 2.2.30
    99Requires PHP: 5.6
    1010License: GPLv2 or later
     
    106106
    107107== Changelog ==
     108
     109= 2.2.30 =
     110* Add Amplitude tracking for Route widget interactions
    108111
    109112= 2.2.29 =
  • routeapp/trunk/routeapp.php

    r3391431 r3402749  
    1010 * Plugin URI:        https://route.com/for-merchants/
    1111 * Description:       Route allows shoppers to insure their orders with one-click during checkout, adding a layer of 3rd party trust while improving the customer shopping experience.
    12  * Version:           2.2.29
     12 * Version:           2.2.30
    1313 * Author:            Route
    1414 * Author URI:        https://route.com/
     
    2626 * Currently plugin version.
    2727 */
    28 define( 'ROUTEAPP_VERSION', '2.2.29' );
     28define( 'ROUTEAPP_VERSION', '2.2.30' );
    2929
    3030/**
Note: See TracChangeset for help on using the changeset viewer.