- This topic has 42 replies, 3 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
December 1, 2022 at 6:55 am #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?
December 1, 2022 at 7:58 am #2444658David
StaffCustomer SupportHi 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.December 1, 2022 at 8:25 am #2444702Georgi
Hi,
What type of hook this should be? Custom hook? https://prnt.sc/dF9Tr27Pcbdr
December 1, 2022 at 9:05 am #2444792David
StaffCustomer SupportSo 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 openingbodytag – use:wp_body_open
3. Before the closingbodytag – use:wp_footerFor example GTM generally has 2 scripts that use
headandbody. See here for more info:https://docs.generatepress.com/article/implement-google-tag-manager/
December 1, 2022 at 9:45 am #2444964Georgi
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 ?
December 1, 2022 at 9:47 am #2444987David
StaffCustomer SupportThose 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 TermThen that hook will only load on posts of that term.
December 1, 2022 at 9:50 am #2445011Georgi
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?
December 1, 2022 at 9:59 am #2445054David
StaffCustomer SupportNope, Hooks are simply “placeholders”, they do nothing apart from inserting the code what you add inside one.
December 1, 2022 at 11:21 am #2445313Georgi
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?
December 1, 2022 at 11:24 am #2445322David
StaffCustomer SupportFor the analytics script that goes in the
wp_headhook then Yes you can include it inside the same hook. And it should come before the analytics script.December 1, 2022 at 11:43 am #2445366Georgi
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?
December 1, 2022 at 11:56 am #2445393David
StaffCustomer SupportWhat is the thank you page ? Is it coming from Woocommerce or another plugin ?
December 1, 2022 at 12:07 pm #2445405Georgi
It’s from WooCommerce.
December 2, 2022 at 2:41 am #2446385David
StaffCustomer SupportOk, 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
IDfrom 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
100change this to the Elements ID.December 5, 2022 at 9:35 am #2450559Georgi
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. -
AuthorPosts
- You must be logged in to reply to this topic.