Site logo

[Resolved] Tracking Google Ads Events on a Category and Thank You Page

Home Forums Support [Resolved] Tracking Google Ads Events on a Category and Thank You Page

Home Forums Support Tracking Google Ads Events on a Category and Thank You Page

Viewing 15 posts - 1 through 15 (of 43 total)
  • Author
    Posts
  • #2444452
    Georgi

    Hello,

    Finally bought the lifetime subscription. Yay!

    I’m running a Google Ads for only 1 category of my website and instead of cluttering the site the normal way by installing Google Tag Manager to make Google Ads tracking code fire only on that category and thank you page, I was wondering if this is possible to achieve with GeneratePres hooks?

    #2444658
    David
    Staff
    Customer Support

    Hi there,

    yes, you can use a GP Hook Element to hook in your codes.
    Simply set the display rules for the specific pages, posts or archives that you want the code to fire.

    #2444702
    Georgi

    Hi,

    What type of hook this should be? Custom hook? https://prnt.sc/dF9Tr27Pcbdr

    #2444792
    David
    Staff
    Customer Support

    So Tracking codes are generally added in one of 3 places, and those and their equivalent hooks are:

    1. In the <head> of the site – use: wp_head
    2. After the opening body tag – use: wp_body_open
    3. Before the closing body tag – use: wp_footer

    For example GTM generally has 2 scripts that use head and body. See here for more info:

    https://docs.generatepress.com/article/implement-google-tag-manager/

    #2444964
    Georgi

    I see.

    But if I want to fire tags only on certain categories, can I implement the GTM to be displayed only on these certain categories? Or I need to set its code to be displayed on the entire site ?

    #2444987
    David
    Staff
    Customer Support

    Those hooks are present on every page.
    So you need to set the Elements Display Rules for just the places you want.

    eg. Posts in a specific category you would set: Post Category -> Category Term

    Then that hook will only load on posts of that term.

    #2445011
    Georgi

    Great, so I will implement GTM only on certain categories, not on the whole site, so it doesn’t slow the site speed too much.

    Also, I was wondering – do the Hooks by themselves increase requests on page? Or they have no influence, only the code they execute has influence?

    #2445054
    David
    Staff
    Customer Support

    Nope, Hooks are simply “placeholders”, they do nothing apart from inserting the code what you add inside one.

    #2445313
    Georgi

    Thank you, David, you’re clarifying a lot of things for me!

    One more thing – can I put the preconnect attribute together with the code for Analytics in the same hook?

    <link href=’https://www.google-analytics.com’ rel=’preconnect’ crossorigin>

    Before the code or after the code for analytics I can put it, do you know?

    #2445322
    David
    Staff
    Customer Support

    For the analytics script that goes in the wp_head hook then Yes you can include it inside the same hook. And it should come before the analytics script.

    #2445366
    Georgi

    Okay.

    I now noticed that while I can specify in a Hook for the Google Tag Manager scripts to run on a particular category, there’s no option to make them work also on the thank you page.

    Do you know how can they be executed particularly on the thank you page, not the entire site?

    #2445393
    David
    Staff
    Customer Support

    What is the thank you page ? Is it coming from Woocommerce or another plugin ?

    #2445405
    Georgi

    It’s from WooCommerce.

    #2446385
    David
    Staff
    Customer Support

    Ok, so there isn’t a ‘real page’ for that, its a URL endpoint.
    It will need some PHP to add the element to that.

    1. Edit your current Hook, and get its ID from the browser URL.
    Keep the current Display Rules for the other places you need it on.

    2. Now add this PHP Snippet to your site:

    
    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 100 === $element_id && is_wc_endpoint_url('order-received') ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    Where it is 100 change this to the Elements ID.

    #2450559
    Georgi

    Thank you a lot, David!
    I haven’t tried this yet but I don’t think there will be a problem.
    I will mark the thread as resolved.

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