[Support request] Apply GA in Elements to Woocommerce Checkout?

Home Forums Support Apply GA in Elements to Woocommerce Checkout?

  • This topic has 10 replies, 3 voices, and was last updated 1 year ago by Tom.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1006570
    Edin

    I’ve added the GA code to Elements in GP.

    In the “Display Rules” I only want to display the code on the checkout page AND the “Order Received” page (which is /checkout/order-received/******).

    The checkout page I’ve figured out, but how do I activate the GA code only on the “Order Received” page.

    Thanks,
    Edin

    #1006647
    David
    Staff
    Customer Support

    Hi there,

    if it is the same code being used on the Checkout then all endpoints e.g /order-received will also display any hooks you applied to the Checkout.

    If you need a specific code for the order-received page then it would probably require a redirect to your own ‘thank you’ page.

    #1008399
    Edin

    Thank you, David.

    So this is enough?

    screenshot

    #1008539
    David
    Staff
    Customer Support
    #1013221
    Edin

    Hi David,

    I tested this and it does not work on the Woocommerce “Order Received” page.

    It does work on the checkout page itself: /checkouts/mycheckoutpage

    How can I make it work on the “Order Received” page: /checkout/order-received/

    Thanks,
    Edin

    #1013824
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Is “Order Received” a physical page in the Pages area? If so, can you choose it in the Display Rules?

    #1013832
    Edin

    Unfortunately not. I seems generated by Woocommerce.

    #1014075
    Tom
    Lead Developer
    Lead Developer

    Looks like we need to use a filter.

    For example:

    add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
        if ( ! function_exists( 'is_wc_endpoint_url' ) ) {
            return $display;
        }
    
        if ( 123 == $element_id && is_wc_endpoint_url( 'order-received' ) ) {
            return true;
        }
    
        return $display;
    }, 10, 2 );

    You just need to update 123 with the ID of the Hook Element you created.

    #1014159
    Edin

    Thank you, Tom, but it doesn’t seem to work.

    Copied the code into functions.php, changed 123 to 2211. But there’s no GA code in /checkout/order-received/

    Thanks,
    Edin

    #1014179
    Edin

    Actually, it’s okay Tom.

    I’ve changed it to “entire site”.

    It does make sense to have analytics on every page, even if it slows down the site (maybe there’s a way to minimize that).

    Thank you!

    #1014662
    Tom
    Lead Developer
    Lead Developer

    Ah, there was an error in my code – I just fixed it if you want to try it again.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.