Site logo

Archived topic

Apply GA in Elements to Woocommerce Checkout?

10 replies · Started by Edin on September 11, 2019

Viewing posts 1–11 of 11

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

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.

Thank you, David.

So this is enough?

screenshot

Thats correct.

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

Hi there,

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

Unfortunately not. I seems generated by Woocommerce.

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.

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

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!

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

This archived topic is closed to new replies.