Home > Technical & Creative Skills > Programming, Servers & Scripts

How to make a FB pixel/google tag manager load before jQuery? (6)


11-05-2020 11:25 PM #1 seogood1000 (Member)
How to make a FB pixel/google tag manager load before jQuery?

Hi there,

I'm using Google Tag Manager to fire a Facebook Pixel. About 15% of the clicks don't get registered as View Content on Facebook. I saw someone suggested making FB pixel/google tag manager load before jQuery - switch the script order to load it first.

https://stackoverflow.com/questions/...les-to-the-tophttps://developer.wordpress.org/refe...ons/add_action/

I contacted a few developers on fiverr and some of them said
its not possible to add script before jquery, wp_head action automatically adjust it, the script should be added before the closing tag of head.

Can someone please help clarify?

Since I'm not a techie, I'm not sure whose advice is correct...

Many thanks!


11-06-2020 01:58 AM #2 jeremie (Moderator)

You can directly modify the header.php of your theme to insert the script before the wp_head() function that is the function responsible of creating all the scripts links in header. By hardcoding it, it will be first.

This is what i recommend you as it is the easiest.

Or you could use wp_enqueue_scripts() but your devs are right that jquery is likely to be inserted before. You would have to modify the jquery call to add a dependency to your script so that the jquery gets loaded after. More complicated...


11-18-2020 04:52 PM #3 seogood1000 (Member)
How To Place a Google Tag Before Jquery using ThriveThemes

Hi,
Can someone please help advise how to add the tag code at the start of head tag, before JQuery while using a WP+Thrive Architect+WC theme to minimize the data loss?

A Google tag failed to fire frequently when adding the Google tag code to Thrive Architect's custom script features and when using a GTM plugin. So I added the code to header.php of theme file but it didn't work and Thrive Architect dev says "Practically your Theme is “hidden” beneath the Landing Page and this is the reason why the Header/Footer from the Theme are not displayed on a Landing Page giving you full customization control to create your own."

Seems they don't know the solution I'm seeking. Their plugin is designed to insert the tag right before </head>. Any suggestions?

Many thanks!


11-18-2020 05:01 PM #4 plutus (Member)

Quote Originally Posted by seogood1000 View Post
Hi,
Can someone please help advise how to add the tag code at the start of head tag, before JQuery while using a WP+Thrive Architect+WC theme to minimize the data loss?

A Google tag failed to fire frequently when adding the Google tag code to Thrive Architect's custom script features and when using a GTM plugin. So I added the code to header.php of theme file but it didn't work and Thrive Architect dev says "Practically your Theme is “hidden” beneath the Landing Page and this is the reason why the Header/Footer from the Theme are not displayed on a Landing Page giving you full customization control to create your own."

Seems they don't know the solution I'm seeking. Their plugin is designed to insert the tag right before </head>. Any suggestions?

Many thanks!
Where did you add it to header.php?

You have to add it to header.php file in theme (or child-theme) that you are currently using, ABOVE <?php wp_head(); ?>

Adding it below that function call will have no effect as it's the place that enqueues all of the header's css/js


11-18-2020 05:58 PM #5 seogood1000 (Member)

Thanks for your response! I added it right after<head> in the theme header.php but the problem is that Thrive Architect dev says "Practically your Theme is hidden beneath the Landing Page and this is the reason why the Header/Footer from the Theme are not displayed on a Landing Page giving you full customization control to create your own."

Basically
Thrive Architect - page builder is hiding the theme files... Any suggestions?


11-18-2020 06:16 PM #6 jeremie (Moderator)

@seogood1000, I merged both of your questions as they are related


Home > Technical & Creative Skills > Programming, Servers & Scripts